response_format to {"type": "json_object"} to have the model return valid JSON.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Force well-structured JSON outputs from the model.
json_mode: true.response_format to {"type": "json_object"} to have the model return valid JSON.
import json
import openai
client = openai.OpenAI(
base_url="https://api.llm7.io/v1",
api_key="YOUR_LLM7_API_TOKEN",
)
prompt = "Return a JSON object with fields city, country, and temperature_c."
stream = client.chat.completions.create(
model="bidara", # or another model with json_mode: true from /v1/models
messages=[
{"role": "system", "content": "Answer with valid JSON only."},
{"role": "user", "content": prompt},
],
response_format={"type": "json_object"},
temperature=0.2,
stream=True,
)
full = ""
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
full += delta
data = json.loads(full)
print(data)
