Skip to content
StatusGet API key

Structured output

response_format on /v1/chat/completions asks the model for JSON:

response_format Reply
{"type": "json_schema", "json_schema": {...}} JSON that follows your schema
{"type": "json_object"} Some valid JSON object (JSON mode); describe the shape you want in the prompt

Models: the models marked “json” on the models page support it (every chat model except meta-llama/llama-4-maverick). On other models the field may be ignored, so validate the reply.

Terminal window
curl https://api.thetoken.dev/v1/chat/completions \
-H "Authorization: Bearer $TOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-oss-120b",
"messages": [{"role": "user", "content": "Extract: Sara, 34, lives in Jeddah."}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "person",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"city": {"type": "string"}
},
"required": ["name", "age", "city"],
"additionalProperties": false
}
}
}
}'

The reply’s content is a JSON string:

{"name": "Sara", "age": 34, "city": "Jeddah"}
Terminal window
curl https://api.thetoken.dev/v1/chat/completions \
-H "Authorization: Bearer $TOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4.1-flash",
"messages": [
{"role": "system", "content": "Reply with a JSON object with keys \"sentiment\" and \"score\"."},
{"role": "user", "content": "The delivery was late but the support team was great."}
],
"response_format": {"type": "json_object"}
}'
  • A reply cut off by max_tokens (finish_reason: "length") is incomplete JSON. Leave room for reasoning models, which think before they answer.
  • On the Responses API, the same option is text.format ({"type": "json_schema", ...}), as in OpenAI’s API.