Structured Outputs
Return structured data from your models.
Last updated
import requests
import json
response = requests.post(
url="https://llm.onerouter.pro/v1/chat/completions",
headers={
"Authorization": "Bearer <API KEY>",
"Content-Type": "application/json"
},
data=json.dumps({
"model": "openai/gpt-5.2",
"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
}
}
}
})
)
print(response.json()["choices"][0]["message"]["content"]){
"conditions": "Overcast with light rain showers",
"location": "London, United Kingdom",
"temperature": 12.5
}import requests
import json
response = requests.post(
url="https://llm.onerouter.pro/v1/chat/completions",
headers={
"Authorization": "Bearer <API KEY>",
"Content-Type": "application/json"
},
data=json.dumps({
"model": "openai/gpt-5.2",
"messages": [
{"role": "system", "content": "Extract the event information."},
{
"role": "user",
"content": "Alice and Bob are going to a science fair on Friday.",
}
],
"response_format": {
"type": "CalendarEvent"
}
})
)
print(response.json()){
'id': 'gen-1766491236-RRKOrbaRaoxv1ogA56cd',
'model': 'gpt-5.1',
'object': 'chat.completion',
'created': 1766491236,
'choices': [{
'index': 0,
'message': {
'role': 'assistant',
'content': '- Event: Science fair \n- Participants: Alice, Bob \n- Date: Friday \n- Location: Not specified',
'reasoning': "**Extracting event information**\n\nI need to pull event details from the user's sentence, but I’m not sure about the exact format they want. Probably it should be brief, including the event name, date, participants, and location. For example, if it's a science fair, I might list the day as Friday with participants being Alice and Bob. However, I notice there's no location mentioned, so I’ll keep my answer concise while ensuring I cover everything necessary!",
'reasoning_details': [{
'id': '',
'format': 'openai-responses-v1',
'index': 0,
'type': 'reasoning.summary',
'data': ''
}, {
'id': 'rs_0ae935064fdad29601694a8464e37c81908e9a2d8154046487',
'format': 'openai-responses-v1',
'index': 0,
'type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-WXYR8eJ8_aiXQx0JyzAvIlIdtMXXa_d7VQJ6YVPhK21kRLv_FqOVvGudBv3AJWpyQLPpnbbIY='
}]
},
'finish_reason': 'stop',
'native_finish_reason': 'completed',
'logprobs': None
}],
'request_id': '112648cf661f4650ac3c3cdc38832972',
'usage': {
'prompt_tokens': 27,
'completion_tokens': 78,
'total_tokens': 105,
'prompt_tokens_details': {},
'completion_tokens_details': {
'reasoning_tokens': 49
},
'input_tokens': 0,
'output_tokens': 0,
'ttft': 0,
'server_tool_use': {
'web_search_requests': ''
}
}
}{
"stream": true,
"response_format": {
"type": "json_schema",
// ... rest of your schema
}
}