response_format field, so the schema format matches the OpenAI structured outputs guide.
Not every model supports schemas. Check the models catalog
(
GET /v1/models) for models that report response_format support.JSON mode
For simple “just give me valid JSON” cases, setresponse_format to json_object:
JSON schema
To enforce an exact shape, pass ajson_schema. This example asks the model to show its steps solving an equation:
Gotchas
- Every property must be listed in
required. To make a field optional, allownullin its type:"type": ["string", "null"]. additionalPropertiesmust be set tofalsefor strict schemas.strictmust betruefor the schema to be enforced.- A schema constrains the shape, not the correctness. The values still depend on the prompt and the model.
- Very large schemas can hit
max_tokensor time out before completing. Keep schemas focused.