Chat and Responses also accept their native
json_object format. Include an instruction explaining the intended JSON content.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Sandbox beta: test payments, real inference. Learn about billing.
Ask a supported model for JSON that follows a schema.
| Protocol | JSON-schema field |
|---|---|
| Chat | response_format: { type: "json_schema", json_schema: { name, strict, schema } } |
| Responses | text: { format: { type: "json_schema", name, strict, schema } } |
| Messages | output_config: { format: { type: "json_schema", schema } } |
json_object format. Include an instruction explaining the intended JSON content.
const result = await client.chat.completions.create({
model: process.env.LIMITLESS_MODEL,
messages: [{ role: "user", content: "Return a JSON object naming one primary color." }],
response_format: {
type: "json_schema",
json_schema: {
name: "color",
strict: true,
schema: {
type: "object",
properties: { name: { type: "string" } },
required: ["name"],
additionalProperties: false,
},
},
},
max_tokens: 512,
});
const choice = result.choices[0];
if (choice?.finish_reason !== "stop") throw new Error("JSON generation did not complete");
console.log(JSON.parse(choice.message.content));