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

ClientKey settingBase URL setting
Python openaiapi_keybase_url
Node.js openaiapiKeybaseURL
Tools using environment variablesOPENAI_API_KEYOPENAI_BASE_URL
Generic HTTP clientsAuthorization: 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:

FieldGuidance
modelUse an exact model ID from Models or GET /v1/models.
messagesSend OpenAI-style chat messages.
temperatureOptional. Keep defaults for first tests.
max_tokensOptional. Use a small value for setup checks.
streamDo not rely on streaming unless the relevant page documents support for your client and model.
toolsVerify 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

FailureLikely causeFix
invalid_api_keyWrong key value, missing Bearer, expired key, disabled key, or key from another serviceCheck the key and the base URL together.
model_not_foundModel ID typo or the key's model scope excludes that modelCopy the model ID from Models and create a replacement key if scope is too narrow.
insufficient_quotaAccount balance or key budget is not enoughAdd balance or create a replacement key with the right budget.
TimeoutSlow model, short client timeout, network proxy, or large requestRaise the client timeout or choose a faster model.

Wrong vs right

WrongRight
NexoRouter key with https://api.openai.com/v1NexoRouter key with https://api.nexorouter.com/v1
OpenAI key with https://api.nexorouter.com/v1NexoRouter key with https://api.nexorouter.com/v1
Full key pasted into support chatKey name, last four characters, and request ID
OpenAI-compatible Chat Completions — NexoRouter