Skip to content
Rapid Router
Guides · Build

Structured output

JSON mode and JSON schema through response_format, emulated on Anthropic models.

Ask for JSON with response_format on POST /chat/completions. { "type": "json_object" } asks for any valid JSON object; { "type": "json_schema", "json_schema": { "name", "schema", "strict" } } asks for JSON that matches your schema. The answer arrives as a JSON string in choices[0].message.content, ready to parse.

curl https://rapidrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $RAPIDROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-3.6-flash",
    "messages": [{ "role": "user", "content": "Extract: Asha, 31, Pune" }],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "person",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "age": { "type": "integer" },
            "city": { "type": "string" }
          },
          "required": ["name", "age", "city"],
          "additionalProperties": false
        }
      }
    }
  }'

# -> choices[0].message.content: "{\"name\":\"Asha\",\"age\":31,\"city\":\"Pune\"}"

Anthropic models. Anthropic's API has no response_format, so the gateway emulates it: the schema becomes a tool the model is made to call, and the arguments of that call come back as the message content with finish_reason: "stop", the same as on any other model. One difference: with stream: true the JSON arrives in a single chunk rather than token by token.

Which models. capabilities.json in GET /models marks the models that support JSON output. On /v1/responses, text.format with json_schema or json_object does the same thing.

Almost-JSON. A model can still wrap the answer in a markdown fence, leave a trailing comma, or run out of max_tokens mid-object. Add the response-healing plugin and the gateway repairs those without a second model call.