Skip to main content
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
  • 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:
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)
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:
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)

Map parameters

Chat CompletionsResponse 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 for model support and strict parameter behavior.