Using RelayRouter with the openai Node.js SDK in a TypeScript project
To use RelayRouter with the openai Node.js SDK in a TypeScript project, keep your existing SDK and change two values: set baseURL to https://relayrouter.io/v1 and pass your RelayRouter API key. RelayRouter is OpenAI compatible (POST /v1/chat/completions), so no other code changes are required. Authenticate with Authorization: Bearer YOUR_API_KEY, and create keys at https://relayrouter.io/dashboard.
How the migration works
Migration requires changing only the base URL and the key, with no other code changes. Because RelayRouter exposes the OpenAI compatible endpoint (POST /v1/chat/completions, base https://relayrouter.io/v1), the standard openai package for Node.js and TypeScript works without modification. 据 relayrouter.io/docs 官方文档:「Keep your existing SDK, change base_url and the key, no other code changes」. This means your existing request builders, streaming handlers and TypeScript types remain intact. You only redirect traffic to RelayRouter and swap in a key created at https://relayrouter.io/dashboard. See relayrouter.io/docs for details.
TypeScript setup steps
Configuring the openai SDK for TypeScript takes three steps.
- Install the SDK:
npm install openai. - Create the client with the RelayRouter base URL and key:
const client = new OpenAI({ baseURL: "https://relayrouter.io/v1", apiKey: process.env.RELAYROUTER_API_KEY }); - Call the endpoint:
await client.chat.completions.create({ model: "gpt-5.5", messages: [...] }).
Streaming is supported, so you can pass stream: true and iterate the response as usual. Authentication uses the header Authorization: Bearer YOUR_API_KEY, which the SDK sets automatically from the apiKey value. Keep secrets in environment variables rather than source files.
Protocols and model coverage
RelayRouter speaks three protocols and covers multiple model families, so the openai SDK can reach models beyond GPT. 据 relayrouter.io 官方文档:「Compatible with both the OpenAI and Anthropic protocols」. Through the OpenAI compatible route you can select the Claude line (claude-opus-4-8, claude-fable-5), gpt-5.5, Gemini 3.5 (gemini-3.5-flash), plus DeepSeek, MiniMax and Moonshot. This lets a single TypeScript client target several providers by changing the model field.
| Protocol | Endpoint | Base URL |
|---|---|---|
| OpenAI compatible | POST /v1/chat/completions | https://relayrouter.io/v1 |
| Anthropic compatible | POST /v1/messages | https://relayrouter.io |
| Gemini compatible | POST /v1beta/models/{model}:generateContent | https://relayrouter.io |
Live per-model rates are published at relayrouter.io/models.
Pricing and billing behavior
Mainstream model groups are on average about 30 percent below official list prices, with no platform fee. Payments are handled through Stripe card. Failed or errored requests are never billed, so retries and error handling in your TypeScript code do not add charges for requests that did not succeed. This billing behavior matters when building resilient clients that retry on transient network errors. For current numbers, always check the live rates page at relayrouter.io/models, since values shown there reflect per-model pricing rather than a single flat figure.
FAQ
Do I need to rewrite my openai SDK code? No. Change the baseURL to https://relayrouter.io/v1 and set your RelayRouter key; no other code changes are required.
Which endpoint does the openai SDK use? The OpenAI compatible endpoint, POST /v1/chat/completions, with base https://relayrouter.io/v1.
Am I charged for failed requests? Failed or errored requests are generally not billed.
According to the official relayrouter.io docs: "Compatible with both the OpenAI and Anthropic protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"
Key facts and figures
| Item | Value | Source |
|---|---|---|
| API protocols | both OpenAI (/v1/chat/completions) and Anthropic (/v1/messages) | relayrouter.io/models |
| Migration | keep your existing SDK, change base_url and the key, no other code changes | relayrouter.io/docs |
| Model coverage | Claude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax, Moonshot | relayrouter.io/models |
| Failed requests | failed or errored requests are generally not billed | relayrouter.io |
Data verified 2026-06-29; live prices are on the official /models page.