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

# Structured Output

> Get JSON responses conforming to a schema using the Response API

Pass a JSON Schema in `text.format` to constrain the model's output to a specific structure. The schema definition matches Chat Completions; the parameter path differs.

## Prerequisites

* An [Auriko API key](https://auriko.ai/signup?redirectTo=%2Fdashboard%3Ftab%3Dapi-keys)
* Python 3.10+ with the OpenAI SDK (`pip install openai`) or the Auriko SDK (`pip install auriko`)
  * OR Node.js 18+ with the OpenAI SDK (`npm install openai`) or `@auriko/sdk` (`npm install @auriko/sdk`)

## Return JSON

Constrain the output to valid JSON:

<CodeGroup>
  ```python Python OpenAI theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["AURIKO_API_KEY"],
      base_url="https://api.auriko.ai/v1"
  )

  response = client.responses.create(
      model="gpt-4o",
      input="List 3 programming languages and their main use cases. Respond in JSON.",
      text={"format": {"type": "json_object"}}
  )

  print(response.output_text)
  ```

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

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

  const response = await client.responses.create({
      model: "gpt-4o",
      input: "List 3 programming languages and their main use cases. Respond in JSON.",
      text: { format: { type: "json_object" } },
  });

  console.log(response.output_text);
  ```

  ```python Python Auriko theme={null}
  import os
  from auriko import Client

  client = Client(
      api_key=os.environ["AURIKO_API_KEY"],
      base_url="https://api.auriko.ai/v1"
  )

  response = client.responses.create(
      model="gpt-4o",
      input="List 3 programming languages and their main use cases. Respond in JSON.",
      text={"format": {"type": "json_object"}}
  )

  print(response.output_text)
  ```

  ```typescript TypeScript Auriko theme={null}
  import { Client } from "@auriko/sdk";

  const client = new Client({
      apiKey: process.env.AURIKO_API_KEY,
      baseUrl: "https://api.auriko.ai/v1",
  });

  const response = await client.responses.create({
      model: "gpt-4o",
      input: "List 3 programming languages and their main use cases. Respond in JSON.",
      text: { format: { type: "json_object" } },
  });

  console.log(response.output_text);
  ```

  ```bash cURL theme={null}
  curl https://api.auriko.ai/v1/responses \
    -H "Authorization: Bearer $AURIKO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o",
      "input": "List 3 programming languages and their main use cases. Respond in JSON.",
      "text": {"format": {"type": "json_object"}}
    }'
  ```
</CodeGroup>

Include the word "JSON" in your prompt or instructions. Some models return non-JSON output without it, matching the Chat Completions `json_object` constraint.

## Enforce schema

Constrain the output to a specific JSON Schema:

<CodeGroup>
  ```python Python OpenAI theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["AURIKO_API_KEY"],
      base_url="https://api.auriko.ai/v1"
  )

  response = client.responses.create(
      model="gpt-4o",
      input="Extract contact info: John Doe, john@example.com, 555-0123",
      text={
          "format": {
              "type": "json_schema",
              "name": "contact_info",
              "strict": True,
              "schema": {
                  "type": "object",
                  "properties": {
                      "name": {"type": "string"},
                      "email": {"type": "string"},
                      "phone": {"type": "string"}
                  },
                  "required": ["name", "email", "phone"],
                  "additionalProperties": False
              }
          }
      }
  )

  print(response.output_text)
  ```

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

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

  const response = await client.responses.create({
      model: "gpt-4o",
      input: "Extract contact info: John Doe, john@example.com, 555-0123",
      text: {
          format: {
              type: "json_schema",
              name: "contact_info",
              strict: true,
              schema: {
                  type: "object",
                  properties: {
                      name: { type: "string" },
                      email: { type: "string" },
                      phone: { type: "string" },
                  },
                  required: ["name", "email", "phone"],
                  additionalProperties: false,
              },
          },
      },
  });

  console.log(response.output_text);
  ```

  ```python Python Auriko theme={null}
  import os
  from auriko import Client

  client = Client(
      api_key=os.environ["AURIKO_API_KEY"],
      base_url="https://api.auriko.ai/v1"
  )

  response = client.responses.create(
      model="gpt-4o",
      input="Extract contact info: John Doe, john@example.com, 555-0123",
      text={
          "format": {
              "type": "json_schema",
              "name": "contact_info",
              "strict": True,
              "schema": {
                  "type": "object",
                  "properties": {
                      "name": {"type": "string"},
                      "email": {"type": "string"},
                      "phone": {"type": "string"}
                  },
                  "required": ["name", "email", "phone"],
                  "additionalProperties": False
              }
          }
      }
  )

  print(response.output_text)
  ```

  ```typescript TypeScript Auriko theme={null}
  import { Client } from "@auriko/sdk";

  const client = new Client({
      apiKey: process.env.AURIKO_API_KEY,
      baseUrl: "https://api.auriko.ai/v1",
  });

  const response = await client.responses.create({
      model: "gpt-4o",
      input: "Extract contact info: John Doe, john@example.com, 555-0123",
      text: {
          format: {
              type: "json_schema",
              name: "contact_info",
              strict: true,
              schema: {
                  type: "object",
                  properties: {
                      name: { type: "string" },
                      email: { type: "string" },
                      phone: { type: "string" },
                  },
                  required: ["name", "email", "phone"],
                  additionalProperties: false,
              },
          },
      },
  });

  console.log(response.output_text);
  ```

  ```bash cURL theme={null}
  curl https://api.auriko.ai/v1/responses \
    -H "Authorization: Bearer $AURIKO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o",
      "input": "Extract contact info: John Doe, john@example.com, 555-0123",
      "text": {
        "format": {
          "type": "json_schema",
          "name": "contact_info",
          "strict": true,
          "schema": {
            "type": "object",
            "properties": {
              "name": {"type": "string"},
              "email": {"type": "string"},
              "phone": {"type": "string"}
            },
            "required": ["name", "email", "phone"],
            "additionalProperties": false
          }
        }
      }
    }'
  ```
</CodeGroup>

## Map parameters

| Chat Completions                                                      | Response API                                          |
| --------------------------------------------------------------------- | ----------------------------------------------------- |
| `response_format: {type: "json_object"}`                              | `text: {format: {type: "json_object"}}`               |
| `response_format: {type: "json_schema", json_schema: {name, schema}}` | `text: {format: {type: "json_schema", name, schema}}` |

In Chat Completions, the schema lives under `json_schema.schema`. In the Response API, it's under `format.schema` (one less level of nesting).

See [Structured Output guide](/guides/structured-output) for model support and `strict` parameter behavior.
