Docs menu
Core API
Structured outputs
Ask for JSON instead of prose with response_format — either plain JSON mode or a strict schema. Sluice forwards it to the model unchanged.
JSON mode
Set response_format to { "type": "json_object" } and the model returns valid JSON.
const res = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "system", content: "Extract the fields as JSON." },
{ role: "user", content: "Ada Lovelace, born 1815, London." },
],
response_format: { type: "json_object" },
});
JSON.parse(res.choices[0].message.content); // { name: "Ada Lovelace", year: 1815, city: "London" }JSON schema
For a strict shape, pass a json_schema. The model is constrained to your schema on providers that support it.
{
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "person",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"year": { "type": "integer" },
"city": { "type": "string" }
},
"required": ["name", "year", "city"],
"additionalProperties": false
}
}
}
}Provider support
response_format is passed through to the model, so strict JSON-schema support depends on the model you route to. Pin a provider/model with routing controls if you need a specific implementation.