Official Python client for the Nadir LLM router. Provides typed access to routing metadata, model recommendations, and all Nadir features beyond what the OpenAI SDK offers.
Installation
pip
pip install nadir-sdk
Quick Start
Python
from nadir import NadirClient
client = NadirClient(api_key="ndr_...")
# Chat completion — Nadir picks the optimal model
response = client.chat.completions.create(
messages=[{"role": "user", "content": "What is 2+2?"}],
)
print(response.choices[0].message.content)
# See which model was selected and why
print(response.nadir_metadata.tier) # "simple"
print(response.nadir_metadata.selected_model) # "gpt-4o-mini"
print(response.nadir_metadata.complexity_score) # 0.12Streaming
Streaming
stream = client.chat.completions.create(
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)Model Recommendation (no LLM call)
Get a routing recommendation without making an LLM call. Useful for previewing which model Nadir would select.
Recommend
rec = client.recommend("Explain quantum entanglement in detail")
print(rec) # {"recommended_model": "claude-sonnet-4-20250514", "complexity": ...}Async
Async
import asyncio
from nadir import AsyncNadirClient
async def main():
async with AsyncNadirClient(api_key="ndr_...") as client:
response = await client.chat.completions.create(
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
asyncio.run(main())Fallback & Routing Control
Advanced
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Complex analysis..."}],
route="fallback", # enable auto-fallback
fallback_models=["claude-sonnet-4-20250514", "gpt-4o"], # explicit fallback chain
layers={"routing": True, "optimize": True}, # per-request feature toggles
reasoning={"effort": "high"}, # reasoning token support
)Environment Variables
| Variable | Description | Default |
|---|---|---|
NADIR_API_KEY | API key (fallback if not passed to constructor) | - |
NADIR_BASE_URL | API base URL | https://api.getnadir.com |
OpenAI Drop-in Compatibility
Nadir's API is OpenAI-compatible. You can also use the OpenAI SDK directly. The Nadir SDK adds typed routing metadata, recommendations, and clustering that the OpenAI SDK can't reach.
OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://api.getnadir.com/v1",
api_key="ndr_...",
)
response = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Hello"}],
)Info
Source code and issues: github.com/NadirRouter/nadir-python