
JSON mode and structured outputs — a field guide
Response format, JSON schema, and the tradeoffs between them.
Two flavors of structured output. Pick the right one for the job.
response_format: json_object#
Loose — the model returns valid JSON but any shape it likes. Fast, cheap, and enough for exploratory work.
json
{"response_format": {"type": "json_object"}}response_format: json_schema#
Strict — you provide a schema and the decoder is constrained to it. Zero parsing errors in production.
json
{
"response_format": {
"type": "json_schema",
"json_schema": { "name": "invoice", "schema": {...}, "strict": true }
}
}Strict schemas cost a fraction more input tokens but eliminate parse-fail retries. Almost always worth it.
Build this with TokenRex
TokenRex is an LLM marketplace by Asirex Labs. Choose an enabled model, create a private API key and use the supported endpoint shown in Docs. Check live prices before your first request.