Structured output
JSON mode and JSON Schema output, routed only to providers proven to honor it.
このページはまだ翻訳されていません。英語版を表示しています。
Request a schema
Chat Completions: response_format with {"type": "json_object"} or {"type": "json_schema", "json_schema": {name, schema, strict}}. Responses: the same under text.format. Support is probed per provider: a route that cannot honor it is skipped, and if none can, 400 unsupported_capability with param: response_format. A schema request is never downgraded to prose.
/v1/chat/completionsPOST/v1/responsesimport json
from openai import OpenAI
client = OpenAI(base_url="https://api.experientiallabs.ai/v1", api_key="YOUR_API_KEY")
r = client.chat.completions.create(
model="gpt-6-luna", max_tokens=2048,
messages=[{"role": "user", "content": "Ada Lovelace was born in 1815 and died in 1852."}],
response_format={"type": "json_schema", "json_schema": {
"name": "person", "strict": True,
"schema": {"type": "object", "additionalProperties": False, "required": ["name", "age"],
"properties": {"name": {"type": "string"}, "age": {"type": "integer"}}},
}},
)
print(json.loads(r.choices[0].message.content))Pitfalls
| Symptom | Cause and fix |
|---|---|
Empty content, finish_reason: "length" | A reasoning model spent max_tokens thinking. Raise max_tokens |
| Schema not enforced on a non-OpenAI provider | Set strict: true; those providers enforce it themselves |
400 unsupported_capability | The model honors json_object but not json_schema (some do). Check supported_params |
400 capability_requires_payment / _purchase | The model serves this only on lanes your account must pay to unlock; param names the field |
/api/models/{slug}curl -s https://api.experientiallabs.ai/api/models/gpt-6-luna | jq '.model.supported_params'