Browse documentation

Quick Start

Make your first LLM API call through nRouter in under two minutes using Python, TypeScript, or cURL with clear instructions and verified code examples.

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 (the minimum credit purchase is $5, with the platform fee on top)

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="gpt-5.4-mini",
        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"\n[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: "gpt-5.4-mini",
    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(`\n[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": "gpt-5.4-mini",
    "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": "gpt-5.4-mini",
  "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:

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

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

# Anthropic Claude (Native Messages API)
response = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    messages=[{"role": "user", "content": "Hello Claude!"}],
    max_tokens=256,
)

Next Steps

Was this page helpful?