Back to docs

Integration guide

OpenAI SDK baseURL for Virouter

Configure the OpenAI SDK to call Virouter instead of the default OpenAI host. One base URL lets you route GPT and Claude requests through one Virouter API key.

Use this base URL

OpenAI SDK baseURL / Python base_url

https://api.virouter.com/v1

Keep your API key in a server-side environment variable such as VIROUTER_API_KEY. Never expose it in frontend code.

Node.js example

Use the standard OpenAI package and change only the API key and baseURL.

import OpenAI from "openai";

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

const response = await client.chat.completions.create({
  model: "gpt-5.5",
  messages: [{ role: "user", content: "Hello from Virouter" }],
});

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

Python example

The Python SDK uses base_url.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["VIROUTER_API_KEY"],
    base_url="https://api.virouter.com/v1",
)

response = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Summarize this in one paragraph."}],
)

print(response.choices[0].message.content)

cURL smoke test

Use cURL to confirm the endpoint, key, and model id before wiring the SDK into your app.

curl https://api.virouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $VIROUTER_API_KEY" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{"role":"user","content":"Say ok"}]
  }'

Switching from GPT to Claude

Keep the same client and request shape. Change the model value to a Claude id and Virouter routes the request to Anthropic.

await client.chat.completions.create({
  model: "claude-opus-4-7",
  messages: [{ role: "user", content: "Review this design." }],
});

Troubleshooting

401 Unauthorized

Check Authorization: Bearer vr_sk_... and make sure the key is active in your Virouter dashboard.

404 Not Found

Use https://api.virouter.com/v1 as baseURL/base_url. Do not use https://virouter.com/api/v1 for SDK integrations.

402 Payment Required

Your wallet does not have enough Billing USD Quota for the estimated request. Top up or reduce max output.

503 Unavailable

No healthy upstream lane is available for that model. Retry later or choose another active model id.

Want to call Claude with this same client? Read the Claude with OpenAI SDK guide. Need the broader product overview? Read the OpenAI-compatible API Gateway page or the OpenAI + Anthropic API Gateway page.