Browse documentation

Claude Code with nRouter

Route supported Claude Code traffic through nRouter with governed OpenAI or Anthropic endpoints, keeping budgets and guardrails in the request path.

Route Anthropic Claude Code agent traffic through nRouter (https://api.nrouter.ai) to centralize provider credentials, enforce hard spend caps, and log exact execution costs. Keep budgets and guardrails in the request path without changing your project code, prompt templates, or local tool configurations.

Key capabilities:

  • Credential isolation: Issue sk-nrouter-... virtual keys rather than distributing raw provider keys to developer environments.
  • Spend protection: Hard USD budget ceilings prevent autonomous loops from exhausting balances.
  • Dual API compatibility: Supports both OpenAI-compatible and Anthropic Messages API surfaces.
  • Audit trail: Every agent turn logs the exact serving model, latency, and list-price cost.

Quickstart

  1. Mint a virtual key with a spend limit in the dashboard.
  2. Confirm your target model in the model catalog.
  3. Check Anthropic's Claude Code gateway documentation for supported variables.

Export the gateway endpoint and credential:

export ANTHROPIC_API_KEY="sk-nrouter-xxxxxxxxxxxx"
export ANTHROPIC_BASE_URL="https://api.nrouter.ai"

Run a short prompt, verify the trace in nRouter observability, and test tool calls and streaming before rollout.

What changes

nRouter centralizes credentials, routing policies, and budget controls at the gateway layer. Your project files, prompts, and tool configurations remain untouched. Removing the environment variables immediately restores direct provider routing.

Production checklist

  1. Set a per-key limit via budget controls before running autonomous workflows.
  2. Review guardrails and cost headers in observability.
  3. For other developer tools, see Cursor with nRouter and OpenClaw with nRouter.

Troubleshooting

If requests succeed locally but do not appear in observability, Claude Code is bypassing the gateway; verify that environment variables are exported in the active shell. If requests fail at the gateway (see Errors & Rate Limits):

  • 401 invalid_api_key: Key is missing or invalid.
  • 402 insufficient_credits: Virtual key budget cap reached.
  • 404 model_not_found: Model ID does not match the active model catalog.

Frequently asked questions

Do I need to change my projects or prompts?

No. The gateway only changes the endpoint URL and virtual key in the client environment; local projects, prompts, and tool setups remain untouched.

Which API surface does Claude Code use through nRouter?

nRouter exposes both OpenAI-compatible and Anthropic Messages surfaces (https://api.nrouter.ai). Configure the endpoint matching your installed Claude Code version.

How do I control what autonomous runs spend?

Set a hard USD limit on the virtual key via budget controls. Requests return HTTP 402 when the ceiling is reached.

How do I verify the gateway setup works?

Run a prompt with a test key and verify the entry in nRouter observability. Test streaming and tool calls before full team rollout.

Was this page helpful?