# Structured output

> Ask a model for JSON that matches a schema. The answer is a JSON string on message.content.


# Structured output

Send `response_format` on a chat completion. The model answers with a JSON string on `choices[0].message.content`. Parse that string. Keep the root of the schema an object. A non-object root is wrapped under a `result` key.

A model supports this when its page lists Structured output under Details. That row is present when the catalog hop advertises `response_format` or `structured_outputs`. Models without that row are not asked to follow a schema.

The shape follows the [OpenAI chat structured outputs guide](https://developers.openai.com/api/docs/guides/structured-outputs?api-mode=chat). AnyRouter forwards the object. It does not rewrite the schema.

```json
{
  "type": "json_schema",
  "json_schema": {
    "name": "founder",
    "strict": false,
    "schema": {
      "type": "object",
      "properties": {
        "name": { "type": "string" }
      },
      "required": ["name"],
      "additionalProperties": false
    }
  }
}
```

`strict` is false. That is the request [Interfaze documents](https://interfaze.ai/docs/structured-output). A `strict: true` body on that hop came back as ordinary prose.

## OpenAI SDK

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://anyrouter.dev/api/v1",
    api_key=os.environ["ANYROUTER_API_KEY"],
)

completion = client.chat.completions.create(
    model="interfaze/interfaze-1.1-lite",
    messages=[{"role": "user", "content": "Who is the founder of Interfaze?"}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "founder",
            "strict": False,
            "schema": {
                "type": "object",
                "properties": {"name": {"type": "string"}},
                "required": ["name"],
                "additionalProperties": False,
            },
        },
    },
)
print(completion.choices[0].message.content)
```

Swap `model` for any listing whose Details card links here. The Try dialog on that page has a visual editor and a code editor for the same schema, and it prints the answer as a JSON code block.


## Related

- [OpenAI SDK](/docs/guides/openai-sdk.md)
- [Vercel AI SDK](/docs/guides/vercel-ai-sdk.md)
- [Tool Use](/docs/features/tool-use.md)
