Skip to main content
Structured Outputs force the model to return a JSON object that matches a schema you define. This eliminates the need to parse, validate, or retry unstructured model output. ARouter supports two structured output modes:

Using Structured Outputs

Pass response_format in your request body:

JSON Object Mode

The model returns valid JSON, but the schema is not enforced:

JSON Schema Mode

Use json_schema to enforce a strict schema:
Response:

Full Example

Model Support

json_schema mode with strict: true is supported by:
  • openai/gpt-5.4, openai/gpt-5.4-pro, openai/o3, openai/o4-mini
  • anthropic/claude-sonnet-4.6, anthropic/claude-opus-4.5
  • google/gemini-2.5-flash, google/gemini-2.5-pro
json_object mode (no schema enforcement) is more broadly supported. Check GET /v1/models for the latest capability information.

Streaming with Structured Outputs

Structured outputs work with streaming. The JSON content is delivered incrementally and you assemble it client-side:

Best Practices

  1. Use strict: true — This guarantees schema compliance. Without it, the model may return valid JSON that doesn’t match the schema exactly.
  2. Set additionalProperties: false — Required for strict mode. Prevents the model from adding extra keys.
  3. List all required fields explicitly — In strict mode, every field in properties should also be in required.
  4. Include a system prompt — Telling the model its role as a data extraction or structured output assistant improves reliability.

Error Handling

If the model cannot produce valid JSON that matches your schema (e.g., a prompt that fundamentally conflicts with the schema), the response will have finish_reason: "length" or finish_reason: "content_filter". Always check finish_reason before parsing content.