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 settingNexoRouter value
API keyNexoRouter API key
Base URLhttps://api.nexorouter.com/v1
ModelExact model ID from Models or GET /v1/models
Request methodchat.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

  1. Send one small non-streaming chat request.
  2. Confirm it appears in Usage Logs.
  3. Confirm the expected key, model ID, tokens, cost, latency, result status, and request ID.
  4. Add larger prompts, tool workflows, or streaming only after the basic request works.
OpenAI SDK migration — NexoRouter