New: Audio API, Embeddings & Realtime WebSocket now available!
RouterBench

Structured Outputs

Get strict JSON that matches your schema from any model, via one OpenAI-compatible parameter.

Structured Outputs

Ask any model to return JSON that conforms to a schema using the standard OpenAI response_format parameter. RouterBench translates your schema to each provider's native structured-output mechanism, so the same request works everywhere — no per-provider code.

ProviderNative mechanism RouterBench maps to
OpenAI (Chat Completions)response_format: { type: "json_schema" }
OpenAI (Responses API, gpt-5.x)text.format
Google GeminigenerationConfig.responseSchema
Anthropic (Claude)forced tool call (schema as the tool)

Usage

Send response_format with a JSON schema. Works with routerbench/auto or any specific model.

curl https://api.routerbench.com/v1/chat/completions \
  -H "Authorization: Bearer $ROUTERBENCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "routerbench/auto",
    "messages": [{ "role": "user", "content": "The capital of France." }],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "location",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": { "city": { "type": "string" }, "country": { "type": "string" } },
          "required": ["city", "country"],
          "additionalProperties": false
        }
      }
    }
  }'
# → { "city": "Paris", "country": "France" }

OpenAI SDK

const res = await client.chat.completions.create({
  model: "routerbench/auto",
  messages: [{ role: "user", content: "The capital of France." }],
  response_format: { type: "json_schema", json_schema: { name: "location", strict: true, schema } },
});

Vercel AI SDK

generateObject / streamObject work out of the box with @routerbench/ai-sdk-provider:

import { RouterBench } from "@routerbench/ai-sdk-provider";
import { generateObject } from "ai";
import { z } from "zod";

const { object } = await generateObject({
  model: RouterBench("routerbench/auto"),
  schema: z.object({ city: z.string(), country: z.string() }),
  prompt: "The capital of France?",
});

json_object mode

If you only need "valid JSON" without a strict schema, use response_format: { type: "json_object" }.

When using json_object with OpenAI models, include the word "json" somewhere in your messages — OpenAI requires it for plain JSON mode.

Reliability

Structured output uses each provider's native enforcement, so responses match your schema. For models without native support, or to repair occasional malformed JSON, add the response-healing plugin as a fallback.

How is this guide?