Skip to content

Glossary

Structured output (JSON mode)

Structured output is a request setting — response_format on an OpenAI-compatible API — that constrains a model to answer with valid JSON, either free-form or conforming to a schema you supply, rather than with prose your code then has to parse out.

JSON modejson_objectjson_schemaresponse_formatconstrained decoding

There are two levels and the difference matters. json_object asks only for syntactically valid JSON of any shape, so your parser succeeds and your field access still fails. json_schema binds the response to a schema you provide, which is the version that removes a whole class of bug rather than moving it one line later.

Where it is implemented as constrained decoding, the guarantee is structural: at each step the sampler is restricted to tokens that keep the output valid against the grammar, so malformed JSON becomes impossible rather than unlikely. Where it is implemented as an instruction in the prompt, it is a request the model usually honours, which is a different thing entirely.

The schema is input tokens, on every request, exactly like a tool definition. A verbose schema with long descriptions on every field is paid for on every extraction, so a schema is worth editing for length the same way a system prompt is.

A conforming answer is not a correct one. Constrained decoding guarantees shape, never semantics — the fields will be present and typed, and the values in them can still be invented. Validation of the content stays your job.

What it costs you

The real price of structured output is measured in retries, and a retry is billed in full. A response that fails to parse has already consumed its input and its output before it is discarded, so the cost of one usable record is the cost of every attempt it took to get one. That makes an enforced schema — a fixed, known number of input tokens per request — reliably cheaper than a requested one, whose cost is a variable number of whole discarded generations. Pairing it with a low temperature is the other half of the same saving.

Worked from today’s rates

Extracting one record from a 4,000-token document on DeepSeek V4 Pro — input plus a 300-token JSON reply — costs $0.00129. Across 100,000 documents that is $128.50, and a 5% malformed rate adds $6.43 for records you parse and throw away.

Related terms

Go deeper

Get an API key — $5 free credit

Every rate quoted above is published in full on the pricing page, alongside the model publisher’s own official rate.