Skip to main content
When you want a response you can parse rather than a sentence, set response_format to a JSON Schema. The model produces JSON that matches it, and the gateway validates the response against the schema before returning it. This is the standard OpenAI-compatible parameter, so it works from any SDK you point at Opper. Reach for structured output to parse a receipt, extract fields from a contract, classify a support ticket, or any job where you describe the shape you want back.

A working example

The content field comes back as a JSON string. Parse it once to get a typed object. If the model can’t produce something that matches the schema, the call fails with a validation error rather than silently returning malformed JSON.
The Anthropic and Google AI SDKs reach the same behaviour through their own structured-output options. Whichever SDK you use, the gateway validates the result against your schema. See Drop-in SDKs.

Writing the schema

The schema is plain JSON Schema. A handful of patterns cover almost everything you’ll need.

Enums (one of a fixed set)

When the answer is one of a fixed set of values, use an enum. The model is far more reliable on these than on free strings.

Optional fields

List required fields in the required array. Anything left out can come back as null.

Arrays

Nested objects

Field descriptions

Describe ambiguous fields. The model reads descriptions as guidance.

Structured output from images, PDFs, and audio

Structured output composes with multimodal input. Put the image, PDF, or audio in the message content and set response_format to the shape you want back. See Vision & PDFs for how to attach media.

When to use what

What’s next

Tool calling

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

Vision & PDFs

Send images and documents, get structure back.

Streaming

Stream the response as it’s generated.

Control Plane

Govern, score, and improve every call.