nRouter SDKs
OpenAI-compatible SDKs for the nRouter LLM gateway. One key, one bill, the live multi-provider catalog, built-in guardrails, and prompt management. The exact current models are published at nrouter.ai/api/public/models.
SDKs
⚠️ Status corrected 2026-08-02. This table used to mark six branded SDKs "Ready" with copy-pasteable install commands. Only Python exists on disk (
sdks/contains exactly one directory) and only Python is published. Every other install line 404s. Verified against the registries on 2026-08-02:pypi.org/pypi/nroutersdk→ 200 (v0.1.0, uploaded 2026-03-31);registry.npmjs.org/@nrouter/sdk→ 404. Do not restore a "Ready" status without a registry check.
| Language | Package | Install | Status |
|---|---|---|---|
| Python | nroutersdk |
pip install nroutersdk |
Published — v0.1.0 on PyPI |
| cURL | None needed | Built-in | Available — see examples/curl.sh |
| Node.js | @nrouter/sdk (reserved name) |
— | NOT BUILT — no sdks/node/, not on npm |
| Go | github.com/nrouter/nrouter-go |
— | NOT BUILT — no repo, no sdks/go/ |
| Java | com.nrouter:sdk |
— | NOT BUILT — not on Maven Central |
| Ruby | nrouter |
— | NOT BUILT — no sdks/ruby/ |
| PHP | nrouter/sdk |
— | NOT BUILT — no sdks/php/ |
Until a branded SDK ships for your language, use the stock OpenAI SDK pointed at
https://api.nrouter.ai/v1 — that is the supported path and it is what every file under
examples/ demonstrates.
Architecture
Every SDK is a thin wrapper around the language's OpenAI SDK. The magic happens server-side.
spec/nrouter-sdk-spec.json ← Single source of truth
↓
sdks/
└── python/ ← pip install nroutersdk (the ONLY one that exists)
(planned, not built: node/ go/ java/ ruby/ php/ — see the status table above)
What Every SDK Does (Same Features, Every Language)
- Pre-configured —
base_urlandapi_key(fromNROUTER_API_KEY) set automatically - Auto-captures metadata —
last_responsepopulated from the gateway's canonicalx-nr-*cost, model, token, request, and limit headers - Typed errors —
GuardrailBlockedError,CreditError,RateLimitError(not generic 400/402/429) - Blocks unsupported endpoints —
audio,files,fine_tuning, etc. give clear errors, not confusing 404s - nRouter APIs —
credits.balance(),guardrails.list(),prompts.list(),nrouterModels.pricing() - Prompt template override —
nrouter_prompt_template_id+nrouter_prompt_variablesper request
Keeping SDKs in Sync
All SDKs are driven by spec/nrouter-sdk-spec.json:
{
"version": "2.0.0",
"response_headers": { "x-nr-request-cost": { "type": "float" }, ... },
"errors": { "guardrail_blocked": { "http": 400, "class": "GuardrailBlockedError" }, ... },
"unsupported_endpoints": { "audio": "...", "files": "...", ... },
"nrouter_apis": { "credits": { "balance": "/api/credits/balance" }, ... }
}
When the backend changes:
- Update
spec/nrouter-sdk-spec.json - Re-publish the Python SDK
(There is no CI that "regenerates + publishes all SDKs" — only the Python package exists, and its release is manual. Do not describe an automated multi-language pipeline that isn't wired.)
Quick Start
Only the Python snippet below is runnable today. The rest show the intended shape of branded SDKs that have not been built — do not paste them into a customer doc.
Python
from nroutersdk import nRouter
client = nRouter()
response = client.chat.completions.create(model="gpt-4o", messages=[{"role": "user", "content": "Hello!"}])
print(f"Cost: ${client.last_response.cost}")
Anthropic Messages (first provider-complete slice)
message = client.messages.create(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello!"}],
max_tokens=256,
)
print(message["content"][0]["text"])
print(f"Cost: ${client.last_response.cost}")
Buffered Messages calls are supported in both nRouter and AsyncnRouter. stream=True refuses
explicitly until the branded SDK has a tested SSE parser; use the official Anthropic-compatible
HTTP endpoint directly if you need streaming today.
Node.js
import { nRouter } from "@nrouter/sdk";
const client = new nRouter();
const res = await client.chat.completions.create({ model: "gpt-4o", messages: [{ role: "user", content: "Hello!" }] });
Go
client := nrouter.New()
resp, _ := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{...})
fmt.Println(client.LastResponse.Cost)
Ruby
client = nRouter::Client.new
response = client.chat(parameters: { model: "gpt-4o", messages: [{ role: "user", content: "Hello!" }] })
PHP
$client = new \nRouter\nRouter();
$response = $client->chat()->create([...]);
Java
nRouter nrouter = new nRouter();
ChatCompletion resp = nrouter.openai().chat().completions().create(...);
cURL
curl https://api.nrouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello!"}]}'
How We Keep SDKs Updated
Industry Standard (What OpenAI, Stripe, Anthropic Do)
| Company | Approach | Tool |
|---|---|---|
| OpenAI | OpenAPI spec → generated SDKs | Stainless |
| Anthropic | OpenAPI spec → generated SDKs | Stainless |
| Stripe | OpenAPI spec → generated SDKs | Custom generator |
| AWS | Smithy model → generated SDKs | Smithy |
| Google Cloud | Protobuf → generated SDKs | gapic-generator |
| Twilio | OpenAPI spec → generated SDKs | Custom generator |
The pattern is universal: one spec file → code generation → publish.
Our Approach
┌─────────────────────────────────────────┐
│ spec/nrouter-sdk-spec.json │ ← YOU EDIT THIS
│ (headers, errors, APIs, version) │
└──────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ scripts/generate-sdks.py │ ← READS SPEC
│ (validates + generates SDK code) │
│ │
│ For each language: │
│ 1. Read spec │
│ 2. Generate response meta class │
│ 3. Generate error classes │
│ 4. Generate unsupported blockers │
│ 5. Generate nRouter API helpers │
│ 6. Write to sdks/{lang}/ │
└──────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ CI Pipeline (GitHub Actions) │
│ │
│ On spec change: │
│ 1. Regenerate all SDKs │
│ 2. Run tests per language │
│ 3. Version bump (from spec.version) │
│ 4. Publish: │
│ PyPI, npm, Maven, RubyGems, │
│ Packagist, Go module tag │
└─────────────────────────────────────────┘
What Triggers an Update
| Backend Change | Spec Update | SDK Impact |
|---|---|---|
| New response header | Add to response_headers |
All SDKs parse new header |
| New error code | Add to errors |
All SDKs get new error class |
| New nRouter API endpoint | Add to nrouter_apis |
All SDKs get new method |
| New unsupported block | Add to unsupported_endpoints |
All SDKs block it |
| Version bump | Change version |
All packages publish same version |
| OpenAI adds new method | Nothing — inherited automatically | SDKs get it for free |
What DOESN'T Need an Update
| Change | Why No SDK Update |
|---|---|
| New model added | Just use model="new-model-name" — no SDK change |
| Guardrail config change | Dashboard config, not SDK |
| Prompt template change | Dashboard config, not SDK |
| Pricing change | Server-side, returned via nrouterModels.pricing() |
| Rate limit change | Server-side enforcement |
| New provider key | Server-side routing |
This is the key advantage of the thin-wrapper approach: 90% of product changes need zero SDK updates.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nrouter_sdk-2.0.0.tar.gz.
File metadata
- Download URL: nrouter_sdk-2.0.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71cbfa7526e5a89d698aea34e2c24d8374d169c69fdd92da9d4ed79aa516dfcf
|
|
| MD5 |
c7f1263eebe39c996dc6295521130303
|
|
| BLAKE2b-256 |
86bfa481171bf44271452bb4c9d580a28511d21bc65499a877749f53f49e9edc
|
File details
Details for the file nrouter_sdk-2.0.0-py3-none-any.whl.
File metadata
- Download URL: nrouter_sdk-2.0.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a005e5e4e93a0530bb83036e2f5fc484f41e0e27c87c09e852a71e083ec0022b
|
|
| MD5 |
b334608295bcd24e9c71cf1c62f1dca4
|
|
| BLAKE2b-256 |
5cbdc36cd9db1c4607746b000b3b0ced45cb4c40e60c93d3990c2286ee91dfeb
|