Endpoints
Structured outputs
Force valid JSON that matches your JSON Schema with response_format on api14, for data extraction, classification and typed API responses.
Try it in the playgroundStructured outputs make a model return JSON that matches a JSON Schema you provide. Use them for extraction, classification and any reply your code parses. Set response_format on Chat completions (or text.format on Responses).
Request parameters
| Parameter | Type | Description |
|---|---|---|
response_format.type | string | "json_schema" for schema-constrained output. "json_object" for free-form JSON mode. |
response_format.json_schema.name | string | A name for the schema. |
response_format.json_schema.strict | boolean | true enforces the schema exactly where the provider supports it. |
response_format.json_schema.schema | object | A JSON Schema. With strict, use additionalProperties: false and list every property in required. |
{
"model": "openai/gpt-5-mini",
"messages": [{ "role": "user", "content": "Extract: Ada Lovelace, born 1815 in London." }],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "person",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"born": { "type": "integer" },
"city": { "type": "string" }
},
"required": ["name", "born", "city"],
"additionalProperties": false
}
}
}
}
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api14.com/api/v1",
apiKey: process.env.API14_API_KEY,
});
const result = await client.chat.completions.create({
"model": "openai/gpt-5-mini",
"messages": [
{
"role": "user",
"content": "Extract the city and country from: \"I live in Lisbon, Portugal.\""
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "place",
"strict": true,
"schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"country": {
"type": "string"
}
},
"required": [
"city",
"country"
],
"additionalProperties": false
}
}
}
});
console.log(JSON.parse(result.choices[0].message.content));
Response
The JSON arrives as a string in message.content:
{
"id": "gen-1760000000-json1",
"model": "openai/gpt-5-mini",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": { "role": "assistant", "content": "{\"name\":\"Ada Lovelace\",\"born\":1815,\"city\":\"London\"}" }
}
],
"usage": { "prompt_tokens": 71, "completion_tokens": 18, "total_tokens": 89, "cost": 0.0000538 }
}
The SDK helpers work as usual, for example client.chat.completions.parse(...) with Zod in Node or Pydantic in Python.
Model support
- To find models that support it, check
supported_parametersin Models forstructured_outputsorresponse_format. - To make sure the request only goes to providers that honour the schema, add
provider: { "require_parameters": true }. - Models without native support may still produce JSON if you ask for it in the prompt, but the output is not guaranteed. Always validate it.
- If
finish_reasonis"length", the JSON is truncated. Raisemax_tokens.
Errors
An invalid schema usually returns an upstream 400 with the provider's message. Other errors are the same as for Chat completions. See Errors.