OpenRouter supports structured outputs for compatible models, ensuring responses follow a specific JSON Schema format. This feature is particularly useful when you need consistent, well-formatted responses that can be reliably parsed by your application.
Structured outputs allow you to:
To use structured outputs, include a response_format parameter in your request, with type set to json_schema and the json_schema object containing your schema:
The model will respond with a JSON object that strictly follows your schema:
Structured outputs are supported by select models.
You can find a list of models that support structured outputs on the models page.
To ensure your chosen model supports structured outputs:
require_parameters: true in your provider preferences (see Provider Routing)response_format and set type: json_schema in the required parametersInclude descriptions: Add clear descriptions to your schema properties to guide the model
Use strict mode: Always set strict: true to ensure the model follows your schema exactly
Here’s a complete example using the Fetch API:
Structured outputs are also supported with streaming responses. The model will stream valid partial JSON that, when complete, forms a valid response matching your schema.
To enable streaming with structured outputs, simply add stream: true to your request:
When using structured outputs, you may encounter these scenarios:
For non-streaming requests using response_format with type: "json_schema", you can enable the Response Healing plugin to reduce the risk of invalid JSON when models return imperfect formatting. Learn more in the Response Healing documentation.