Back to docs

Integration guide

Use Claude with the OpenAI SDK

Virouter lets you call Claude models with the OpenAI SDK chat completions shape. Change the baseURL, keep one Virouter API key, and choose a Claude model id.

1. Configure the OpenAI SDK

Use the Virouter OpenAI-compatible endpoint as your SDK base URL. Store the key server-side in VIROUTER_API_KEY.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.VIROUTER_API_KEY,
  baseURL: "https://api.virouter.com/v1",
});

2. Send a Claude chat completion

Keep the OpenAI chat completions method and pass a Claude model id. Virouter routes the request to the Anthropic lane behind the scenes.

const response = await client.chat.completions.create({
  model: "claude-opus-4-7",
  messages: [
    { role: "system", content: "You are concise and practical." },
    { role: "user", content: "Review this API design." },
  ],
});

console.log(response.choices[0]?.message?.content);

3. Switch between GPT and Claude

Your app can use the same client and wallet for both provider families. Change only the model field.

await client.chat.completions.create({
  model: "gpt-5.5",
  messages,
});

await client.chat.completions.create({
  model: "claude-sonnet-4-6",
  messages,
});

Claude model ids

Available models depend on active provider channels and your key allowlist. Use GET /v1/models for the current list.

Model idUse case
claude-opus-4-7High-quality reasoning lane when available.
claude-opus-4-6Opus tier for deep analysis and long-context work.
claude-sonnet-4-6Balanced Claude model for product workloads.
claude-fable-5-20260612Claude Fable 5 lane at $10 / $50 per M input/output tokens when enabled.

Response cost and token headers

Claude calls through the OpenAI SDK still return Virouter gateway headers for cost and quota tracking.

x-virouter-cost-usd

Billing USD cost for the completed Claude request.

x-virouter-remaining-usd

Remaining Billing USD Quota.

x-virouter-input-tokens

Input tokens.

x-virouter-output-tokens

Output tokens.

Troubleshooting

400 model not allowed

The model id is not currently active for your key or provider channel. Call /v1/models or check model access docs.

401 unauthorized

The Virouter key is missing, invalid, revoked, or not sent as Authorization: Bearer vr_sk_...

402 payment required

Your Billing USD Quota is too low for the estimated request. Top up or lower max output.

503 upstream unavailable

No healthy Anthropic lane is available for that Claude model. Retry or choose another active model.

Using Claude Code? Read Set up Claude Code with Virouter API. Need the base URL guide first? Read OpenAI SDK baseURL for Virouter. For product overview, see OpenAI + Anthropic API Gateway.