OpenAI-Compatible API

OpenAI-Compatible API for multi-model applications.

Use the OpenAI SDK, REST format, and streaming patterns you already know while nRouter adds model choice, provider failover, guardrails, budgets, and spend visibility.

openai-api · migration check

Existing client, governed traffic

SDKOpenAI client
Base URLapi.nrouter.ai/v1
ModelAny live catalog model
ControlsGuardrails + budgets
Drop-inStreamingOne key
Changes
2

Base URL and API key

Endpoint
1

OpenAI-compatible request path

BYOK keys
0

Provider credentials managed for you

Features
100%

Governance included on every tier

Written by Suresh, Senior SEO Engineer · Technically reviewed by Rama Surasani, Founder & CEO, CloudAct Inc. · Last updated October 6, 2026

The control layer

Use your OpenAI SDK with nRouter

nRouter provides an OpenAI-compatible API for accessing multiple AI providers through one endpoint. To migrate an existing OpenAI SDK integration, change the base URL and API key, then select a model from the nRouter catalogue. Your existing client structure, streaming code, and message format can remain largely unchanged, while routing, budgets, guardrails, and observability run at the gateway layer.

OpenAI-Compatible API

Base URL Migration: Change Two Configuration Values

Create an nRouter virtual key, point the client at https://api.nrouter.ai/v1, and choose a live model ID. The request format stays familiar; the gateway becomes the provider and governance control plane.

Set NROUTER_API_KEY

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Set OPENAI_BASE_URL to https://api.nrouter.ai/v1

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Verify the selected model ID in the live catalogue

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-Compatible API

Streaming Compatibility and Endpoint Behavior

Chat completions can use stream: true and server-sent events. Handle partial chunks and stream errors in the client. Once output has started, do not assume a request can be transparently replayed to another provider; failover behavior depends on the failure point and endpoint policy.

/v1/chat/completions for chat and streaming

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

/v1/models and /v1/embeddings for discovery and vectors

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

/v1/images, /v1/audio, and /v1/videos where supported

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-Compatible API

Model Aliases and Provider Switching Through One API

Model IDs identify the catalogue entry selected by your request. Check each model’s provider, modality, context window, input and output pricing, and capability flags before production use. Provider abstraction simplifies switching, but it does not make different model capabilities identical.

Live model catalogue and capability metadata

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Text, vision, image, audio, video, and embedding support where available

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Provider-specific context, pricing, and rate limits remain relevant

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-Compatible API

Tool Calls, Structured Output, and Gateway Controls

API compatibility is the integration layer, not the whole product. nRouter can route by policy, apply provider fallback, redact PII, detect prompt injection, enforce organization/team/key budgets, and record request and cost data around the compatible call.

Model routing and provider fallback

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

PII redaction and prompt-injection protection

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Budget enforcement, logs, cost tracking, and attribution

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-Compatible API

OpenAI SDK Migration: Compatibility and Provider Differences

The nRouter endpoint is not an OpenAI product and should not be treated as a promise that every OpenAI-specific parameter behaves identically. Its value is a familiar client contract plus multi-provider access and gateway-level controls.

OpenAI SDK: supported on both

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Multiple providers, cross-provider cost view, and gateway routing: nRouter

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Provider-specific features: verify the live API reference and model catalogue

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-Compatible API

Compatibility limitations and provider differences

Models expose different capabilities. Tool calling, JSON mode, vision, audio, reasoning, streaming, rate limits, and context windows vary by model and provider. Some provider-specific parameters do not transfer. The API reference and live catalogue are the source of truth before rollout.

Test model capabilities instead of assuming parity

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Check endpoint and parameter support before migration

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Verify errors, retries, streaming, and cost headers in staging

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-Compatible API

Verify a migrated application before production

Use a staged rollout: change the base URL and key, verify the model ID, test streaming, tool calling, and error handling, configure budgets and guardrails, confirm cost headers and logs, then enable production traffic gradually.

Base URL and API key changed

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Streaming, tools, errors, budget, and guardrails tested

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

Cost records verified before gradual production rollout

Built into the same managed gateway so teams can ship with one API key, clear controls, and an auditable request path.

OpenAI-compatible API

Copy-paste migration examples

The simplest migration changes the base URL and key. The examples below use the tested OpenAI-compatible request shape; confirm the selected model and endpoint capability in the API reference before adding provider-specific parameters.

// Node.js — OpenAI SDK
import OpenAI from "openai";
const client = new OpenAI({
  apiKey: process.env.NROUTER_API_KEY,
  baseURL: "https://api.nrouter.ai/v1",
});
const response = await client.chat.completions.create({
  model: "gpt-5",
  messages: [{ role: "user", content: "Explain model routing in one sentence." }],
});
console.log(response.choices[0].message.content);

# Python
from openai import OpenAI
client = OpenAI(api_key="your-nrouter-key", base_url="https://api.nrouter.ai/v1")
response = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "What is an OpenAI-compatible API?"}],
)

# Environment variables
export OPENAI_API_KEY="your-nrouter-key"
export OPENAI_BASE_URL="https://api.nrouter.ai/v1"

# cURL
curl https://api.nrouter.ai/v1/chat/completions \
  -H "Authorization: Bearer $NROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5","messages":[{"role":"user","content":"Explain provider failover."}]}'

# Streaming: add stream: true and consume server-sent event chunks.
# LangChain, LlamaIndex, Vercel AI SDK, and CrewAI can use the same base URL
# when their OpenAI-compatible provider accepts a custom endpoint.
Gateway comparison

Supported OpenAI-compatible endpoints

GatewayBest known fornRouter perspective
/v1/chat/completionsChat and streaming completionsSupported through the OpenAI-compatible request format; model capability and streaming behavior vary by model.
/v1/modelsModel discoveryReturns the live catalogue surface used to verify IDs and capabilities.
/v1/embeddingsEmbeddingsAvailable where the selected embedding model and provider support the endpoint.
/v1/imagesImage generationAvailable where supported by the selected model and provider.
/v1/audio and /v1/videosAudio operations and video jobsAvailable where supported; consult the API reference for request and polling behavior.
Pricing

Compatible API with governance included

nRouter passes through provider list prices with 0% token markup. Pay-as-you-go credits currently carry a 4% platform fee added on top. The compatible API layer also connects to routing, guardrails, budgets, and observability; see the pricing page for current allowances and terms.

FAQ

Common openai-compatible api questions

What is an OpenAI-compatible API?

It is an API that follows familiar OpenAI client and request conventions so applications can use a compatible SDK or REST shape against another gateway or provider layer.

Does nRouter work with the OpenAI Python SDK?

Yes. Set the client base_url to https://api.nrouter.ai/v1 and use an nRouter virtual key, then select a model from the live catalogue.

What base URL does nRouter use?

The canonical base URL is https://api.nrouter.ai/v1.

Can I use an OpenAI-compatible API with Claude or Gemini models?

Yes, where the model is available in the nRouter catalogue and supports the requested endpoint. Check the model capability metadata because provider features and parameters vary.

Does nRouter support streaming?

Streaming chat completions use stream: true and server-sent event chunks. Your client should handle partial output and stream errors; do not assume mid-stream replay to another provider.

Can I use embeddings through nRouter?

Yes, where the selected embedding model and provider support /v1/embeddings. Verify the live catalogue and API reference before rollout.

Can I migrate from OpenRouter without rewriting my application?

Usually the migration starts with changing the endpoint, key, and model ID, followed by testing provider-specific parameters, streaming, errors, budgets, and guardrails.

Does nRouter support tool calling?

Tool calling is supported where the selected model and provider expose it. Test the exact model, schema, and response behavior because tool support is not identical across providers.

Are provider-specific parameters supported?

Some parameters are provider- or model-specific and may not transfer through a common API. The API reference and model catalogue are the source of truth.

How does nRouter handle model failover?

Configured routing can select eligible fallback providers or models for retryable failures, subject to capability, budget, timeout, and policy checks.

Build on one gateway

Move from prototype to governed production AI.

Start with one OpenAI-compatible key, then add routing, budgets, guardrails, and observability as your workload grows.