The Ottili AI API can constrain responses to a JSON schema so you get parseable data instead of free text. Not every model supports structured outputs — check the model's capabilities first.
Request
{
"model": "auto",
"messages": [{ "role": "user", "content": "Extract the customer name and order total." }],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "order_summary",
"schema": {
"type": "object",
"properties": {
"customer_name": { "type": "string" },
"order_total": { "type": "number" }
},
"required": ["customer_name", "order_total"],
"additionalProperties": false
}
}
}
}Response
The assistant content is valid JSON matching the schema:
{
"choices": [
{
"message": {
"role": "assistant",
"content": "{\"customer_name\":\"Acme GmbH\",\"order_total\":1299.0}"
},
"finish_reason": "stop"
}
]
}Notes
- The schema must be a valid JSON Schema object; an invalid or oversized
schema returns invalid_request_error (HTTP 422).
- Streaming is compatible with structured outputs; the final event carries the complete object.
- If the selected model does not advertise
structured_outputsin its capabilities, the API returns a clear capability error instead of an unconstrained reply.
Was this article helpful?
