Browse documentation

Quick Start

Make your first API call in under 2 minutes with Python, TypeScript, or cURL

Last updated

Make your first nRouter API call in under 2 minutes. Use the official branded SDKs (nrouter-sdk, @nrouter_ai/sdk) or any standard OpenAI / Anthropic client library.

Prerequisites

  1. A nRouter account — sign up here
  2. An API key from your dashboard's API Keys page
  3. Credits in your account (load your first $5 and receive a $10 bonus, giving you $15 to start)

Export your virtual API key in your terminal:

export NROUTER_API_KEY="sk-nrouter-your-key-here"

1. Python (Official SDK)

Install the official Python SDK from PyPI:

pip install nrouter-sdk

Run your first chat completion with automatic USD cost extraction:

from nroutersdk import nRouter

# Automatically resolves NROUTER_API_KEY from your environment
with nRouter() as client:
    response = client.chat.completions.create(
        model="claude-sonnet-4-5-20250929",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What makes an LLM router valuable?"},
        ],
        max_completion_tokens=256,
    )

    print(response.choices[0].message.content)

    # Built-in response metadata
    if client.last_response:
        print(f"
[Cost: ${client.last_response.cost} | Request ID: {client.last_response.request_id}]")

2. TypeScript / Node.js (Official SDK)

Install the official TypeScript/JavaScript SDK:

npm install @nrouter_ai/sdk

Execute a completion with automatic token and metadata management:

import { nRouter } from "@nrouter_ai/sdk";

const client = new nRouter();

async function main() {
  const response = await client.chat.completions.create({
    model: "claude-sonnet-4-5-20250929",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "What makes an LLM router valuable?" },
    ],
    max_completion_tokens: 256,
  });

  console.log(response.choices[0].message.content);

  if (client.lastResponse) {
    console.log(`
[Cost: $${client.lastResponse.cost} | Request ID: ${client.lastResponse.requestId}]`);
  }
}

main();

3. cURL

Test nRouter directly from your command line:

curl https://api.nrouter.ai/v1/chat/completions   -H "Authorization: Bearer $NROUTER_API_KEY"   -H "Content-Type: application/json"   -d '{
    "model": "claude-sonnet-4-5-20250929",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "What is nRouter?"
      }
    ],
    "max_completion_tokens": 256
  }'

Every response returns an OpenAI-compatible JSON payload alongside public x-nr-* tracking headers:

{
  "id": "chatcmpl-90ab12cd",
  "object": "chat.completion",
  "created": 1756636800,
  "model": "claude-sonnet-4-5-20250929",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "nRouter is an enterprise unified LLM router and security gateway..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 42,
    "total_tokens": 66
  }
}

Switch Models Instantly

Switch upstream providers without installing new SDKs or managing multiple vendor credentials:

# Anthropic Claude
response = client.chat.completions.create(model="claude-sonnet-4-5-20250929", messages=messages)

# OpenAI GPT-5
response = client.chat.completions.create(model="gpt-5.4-mini", messages=messages)

# Google Gemini
response = client.chat.completions.create(model="gemini-2.5-flash", messages=messages)

Next Steps

Was this page helpful?