Overview
Structured outputs allow you to constrain the model’s response to follow a specific JSON schema. This ensures the model returns data in a predictable format that can be reliably parsed and processed by your application.Getting started
To use structured outputs, include theresponse_format parameter in your request with a json_schema type:
- Python
- JavaScript
- cURL
Example response
When using structured outputs, the model’s response will be a JSON string that conforms to your schema:Supported models
Structured outputs are supported by the following model families:| Provider | Supported |
|---|---|
| OpenAI (GPT-4.1, GPT-5.x) | Yes |
| Gemini | Yes |
| Claude (4.5+) | Yes |
| Alibaba Cloud Qwen | Yes |
| Moonshot AI Kimi | Yes |
| gpt-oss | No |
API reference
Request parameters
Theresponse_format parameter controls how the model formats its response:
| Key | Type | Required? | Description |
|---|---|---|---|
response_format | object | No | Specifies the format of the model’s response. |
response_format.type | string | Yes | The type of response format. Use "json_schema" for structured outputs. |
response_format.json_schema | object | Yes | The JSON schema configuration object. |
JSON schema object
| Key | Type | Required? | Description |
|---|---|---|---|
json_schema.name | string | Yes | A name for the schema. Used for identification purposes. |
json_schema.schema | object | Yes | A valid JSON Schema object that defines the structure of the expected response. |
json_schema.strict | boolean | No | When true, the model will strictly adhere to the schema. Recommended for reliable parsing. |
Schema definition
Theschema object follows the JSON Schema specification. Common properties include:
| Property | Type | Description |
|---|---|---|
type | string | The data type: "object", "array", "string", "number", "boolean". |
properties | object | For objects, defines the properties and their schemas. |
items | object | For arrays, defines the schema for array items. |
required | array | List of required property names. |
additionalProperties | boolean | When false, prevents additional properties not defined in the schema. |
Best practices
When using structured outputs, keep these recommendations in mind: Setstrict: true to ensure the model’s response strictly adheres to your schema. This is especially important when your application depends on specific fields being present.
Use additionalProperties: false at each level of your schema to prevent the model from adding unexpected fields to the response.
Keep your schemas focused and specific. Complex schemas with many nested levels may increase latency and token usage.
Include clear descriptions in your system or user messages to help the model understand what data to extract or generate for each field.