---
title: "Structured output"
description: "Get a JSON object that matches your schema from a Chat Completions or Messages request."
canonical_url: "https://minirouter.sh/docs/structured-output"
markdown_url: "https://minirouter.sh/docs/structured-output.md"
last_updated: "2026-11-01"
---

# Structured output

Get a JSON object that matches your schema from a Chat Completions or Messages request.

## Send a schema request

Add `response_format` with a JSON Schema. This one requires both fields and rejects extra properties.

```sh
curl https://api.minirouter.sh/v1/chat/completions \
  -H "Authorization: Bearer $MINIROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-5.4-mini",
  "max_tokens": 256,
  "messages": [
    {
      "role": "user",
      "content": "Extract the city and country: I live in Paris, France."
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "place",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          },
          "country": {
            "type": "string"
          }
        },
        "required": [
          "city",
          "country"
        ],
        "additionalProperties": false
      }
    }
  }
}'
```

The JSON string is in `choices[0].message.content`, and `finish_reason` is `stop`:

```json
{"city":"Paris","country":"France"}
```

Parse that string and validate it against your schema in your application. A refusal, an error or a `length` finish is not a completed result.

Examples read your key from `MINIROUTER_KEY`. Create one at [minirouter.sh/key](https://minirouter.sh/key).

## Fields

| Field | Effect |
| --- | --- |
| `type` | `json_schema` for a schema, `json_object` for any JSON object, `text` for none. With `json_object`, ask for JSON in the prompt. |
| `json_schema.name` | Required. Up to 64 characters. |
| `json_schema.schema` | Your JSON Schema object. Keep `additionalProperties: false` for an object with only the named fields. |
| `json_schema.strict` | Optional boolean, passed to the provider unchanged. |
| `json_schema.description` | Optional. |

Any other key under `response_format` or `json_schema` returns 400.

## Stream the result

Add `"stream": true` to the same request and use `curl -N`. Join `choices[0].delta.content` until `data: [DONE]`, then parse the whole string. A chunk may hold part of a JSON token.

## Which models enforce it

Models whose `supported_parameters` in the [public catalog](https://minirouter.sh/api/v1/models) list `structured_outputs` (JSON Schema) or `response_format` (JSON mode). MiniRouter sends the request only to providers verified to enforce the format, streaming included.

> **Other models answer in plain text:** The format is removed, the reply is plain text and the response carries `x-minirouter-structured-output: ignored`. The same happens when your key excludes every verified provider. Send `"provider": {"require_parameters": true}` to get a `400` naming the model instead.

## Limits and failures

| You see | Why |
| --- | --- |
| `400 invalid_request_error` | A malformed `response_format`, or a schema over the request limits. Simplify the schema. |
| `429` | Every verified provider is at capacity. A plain request would have moved to another provider. |
| `finish_reason: length` | The object was cut off. Raise `max_tokens` or ask for a smaller object. |
| A refusal | Handle it separately. Do not parse it as your data object. |
| Plain text | The format was not enforced; see the header above. Pick a model listing `structured_outputs`, or send `provider.require_parameters` to fail fast. |

### Messages API

The same schema goes under `output_config.format`. It is enforced on `openai/gpt-4.1-mini` and `anthropic/claude-opus-5` only.

```sh
curl https://api.minirouter.sh/v1/messages \
  -H "Authorization: Bearer $MINIROUTER_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
  "model": "openai/gpt-4.1-mini",
  "max_tokens": 256,
  "messages": [
    {
      "role": "user",
      "content": "Extract the city and country: I live in Paris, France."
    }
  ],
  "output_config": {
    "format": {
      "type": "json_schema",
      "schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          },
          "country": {
            "type": "string"
          }
        },
        "required": [
          "city",
          "country"
        ],
        "additionalProperties": false
      }
    }
  }
}'
```

Join the `text` of `content` blocks whose `type` is `text`, check `stop_reason`, then parse. When streaming, collect `content_block_delta` events with `delta.type: "text_delta"` and parse after `message_stop`.

Responses `text.format` is always removed and flagged with the `ignored` header.

### Routers and fallbacks

[`minirouter/auto`](https://minirouter.sh/docs/auto-router) picks the first candidate that enforces your format and drops the format only when none can.

A [`models` fallback list](https://minirouter.sh/docs/model-fallbacks) keeps the format when the first model enforces it; fallbacks that cannot are left out of that request.

[Auto Free](https://minirouter.sh/docs/free-inference) never enforces a format.

### Combining with other controls

[Thinking](https://minirouter.sh/docs/reasoning) and tool controls have separate model requirements. Start with the schema-only request above, then add them one at a time.

The [`response-healing` plugin](https://minirouter.sh/docs/tools#plugins) repairs malformed JSON on non-streaming Chat Completions replies. It does not check the schema.
