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

# Structured JSON

> Constrain a model response to a JSON Schema through the AI Gateway.

Use `response_format` when your application needs predictable JSON instead of prose. The gateway forwards the schema through the OpenAI-compatible Chat Completions route to a model that supports structured output.

## Generate Schema-Constrained JSON

```typescript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inquantum.ai/v1",
  apiKey: process.env.PLANCK_API_KEY,
});

const response = await client.chat.completions.create({
  model: "gpt-4.1-mini",
  messages: [
    {
      role: "user",
      content: "The customer cannot sign in after rotating their API key.",
    },
  ],
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "support_ticket",
      strict: true,
      schema: {
        type: "object",
        properties: {
          category: {
            type: "string",
            enum: ["account", "billing", "technical"],
          },
          priority: {
            type: "string",
            enum: ["low", "medium", "high"],
          },
          summary: { type: "string" },
        },
        required: ["category", "priority", "summary"],
        additionalProperties: false,
      },
    },
  },
});

const ticket = JSON.parse(response.choices[0].message.content ?? "{}");
console.log(ticket);
```

A matching response looks like:

```json theme={null}
{
  "category": "account",
  "priority": "high",
  "summary": "Customer cannot sign in after rotating an API key."
}
```

## Choosing a Model

Use a model that advertises support for `response_format`. The request remains OpenAI-compatible even when the gateway routes it to another supported provider.

<Note>
  `json_schema` constrains the response to your schema. `json_object` only asks
  for valid JSON and does not enforce required fields or value types.
</Note>

Structured responses are logged in **Requests** like other chat completions, including the request schema and returned JSON.

See [Chat Completions](/rest/ai-gateway/post-v1-chat-completions) for the full request reference.
