Structured outputs
Get model responses that conform to a JSON Schema.
Structured outputs constrain model responses to a JSON Schema you define. Use JSON.parse to read the result for extraction, classification, or form filling. Each endpoint uses a different field for the same behavior.
| Endpoint | Field |
|---|---|
| Chat Completions | response_format: { "type": "json_schema", "json_schema": { "name", "schema", "strict" } } |
| Responses | text.format: { "type": "json_schema", "name", "schema", "strict" } |
| Anthropic Messages | output_config.format: { "type": "json_schema", "schema" } |
Example
curl https://api.outerlane.app/v1/chat/completions \
-H "Authorization: Bearer $OUTERLANE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-6.1-sol",
"messages": [{ "role": "user", "content": "What are the capital and currency code of South Korea?" }],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "country",
"strict": true,
"schema": {
"type": "object",
"properties": {
"capital": { "type": "string" },
"currency": { "type": "string" }
},
"required": ["capital", "currency"],
"additionalProperties": false
}
}
}
}'The response text is a JSON string that conforms to the schema.
{ "capital": "Seoul", "currency": "KRW" }Schema rules
- For
strict: true, list every property inrequiredand setadditionalProperties: falseon each object. Allownullfor fields that may have no value, for example"type": ["string", "null"]. - Anthropic Messages always forwards
output_config.formatin strict mode, so the same rules apply. - For JSON without a schema, set
response_format: { "type": "json_object" }in Chat Completions ortext.format: { "type": "json_object" }in Responses. Also tell the model to respond in JSON in your prompt.
Notes
- Check support before switching models. An unsupported model may return an error or fail to follow the schema.
- If output reaches the token limit, the JSON may be incomplete. Check
finish_reasonin Chat Completions,statusin Responses, orstop_reasonin Messages before parsing.