Many applications already use the OpenAI SDK. Moving to another compatible gateway should not require rewriting the whole application. In most cases, the main changes are the API key, base URL, and model ID.
This guide shows the basic migration flow with Route Key, an OpenAI-compatible AI API gateway and multi-model router.
Before starting, prepare:
You can review the current supported models and pricing signals in the Route Key model catalog.
For Python:
pip install openai
For Node.js:
npm install openai
Keep the API key in an environment variable. Do not put it directly in source code or commit it to a public repository.
export ROUTEKEY_API_KEY="your-api-key"
export ROUTEKEY_MODEL="your-supported-model-id"
The request format can stay familiar. Point the SDK to the Route Key compatible endpoint:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ROUTEKEY_API_KEY"],
base_url="https://api.routekey.ai/v1",
)
response = client.chat.completions.create(
model=os.environ["ROUTEKEY_MODEL"],
messages=[
{"role": "user", "content": "Explain API routing in one paragraph."}
],
)
print(response.choices[0].message.content)
The exact model ID must come from the current catalog. Do not assume that every provider model supports the same endpoint, tool schema, context length, or streaming behavior.
Start with a short non-streaming request. Check:
If the request fails, verify that the API key is active, the model ID is supported, and the /v1
path has not been duplicated by the SDK configuration.
After the basic request works, test streaming separately. Then add:
A compatible gateway makes it easier to change routing policy without changing every application integration. However, you should still verify tool calls, structured output, image or audio endpoints, and provider-specific behavior before moving production traffic.
Before switching production traffic:
For the full setup flow, see the Route Key integration guide. The official Route Key website includes the model catalog, documentation, and additional integration resources.