Documentation
OpenAI-compatible Chat Completions in the NexoRouter documentation.
OpenAI-compatible Chat Completions
Status: Stable public API.
NexoRouter's primary public integration path is the OpenAI-compatible POST /v1/chat/completions endpoint. Most SDKs and tools should start here.
Use this when
- You already use the OpenAI SDK and want to change provider with minimal code changes.
- A tool asks for an OpenAI-compatible, Custom OpenAI, or OpenAI API provider.
- Your app sends text chat requests through
messages. - You want request IDs, cost, latency, and result status to appear in Usage Logs.
Do not use this page as proof that Responses API, native Claude, native Gemini, embeddings, streaming, vision, image, video, or audio endpoints are supported.
Endpoint
Base URL: https://api.nexorouter.com/v1
Endpoint: POST /v1/chat/completions
Header: Authorization: Bearer YOUR_NEXOROUTER_API_KEY
SDK setup
| Client | Key setting | Base URL setting |
|---|---|---|
Python openai | api_key | base_url |
Node.js openai | apiKey | baseURL |
| Tools using environment variables | OPENAI_API_KEY | OPENAI_BASE_URL |
| Generic HTTP clients | Authorization: Bearer ... | full request URL |
For tools that reuse OpenAI environment variable names, set:
export OPENAI_API_KEY="$NEXOROUTER_API_KEY"
export OPENAI_BASE_URL="https://api.nexorouter.com/v1"
Keep those variables scoped to the shell, service, or project that should use NexoRouter.
Minimal request
curl https://api.nexorouter.com/v1/chat/completions \
-H "Authorization: Bearer $NEXOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{ "role": "user", "content": "Write one short production checklist." }
],
"max_tokens": 256
}'
SDK migration rule
When moving existing OpenAI SDK code, keep the request body shape and change only:
apiKey -> NexoRouter API key
baseURL -> https://api.nexorouter.com/v1
model -> a model ID from NexoRouter Models
Python:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_NEXOROUTER_API_KEY",
base_url="https://api.nexorouter.com/v1",
)
Node.js:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.NEXOROUTER_API_KEY,
baseURL: "https://api.nexorouter.com/v1",
});
Go:
package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey(os.Getenv("NEXOROUTER_API_KEY")),
option.WithBaseURL("https://api.nexorouter.com/v1"),
)
completion, err := client.Chat.Completions.New(
context.Background(),
openai.ChatCompletionNewParams{
Model: "deepseek-v4-flash",
Messages: []openai.ChatCompletionMessageParamUnion{
openai.UserMessage("Write one short production checklist."),
},
},
)
if err != nil {
panic(err)
}
fmt.Println(completion.Choices[0].Message.Content)
}
.NET:
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;
ChatClient client = new(
model: "deepseek-v4-flash",
credential: new ApiKeyCredential(
Environment.GetEnvironmentVariable("NEXOROUTER_API_KEY")
),
options: new OpenAIClientOptions
{
Endpoint = new Uri("https://api.nexorouter.com/v1")
}
);
ChatCompletion completion = client.CompleteChat("Write one short production checklist.");
Console.WriteLine(completion.Content[0].Text);
Other languages:
Use an OpenAI-compatible client only if it lets you set both:
api key = NexoRouter API key
base URL = https://api.nexorouter.com/v1
Request body boundary
Start with the common Chat Completions fields:
| Field | Guidance |
|---|---|
model | Use an exact model ID from Models or GET /v1/models. |
messages | Send OpenAI-style chat messages. |
temperature | Optional. Keep defaults for first tests. |
max_tokens | Optional. Use a small value for setup checks. |
stream | Do not rely on streaming unless the relevant page documents support for your client and model. |
tools | Verify per model and tool before production agent workflows. |
Verify
After the first request, open Usage Logs and confirm the API key, model ID, result status, token counts, cost, latency, and request ID.
Common failures
| Failure | Likely cause | Fix |
|---|---|---|
invalid_api_key | Wrong key value, missing Bearer, expired key, disabled key, or key from another service | Check the key and the base URL together. |
model_not_found | Model ID typo or the key's model scope excludes that model | Copy the model ID from Models and create a replacement key if scope is too narrow. |
insufficient_quota | Account balance or key budget is not enough | Add balance or create a replacement key with the right budget. |
| Timeout | Slow model, short client timeout, network proxy, or large request | Raise the client timeout or choose a faster model. |
Wrong vs right
| Wrong | Right |
|---|---|
NexoRouter key with https://api.openai.com/v1 | NexoRouter key with https://api.nexorouter.com/v1 |
OpenAI key with https://api.nexorouter.com/v1 | NexoRouter key with https://api.nexorouter.com/v1 |
| Full key pasted into support chat | Key name, last four characters, and request ID |