Migrate from OpenAI

Most OpenAI-compatible applications only need three configuration changes:

  1. Replace the API key.
  2. Set the Base URL to https://getrouter.ai/v1.
  3. Select a model ID available on GetRouter.

Python

Before:

from openai import OpenAI

client = OpenAI(api_key="OPENAI_API_KEY")

After:

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://getrouter.ai/v1",
)

response = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": "Hello"}],
)

Node.js / TypeScript

Before:

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })

After:

const client = new OpenAI({
  apiKey: process.env.GETROUTER_API_KEY,
  baseURL: 'https://getrouter.ai/v1',
})

const response = await client.chat.completions.create({
  model: 'MODEL_ID',
  messages: [{ role: 'user', content: 'Hello' }],
})

Environment variables

If your application reads standard OpenAI environment variables, you can often update its runtime configuration without changing source code:

export OPENAI_API_KEY="YOUR_API_KEY"
export OPENAI_BASE_URL="https://getrouter.ai/v1"

The exact environment variable names are application-specific. Confirm that your SDK or tool supports a custom Base URL.

Check feature compatibility

OpenAI-compatible request shapes are supported, but capabilities depend on the selected model and endpoint. Verify the features your application uses:

  • Chat Completions or Responses API
  • Streaming
  • Tool or function calling
  • Structured output
  • Vision or other multimodal input
  • Embeddings, images, or audio
Tip

Migrate with a short non-streaming request first. Then enable streaming, tools, reasoning, and other advanced fields one at a time.

Common migration issues

The request goes to the original provider

Confirm that your application is actually reading the custom Base URL. Some applications load environment variables only during startup.

The URL contains /v1/v1

Your application may append /v1 automatically. Use the Base URL format required by that specific client.

The model is rejected

Replace the original provider's model name with an exact ID from GetRouter Models.

Chat works but Responses does not

The two APIs use different endpoints and response event formats. Confirm that the model and integration support POST /v1/responses.

Next steps