Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.opper.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sometimes you want a chat response to be a JSON object you can parse, not a sentence. Set response_format with a JSON Schema and the model will produce JSON that matches it. If you’re building a one-shot extraction or classification task, the JSON API is usually a better fit. Use this when you’re already in a chat flow and need structure for one specific turn.

A working example

import os, json
from openai import OpenAI

client = OpenAI(
    base_url="https://api.opper.ai/v3/compat",
    api_key=os.environ["OPPER_API_KEY"],
)

r = client.chat.completions.create(
    model="openai/gpt-5-mini",
    messages=[
        {"role": "user", "content": "Pick a category for: 'My reset link is broken.'"}
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "ticket",
            "schema": {
                "type": "object",
                "properties": {
                    "category":   {"type": "string"},
                    "priority":   {"type": "string"},
                    "confidence": {"type": "number"},
                },
                "required": ["category", "priority", "confidence"],
            },
        },
    },
)

result = json.loads(r.choices[0].message.content)
print(result["category"], result["priority"])
The content field is a JSON string. Parse it once to get a typed object.

When to use what

NeedReach for
One-shot extraction or classification from a single inputJSON API
Structured response inside an ongoing chatresponse_format: json_schema (this page)
Tool that returns structured arguments to your codeTool calling
Multimodal input (image, PDF, audio) with structured outputJSON API

Tips

  • When the answer is one of a fixed set, use enums. Add "enum": ["low", "medium", "high"] to a property. The model is far more reliable on these than on free strings.
  • Add a "description" to ambiguous properties. The model reads descriptions as guidance.
  • List required fields in the required array. Optional fields can come back as null.

What’s next

JSON API: schemas

The richer schema system for one-shot tasks.

Tool calling

When the model should call your code, not just answer.