Structured outputs
Structured outputs make the model answer with JSON of a given shape. You describe the keys, types, and required fields once in a schema, and you do not have to parse free text.
To check whether a model supports them, look in GET /v1/models: capabilities.features includes structured_outputs (strict schema) or response_format (JSON mode without a schema). See Models.
Chat Completions
Section titled “Chat Completions”Pass the schema in response_format with the type json_schema.
curl https://api.waibee.com/v1/chat/completions \ -H "Authorization: Bearer $WAIBEE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-5.4-mini", "messages": [ { "role": "user", "content": "Extract the data: Ivan Petrov, 34 years old, Berlin, senior backend." } ], "response_format": { "type": "json_schema", "json_schema": { "name": "person", "strict": true, "schema": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" }, "city": { "type": "string" }, "role": { "type": "string" } }, "required": ["name", "age", "city", "role"], "additionalProperties": false } } } }'The response is an ordinary message, with the JSON as a string in content:
{ "choices": [{ "index": 0, "finish_reason": "stop", "message": { "role": "assistant", "content": "{\"name\":\"Ivan Petrov\",\"age\":34,\"city\":\"Berlin\",\"role\":\"senior backend\"}" } }], "usage": { "prompt_tokens": 66, "completion_tokens": 28, "total_tokens": 94 }}json_schema fields:
| Field | Purpose |
|---|---|
name | The schema name. The model sees it and treats it as a hint about what the object means |
strict | true requires an exact match with the schema |
schema | The schema itself, in JSON Schema format |
The simpler {"type": "json_object"} mode requires only valid JSON, with no schema. Use it when you do not need the response in a particular shape.
Messages
Section titled “Messages”On POST /v1/messages, set the structure with the format field inside output_config:
{ "model": "anthropic/claude-sonnet-5", "max_tokens": 1024, "output_config": { "format": { "type": "json_schema", "schema": { "type": "object", "properties": { "city": { "type": "string" }, "temp_c": { "type": "number" } }, "required": ["city", "temp_c"] } } }, "messages": [{ "role": "user", "content": "It is 19 degrees in Berlin. Format the answer to the schema." }]}The response is a text block with the JSON inside: {"city":"Berlin","temp_c":19}.
output_config is passed to the provider as is, so the fields it accepts depend on the model. The reasoning level is set there too; see Reasoning.
Responses
Section titled “Responses”On POST /v1/responses, set the schema with the format field inside the text object, with type: "json_schema". The request goes to the model as is, and the JSON comes back as text in a message item of the output list.
What to keep in mind
Section titled “What to keep in mind”- A schema constrains the shape, not the meaning. The model fills in every required field even when the input has no data for it: give “unknown” an explicit value (
nullin the list of types, or a flag field). - Keep the schema flat. Deep nesting and large
oneOflead to refusals and extra tokens noticeably more often. Two requests with simple schemas are often easier. - A schema does not replace validation. Parse the response with your own validator: you still need it to tell a model failure from a usable response.
- The length limit cuts off the JSON. If the response hits
max_tokens, you get an unclosed string withfinish_reason: "length". Check for this separately from parse errors. - Do not combine with streaming unless you need to. Partial JSON in a stream cannot be fully parsed until generation ends anyway.
- Function arguments have their own schema. Structured outputs describe the model’s response, not tool calls; see Tool calling.