Skip to main content
You can force models to return valid JSON, optionally conforming to a specific schema.

Prerequisites

  • An Auriko API key
  • Python 3.10+ with auriko SDK installed (pip install auriko)
    • OR Node.js 18+ with @auriko/sdk installed (npm install @auriko/sdk)

Choose a response format

Auriko supports three response format types:
TypeDescriptionUse case
textDefault. Model returns plain text.General chat, creative writing
json_objectModel returns valid JSON. No schema enforcement.Flexible JSON extraction
json_schemaModel returns JSON matching a provided schema.Typed data extraction, API responses
json_schema and json_object are separate capabilities. json_schema has broader model support. Claude supports json_schema but not json_object. If you request an unsupported mode, Auriko returns a 503 with a suggested alternative.
Check per-model support on the models page or via the Directory API. json_schema appears as Structured Output, json_object as JSON Mode.

Return JSON

To return any JSON output, set response_format to json_object:
import os
from auriko import Client

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

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "Extract the user's name and age as JSON."},
        {"role": "user", "content": "I'm Alice and I'm 30 years old."}
    ],
    response_format={"type": "json_object"}
)

print(response.choices[0].message.content)
# {"name": "Alice", "age": 30}
The model returns valid JSON, but the structure isn’t guaranteed. For strict schema conformance, use json_schema instead.
When using json_object mode, always include the word “JSON” in your system or user message. OpenAI and DeepSeek require this and return a 400 error without it. Including it is harmless on other providers. The json_schema mode does not have this requirement.The examples above include “JSON” in the system message.

Enforce schema

You can enforce a specific JSON structure by providing a schema:
import os
import json
from auriko import Client

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

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Extract: Alice is 30, lives in NYC, [email protected]"}
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "ContactInfo",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"},
                    "city": {"type": "string"},
                    "email": {"type": "string"}
                },
                "required": ["name", "age", "city", "email"]
            }
        }
    }
)

contact = json.loads(response.choices[0].message.content)
print(contact["name"])   # Alice
print(contact["email"])  # [email protected]
The json_schema object requires a name field. The schema field accepts a standard JSON Schema definition.
Auriko automatically routes to providers that support your requested format. If no provider supports it, you get a clear error with suggestions.

Use OpenAI SDK

You can use the standard OpenAI SDK pointed at Auriko:
import os
from openai import OpenAI

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

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Extract: Bob is 25, lives in London, [email protected]"}
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "ContactInfo",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"},
                    "city": {"type": "string"},
                    "email": {"type": "string"}
                },
                "required": ["name", "age", "city", "email"]
            }
        }
    }
)

print(response.choices[0].message.content)
# {"name": "Bob", "age": 25, "city": "London", "email": "[email protected]"}
The same response_format field works with both the Auriko SDK and the OpenAI SDK.

Resources

Tool calling

Call functions from LLM responses

Routing options

Optimize for cost, speed, or throughput

Error handling

Handle errors and retries

Browse models

See which models support structured output and JSON mode