Overview
Structured outputs allow you to:
Enforce JSON Schema validation on model responses
Get consistent, type-safe outputs
Avoid parsing errors and hallucinated fields
Simplify downstream integrations
Using Strucutred Outputs
Include a response_format
parameter in your request with type
set to json_schema
.
The json_schema
object defines the exact structure you want.
title= "Example Request"
{
"model" : "openai/gpt-4o" ,
"messages" : [
{ "role" : "user" , "content" : "What's the weather like in London?" }
],
"response_format" : {
"type" : "json_schema" ,
"json_schema" : {
"name" : "weather" ,
"strict" : true ,
"schema" : {
"type" : "object" ,
"properties" : {
"location" : { "type" : "string" , "description" : "City or location name" },
"temperature" : { "type" : "number" , "description" : "Temperature in Celsius" },
"conditions" : { "type" : "string" , "description" : "Weather conditions description" }
},
"required" : [ "location" , "temperature" , "conditions" ],
"additionalProperties" : false
}
}
}
}
The model will return a JSON object that strictly follows your schema:
{
"location" : "London" ,
"temperature" : 18 ,
"conditions" : "Partly cloudy with light drizzle"
}
Model Support
Structured outputs are supported on select Anannas models:
gpt-4o-audio-preview
gpt-5-chat
gpt-5
gpt-5-mini
gpt-5-nano
gpt-oss-120b
gpt-oss-20b
o3-pro
o3
o3-mini
codex-mini
o4-mini
gpt-4.1
gpt-4.1-mini
gpt-4.1-nano
o1-pro
o1
o1-mini
o1-mini-2024-09-12
gpt-4o-mini-search-preview
gpt-4o-search-preview
chatgpt-4o-latest
gpt-4o-2024-11-20
gpt-4o-2024-08-06
gpt-4o-mini
gpt-4o-mini-2024-07-18
gpt-4o
gpt-4o:extended
gpt-4o-2024-05-13
gpt-4-turbo
Anthropic claude-opus-4
claude-sonnet-4
claude-3-opus
claude-3-sonnet
claude-3.7-sonnet
claude-3-haiku
claude-3.5-haiku
DeepSeek deepseek-chat
deepseek-r1
deepseek-r1-distill-llama-70b
llama-3.3-70b-instruct
llama-3.1-405b-instruct
llama-3.1-70b-instruct
llama-3.1-8b-instruct
gemini-2.5-flash-image-preview
gemini-2.5-flash-lite
gemini-2.5-flash-lite-preview-06-17
gemini-2.5-flash
gemini-2.5-pro
gemini-2.5-pro-preview
gemini-2.5-pro-preview-05-06
gemini-2.0-flash-lite-001
gemini-2.0-flash-001
gemini-2.0-flash-exp:free
gemini-flash-1.5-8b
gemini-flash-1.5
gemini-pro-1.5
gemma-3-4b-it:free
gemma-3-4b-it
gemma-3-12b-it:free
gemma-3-12b-it
gemma-3-27b-it:free
gemma-3-27b-it
gemma-2-27b-it
gemma-2-9b-it:free
gemma-2-9b-it
qwen-2.5-72b-instruct
qwen-2.5-7b-instruct
qwq-32b-preview
Mistral mistral-medium-3.1
codestral-2508
devstral-medium
devstral-small
mistral-small-3.2-24b-instruct:free
mistral-small-3.2-24b-instruct
magistral-small-2506
magistral-medium-2506
Moonshot kimi-k2-0905
kimi-k2-0711
Best Practices
Add property descriptions -> Guides the model to populate fields correctly.
Use strict: true->
Ensure no unexpected or hallucinated fields.
Keep schemas lena -> Simpler schemas yield more reliable results.
Example Implementation
const response = await fetch ( 'https://api.anannas.ai/v1/chat/completions' , {
method: 'POST' ,
headers: {
Authorization: 'Bearer {{API_KEY_REF}}' ,
'Content-Type' : 'application/json' ,
},
body: JSON . stringify ({
model: 'openai/gpt-4o' ,
messages: [{ role: 'user' , content: 'What is the weather like in London?' }],
response_format: {
type: 'json_schema' ,
json_schema: {
name: 'weather' ,
strict: true ,
schema: {
type: 'object' ,
properties: {
location: { type: 'string' , description: 'City or location name' },
temperature: { type: 'number' , description: 'Temperature in Celsius' },
conditions: { type: 'string' , description: 'Weather conditions description' }
},
required: [ 'location' , 'temperature' , 'conditions' ],
additionalProperties: false ,
},
},
},
}),
});
const data = await response . json ();
const weatherInfo = data . choices [ 0 ]. message . content ;
import requests
response = requests.post(
"https://api.anannas.ai/v1/chat/completions" ,
headers = {
"Authorization" : f "Bearer {{ API_KEY_REF }} " ,
"Content-Type" : "application/json" ,
},
json = {
"model" : "openai/gpt-4o" ,
"messages" : [
{ "role" : "user" , "content" : "What is the weather like in London?" },
],
"response_format" : {
"type" : "json_schema" ,
"json_schema" : {
"name" : "weather" ,
"strict" : True ,
"schema" : {
"type" : "object" ,
"properties" : {
"location" : { "type" : "string" , "description" : "City or location name" },
"temperature" : { "type" : "number" , "description" : "Temperature in Celsius" },
"conditions" : { "type" : "string" , "description" : "Weather conditions description" },
},
"required" : [ "location" , "temperature" , "conditions" ],
"additionalProperties" : False ,
},
},
},
},
)
data = response.json()
weather_info = data[ "choices" ][ 0 ][ "message" ][ "content" ]
Streaming with Structured Outputs
Structured outputs also work with streaming.
Just add βstreamβ : true to your request:
{
"stream" : true ,
"response_format" : {
"type" : "json_schema" ,
"json_schema" : {
"name" : "weather" ,
"strict" : true ,
"schema" : { "..." : "..." }
}
}
}
Error Handling
You may encounter:
Model does not support structured outputs -> Error response with unsupported_parameter
Invalid JSON Schema -> Request rejected before completion.
Schema violation -> Response may fail validation in strict mode.
With Anannas, you can unify structured outputs across OpenAI and Anthropic , without needing different request formats.
Was this page helpful? π
Yesπ
No