> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trylimitless.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Structured output

> Ask a supported model for JSON that follows a schema.

Select a model with structured-output support. The three protocols use different field shapes:

| 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 } }` |

Chat and Responses also accept their native `json_object` format. Include an instruction explaining the intended JSON content.

```javascript theme={null}
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));
```

The model and backend determine supported schema constraints. Validate returned data in your application before using it. Output limits, interruptions, tool calls, and refusals can prevent a complete JSON result. Accumulate streaming text before parsing JSON; individual deltas are usually not complete JSON documents.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.