Documentation
OpenAI SDK migration in the NexoRouter documentation.
OpenAI SDK migration
Status: Stable for documented Chat Completions calls.
Most OpenAI SDK chat code can use NexoRouter after changing the API key, base URL, and model ID.
Migration rule
| Existing OpenAI setting | NexoRouter value |
|---|---|
| API key | NexoRouter API key |
| Base URL | https://api.nexorouter.com/v1 |
| Model | Exact model ID from Models or GET /v1/models |
| Request method | chat.completions.create |
Do not switch SDK code to /v1/responses for NexoRouter unless a NexoRouter page explicitly documents that endpoint.
Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_NEXOROUTER_API_KEY",
base_url="https://api.nexorouter.com/v1",
)
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "Reply with one sentence."}],
)
print(response.choices[0].message.content)
Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.NEXOROUTER_API_KEY,
baseURL: "https://api.nexorouter.com/v1",
});
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "Reply with one sentence." }],
});
console.log(response.choices[0].message.content);
Environment variable mode
Use this only in a shell, service, or project that should send OpenAI-compatible calls to NexoRouter:
export OPENAI_API_KEY="$NEXOROUTER_API_KEY"
export OPENAI_BASE_URL="https://api.nexorouter.com/v1"
Do not overwrite real OpenAI credentials in shared production environments.
Verify
- Send one small non-streaming chat request.
- Confirm it appears in Usage Logs.
- Confirm the expected key, model ID, tokens, cost, latency, result status, and request ID.
- Add larger prompts, tool workflows, or streaming only after the basic request works.