response_format to {"type": "json_object"}. Use JSON mode when you need parseable JSON but don’t need to enforce a specific schema.
For most production use cases, prefer structured outputs. Structured outputs guarantee that the response matches a JSON schema you provide, which is stricter, type-safe, and removes the need to retry or validate after the fact.
How it works
JSON mode tells the server to constrain the output to valid JSON. You still describe the fields you want in the prompt; the server only enforces well-formedness, not shape.json_mode.py
JSON mode versus structured outputs
Reach for JSON mode when you don’t want to define a schema and the downstream consumer can tolerate flexible field sets. Otherwise, use structured outputs.
Model support
JSON mode and structured outputs are supported on a per-model basis. See the feature support table on the Model APIs overview for which models support each.Related
- Structured outputs: Schema-enforced JSON output.
- Model APIs overview: Supported models and feature matrix.
- Chat Completions reference: Full request and response schema.