LangChain
Use ChatOpenAI with base_url set to the nRouter endpoint. Every chain, tool, and agent runs unchanged.
pip install langchain-openaiProvider docsA fully OpenAI-compatible REST API: every framework, SDK, and tool that already talks to OpenAI talks to nRouter. Change two lines — keep one key, one bill, and built-in guardrails across 151+ models.
No bespoke plugins needed: compatibility is the integration
There is no nRouter SDK you are forced to adopt. These snippets are generated from the canonical SDK examples: the same source the playground and keys page use.
Sign up at nrouter.ai, generate a nRouter virtual key (sk-nrouter-…), and grab the base URL.
Set base_url to the nRouter endpoint and api_key to your key. That is the entire integration.
Your framework, SDK, and observability tooling all run unchanged — now with one key, one bill, and built-in guardrails.
pip install nrouter-sdk| 1 | # Cache: enabled (org default). Pass nrouter_cache: false to skip. |
| 2 | from nroutersdk import nRouter, nRouterGuardrailBlockedError |
| 3 | |
| 4 | client = nRouter() # reads NROUTER_API_KEY from env |
| 5 | |
| 6 | try: |
| 7 | response = client.chat.completions.create( |
| 8 | model="gpt-5.4-mini", |
| 9 | temperature=1, |
| 10 | max_completion_tokens=1024, |
| 11 | messages=[ |
| 12 | {"role": "user", "content": "Hello! What models do you support?"}, |
| 13 | ], |
| 14 | # nrouter_cache=False, # Uncomment to skip cache |
| 15 | ) |
| 16 | print(response.choices[0].message.content) |
| 17 | |
| 18 | # Auto-captured metadata |
| 19 | meta = client.last_response |
| 20 | if meta: |
| 21 | print(f"Cost: ${meta.cost}") |
| 22 | print(f"Guardrails: {meta.guardrails_applied}") |
| 23 | |
| 24 | except nRouterGuardrailBlockedError as e: |
| 25 | print(f"Blocked by guardrail: {e}") |
Base URL is always https://api.nrouter.ai/v1. Works with the official OpenAI SDKs and any OpenAI-compatible client.
Each of these is a standard OpenAI-API client. nRouter does not ship a bespoke plugin for them. It does not need to. They work because the API surface is identical.
Use ChatOpenAI with base_url set to the nRouter endpoint. Every chain, tool, and agent runs unchanged.
pip install langchain-openaiProvider docsPoint the OpenAI LLM class at nRouter. Query engines and retrievers keep working. Only the endpoint moves.
pip install llama-index-llms-openaiProvider docsConfigure the @ai-sdk/openai provider with a custom baseURL. streamText and generateText route through nRouter.
npm install ai @ai-sdk/openaiProvider docsOpenAIGenerator and OpenAIChatGenerator accept an api_base_url: set it to nRouter and your pipelines are unchanged.
pip install haystack-aiProvider docsConfigure CrewAI LLM class with base_url pointing to nRouter. Multi-agent workflows run with server-side guardrails and cost telemetry.
pip install crewaiProvider docsMicrosoft AutoGen v0.4+ OpenAIChatCompletionClient connects directly to nRouter endpoint. Every agent message routes through the gateway.
pip install autogen-agentchat autogen-ext[openai]Provider docsStructured outputs with Pydantic validation. Patch OpenAI client to target nRouter with full schema enforcement.
pip install instructor openaiProvider docsADK speaks the OpenAI-compatible interface. Point it at nRouter to keep one key and one bill.
pip install google-adkMarvin, DSPy, Semantic Kernel… If a library accepts an OpenAI base URL or honors OPENAI_API_BASE, it works. No SDK fork, no shim.
Live, production-tested snippets targeting nRouter unified gateway with server-side guardrails and cost attribution.
pip install nrouter-sdk| 1 | # Cache: enabled (org default). Pass nrouter_cache: false to skip. |
| 2 | import asyncio |
| 3 | from nroutersdk import nRouter, nRouterGuardrailBlockedError |
| 4 | from nroutersdk.memory import create_memory |
| 5 | |
| 6 | # Autonomous Agent using native nRouter SDK primitives |
| 7 | # Features: Server-side guardrails, multi-turn memory, tool execution, and cost telemetry |
| 8 | async def main(): |
| 9 | client = nRouter() # reads NROUTER_API_KEY; defaults to https://api.nrouter.ai/v1 |
| 10 | memory = create_memory() |
| 11 | |
| 12 | await memory.add("system", "You are an autonomous enterprise agent powered by nRouter with memory, tools, and telemetry.") |
| 13 | await memory.add("user", "Hello! What models do you support?") |
| 14 | |
| 15 | print(f"[*] Agent started: model=gpt-5.4-mini") |
| 16 | |
| 17 | try: |
| 18 | messages = await memory.messages() |
| 19 | response = client.nrouter.chat( |
| 20 | model="gpt-5.4-mini", |
| 21 | messages=messages, |
| 22 | temperature=1, |
| 23 | max_completion_tokens=1024, |
| 24 | ) |
| 25 | content = response.choices[0].message.content |
| 26 | await memory.add("assistant", content) |
| 27 | print(f"[*] Response:\n{content}") |
| 28 | |
| 29 | # Enterprise audit & telemetry via client.last_response |
| 30 | meta = client.last_response |
| 31 | if meta: |
| 32 | # cost is None when the model is unpriced -- never read that as 0. |
| 33 | print(f"[*] Telemetry: request_id={meta.request_id} cost={meta.cost} status={meta.cost_status}") |
| 34 | |
| 35 | except nRouterGuardrailBlockedError as e: |
| 36 | print(f"[!] Blocked by enterprise guardrail: {e}") |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | asyncio.run(main()) |
Python
pip install nroutersdk
nRouter SDK or openai
Python (OpenAI)
pip install openai
openai.OpenAI(base_url=…)
Node.js / TypeScript
npm install openai
new OpenAI({ baseURL })
Go
go get github.com/sashabaranov/go-openai
openai.ClientConfig{ BaseURL }
Java
Maven / Gradle — openai-java
OpenAIOkHttpClient.builder()
Ruby
gem install ruby-openai
OpenAI::Client.new(uri_base:)
PHP
composer require openai-php/client
OpenAI::factory()->withBaseUri()
cURL / HTTP
Any HTTP client
POST /v1/chat/completions
Live, runnable snippets for every language are on the playground and your dashboard keys page. If a library honors OPENAI_API_BASE, it already works.
Pointing your client at nRouter is two lines. But those two lines move every request behind a managed gateway: one key for every model, guardrails at the gateway instead of in your framework code, and real cost accounting on every call.
Your code
OpenAI SDK, unchanged
base_url + api_key — two lines, nothing else moves
nRouter gateway
Guardrails · budgets · cost tracking
Every request guarded, attributed, and settled exactly
Providers
151+ models, one bill
We manage every provider key and relationship
Request logs, traces, and metrics forwarded to the tools your platform team already runs. Configured from Logging → Callbacks, with zero changes to your application code. Alerts also fan out over generic webhooks.
Langfuse
Traces, spans, and token usage for prompt analytics and evals. Configured once under Logging → Callbacks.
Datadog
Request logs and latency metrics alongside the rest of your service telemetry.
Amazon S3
Raw request logs archived to a bucket you control: retention, audit, batch analysis.
Slack
Budget and spend thresholds routed to a channel: email, Slack, Teams, or webhook.
Terraform provider: manage keys, teams, budgets, and guardrails as code. Planned, not yet published to the Terraform registry.
CLI tool: a nrouter command for keys, usage, and config from the terminal. In design, no install command to publish yet.
These are full product builds, not marketing pages. We track them as committed roadmap items, not shipped features. Want early access? sales@nrouter.ai
Point your existing client base_url to https://api.nrouter.ai/v1 and supply your sk-nrouter-* virtual key. Because nRouter implements 100% OpenAI API compatibility, no SDK replacement or pipeline rewrite is required.
Yes. Server-Sent Events (SSE) streaming, tool calling, JSON schema validation, and multimodal image/audio payloads are natively supported across all models that offer those capabilities.
Observability integrations for Langfuse, Datadog, Slack, and S3 are dashboard toggles. Telemetry and traces are fanned out asynchronously from the gateway without adding latency to the client inference request.
The high-performance Rust gateway adds under 1 millisecond of internal routing overhead for auth verification, rate limiting, and credit reservation, which is negligible compared to model generation times.
Keep your framework, keep your SDK, keep your observability tooling. Change the base URL and the key: get one bill, built-in guardrails, and real cost tracking.
OpenAI-compatible · one key · guardrails included