LogoToRouter Docs
LogoToRouter Docs
HomepageWhat is ToRouter5-minute quickstartCore concepts
OpenAI Python SDKOpenAI Node / TypeScript SDKAnthropic SDK (Python & TypeScript)Google Gen AI SDK (Gemini)CursorCline (VS Code extension)Claude Code CLILangChain & LlamaIndexDify & n8n (no-code)
Integrations

Claude Code CLI

Run Anthropic's official Claude Code CLI against ToRouter — full agentic coding without an Anthropic-only key.

Claude Code is Anthropic's official terminal agent. It speaks the native Anthropic Messages API, which ToRouter exposes 1:1 — so the CLI works against ToRouter unchanged once you set two environment variables.

Configuration

VariableValue
ANTHROPIC_BASE_URLhttps://portal.torouter.ai
ANTHROPIC_API_KEYsk-***

The model is selected per-session via the CLI flag --model or the /model slash command; default is the current flagship Claude.

Install & run

npm install -g @anthropic-ai/claude-code

export ANTHROPIC_BASE_URL=https://portal.torouter.ai
export ANTHROPIC_API_KEY=sk-***

claude
npm install -g @anthropic-ai/claude-code

$env:ANTHROPIC_BASE_URL = "https://portal.torouter.ai"
$env:ANTHROPIC_API_KEY  = "sk-***"

claude

Inside the CLI:

> /model claude-opus-4-7
> Refactor src/server.go for readability

Prompt caching is on by default

Claude Code aggressively uses cache_control on system prompts and recent turns. ToRouter forwards cache_control unchanged for both direct Anthropic and Anthropic-on-OpenRouter routing, so your effective cost on long sessions matches Anthropic's published cached pricing.

Gotchas

  • Use https://portal.torouter.ai for ANTHROPIC_BASE_URL — no /v1 suffix. Claude Code appends /v1/messages itself.
  • claude /login is the OAuth login flow for Anthropic-direct billing; when using ToRouter you skip it entirely — the env vars are sufficient.
  • Persist the env vars in your shell profile (~/.zshrc, ~/.bashrc) or use a .env loader so new terminal sessions pick them up.
  • Tool-use heavy sessions can hit per-key rate limits; tune them in the ToRouter console under Keys → Rate limits.

Next steps

Create an API key

Base URL & auth reference

Model catalog

Troubleshoot errors

Cline (VS Code extension)

Configure the Cline VS Code agent to use Claude, GPT and other models through ToRouter.

LangChain & LlamaIndex

Use LangChain's ChatOpenAI and LlamaIndex's OpenAI wrapper against ToRouter to mix Claude, GPT and Gemini in one chain.

Table of Contents

ConfigurationInstall & runNext steps