Skip to main content
When you need the model to return JSON that exactly matches a schema, use response_format with a model that advertises structured_outputs from GET /v1/models. Cogito enforces the schema with grammar-constrained decoding on those routes — the model literally cannot emit tokens that would break the schema, so you don’t need to ask nicely or add “respond only in JSON” to the system prompt.

JSON schema mode

What “strict” guarantees

With strict: true, every property in required is present, every value matches its declared type, and no extra fields are emitted. You can json.loads() without a try/except in production.

json_object mode

For “give me any valid JSON” without a schema:
Less strict — the structure is up to the model — but the result is still guaranteed valid JSON.

Streaming structured outputs

Both modes work with stream: true. Chunks arrive as token-level deltas and assemble into valid JSON once the stream completes. Don’t JSON.parse partial chunks; only the assembled string is guaranteed valid.

Errors

If the schema is malformed (recursive without a depth limit, mutually exclusive constraints), Cogito returns a 400 before generation starts. Models that do not advertise structured_outputs return a 400 for enforced response_format requests.