Integrations
If it speaks the OpenAI API, it works with nRouter.
Point any OpenAI-compatible framework, SDK, or HTTP client at one base URL and one virtual key.
Three steps, two lines of code.
Base URL is http://localhost:4111/v1. Works with official nRouter SDKs and any OpenAI-compatible client.
1. Create a key.
Sign up at nrouter.ai, generate an sk-nrouter-* virtual key, and copy the endpoint.
2. Point your client.
Set base_url to http://localhost:4111/v1 and api_key to your virtual key.
3. Ship.
Your framework, SDK, and tooling run unchanged with one key, one bill, and 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; defaults to https://api.nrouter.ai/v1 |
| 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}") # x-nr-guardrails: pass, redacted, ... |
| 23 |
|
| 24 | except nRouterGuardrailBlockedError as e: |
| 25 | print(f"Blocked by guardrail: {e}") |
Frameworks you already use.
Standard OpenAI-API clients work directly without bespoke plugins or SDK forks.
LangChain
Use ChatOpenAI with base_url set to nRouter. Chains, tools, and agents run unchanged.pip install langchain-openaiLlamaIndex
Point the OpenAI LLM class at nRouter. Query engines and retrievers keep working.pip install llama-index-llms-openaiVercel AI SDK
Configure @ai-sdk/openai with a custom baseURL for streamText and generateText.npm install ai @ai-sdk/openaiCrewAI
Point the CrewAI LLM class at nRouter for multi-agent workflows with guardrails.pip install crewaiAutoGen
Connect OpenAIChatCompletionClient to the nRouter endpoint for multi-agent chat.pip install autogen-agentchat autogen-ext[openai]Instructor
Structured outputs with Pydantic validation and schema enforcement over OpenAI.pip install instructor nrouter-sdk
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()) |
More than a base URL.
Two lines move every request behind a managed gateway with guardrails and cost accounting.
One key for every model.
Switch models by changing a single string. nRouter manages the provider credentials.
- No per-provider API keys to rotate
- Scope allowed models per virtual key
- 0% platform fee at exact model list price
Guardrails in the request path.
PII redaction, prompt-injection defense, and moderation run at the gateway.
- Enforced before requests reach a provider
- A refused call holds and spends $0
- No guardrail code to maintain in each service
Real-time spend and budgets.
Track per-key and per-team spend with credits reserved before every call.
- Credits reserve before dispatch and settle at list price
- Pay as you go from a $5 minimum purchase
- Budget caps per team and per key
Request logs, built in.
Per-request traces, headers, and cost on every call with zero changes to application code.
Request logs
Every request in the dashboard with model, status, latency, tokens, and settled cost.CSV export
Export request logs from the dashboard for retention, audit, and batch analysis.Response headers
x-nr-request-id, x-nr-request-cost, and x-nr-model on every response; tag with x-nr-tags.Alerts
Route budget and spend threshold notifications to email, Slack, Teams, or webhook.
FAQs
How do I switch an existing OpenAI codebase to nRouter?
Point your existing client base_url to http://localhost:4111/v1 and supply your sk-nrouter-* virtual key. nRouter exposes an OpenAI-compatible API, so no SDK replacement or pipeline rewrite is required.
Does nRouter support streaming, tool use, and function calling?
Yes. Server-sent event streaming, tool and function calling, and structured JSON output pass through for every model that offers those capabilities.
How does observability work?
Every request lands in the dashboard request log with its model, status, latency, tokens, and cost. Logs can be exported as CSV, and every response carries x-nr-request-id, x-nr-request-cost, and x-nr-model headers.