Using Claude Code with Yi-AI Router

Connect Claude Code through Yi-AI Router without needing an Anthropic API key. All requests are automatically routed, with usage and billing managed centrally through your Yi-AI account.

Quick Start

Prerequisites

  • A Yi-AI account

Manual Setup (Recommended)

Add these environment variables to ~/.zshrc or ~/.bashrc:

export ANTHROPIC_AUTH_TOKEN="sk-yi-your-key"
export ANTHROPIC_BASE_URL="https://www.yiairouter.com/api"
export ANTHROPIC_API_KEY=""  # Must be explicitly empty to prevent conflicts

Save the file, restart your terminal, and run claude directly.

One-Command Install & Setup

If you encounter network issues, this method installs Claude Code and configures your API key in one step:

# macOS, Linux, WSL
curl -fsSL https://www.yiairouter.com/mirrors/install.sh | bash
# Windows PowerShell
irm https://www.yiairouter.com/mirrors/install.ps1 | iex

Terminal tip: If your prompt shows PS C:\ you're in PowerShell. If it shows C:\ without the PS, you're in CMD. For the best experience on Windows, install Git for Windows and use its Bash terminal to run the macOS/Linux command.

After completion, restart your terminal or run source ~/.zshrc, then launch with:

yi-claude

Add these environment variables to ~/.zshrc or ~/.bashrc:

export ANTHROPIC_AUTH_TOKEN="sk-yi-your-key"
export ANTHROPIC_BASE_URL="https://www.yiairouter.com/api"
export ANTHROPIC_API_KEY=""  # Must be explicitly empty to prevent conflicts

Save the file, restart your terminal, and run claude directly.

Verify Connection

Run /status inside Claude Code to confirm your connection:

> /status
Auth token: ANTHROPIC_AUTH_TOKEN
Anthropic base URL: https://www.yiairouter.com/api

You can also run /model to see the list of available models.

Clear Cached Login

If you previously logged in to Claude Code with an Anthropic account, clear the cached session:

> /logout

Then quit and re-launch claude. Otherwise, the cached OAuth session may conflict with your Yi-AI configuration and cause model availability errors.

How It Works

Yi-AI Router is compatible with the Anthropic Messages API. Claude Code communicates directly with Yi-AI Router using its native protocol β€” no local proxy required. The platform handles model mapping, usage accounting, and request routing.

Configuring Models

Claude Code uses several environment variables to determine which model to use for different tasks:

export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-7"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-20250514"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-20250514"
VariableDescription
ANTHROPIC_DEFAULT_OPUS_MODELModel for complex reasoning tasks
ANTHROPIC_DEFAULT_SONNET_MODELModel for general coding tasks
ANTHROPIC_DEFAULT_HAIKU_MODELModel for quick completions

Add these to the same shell profile where you set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN.

Pricing & Prompt Caching

Claude Code is a high-throughput agent that reads large local file contexts on every turn.

  • 90% cost reduction: Yi-AI Router's messages endpoint natively supports Anthropic's Prompt Caching. Repeated context automatically hits the cache β€” input costs drop to 10% of the standard rate.
  • Transparent billing: View your exact token usage and costs in the Yi-AI dashboard.

Troubleshooting

Terminal shows Cerebrating... with no streaming output?
Cause: ANTHROPIC_BASE_URL ends with /v1, causing the SDK to call /api/v1/v1/messages (404 lockup), or your proxy layer is buffering the stream.
Fix: Ensure ANTHROPIC_BASE_URL ends with /api β€” no /v1 suffix. If using a custom gateway, enable zero-buffering passthrough.

Getting There's an issue with the selected model?
Cause: 99% of the time the model exists β€” a stale Anthropic API key or OAuth session is causing an auth conflict.
Fix: Run export ANTHROPIC_API_KEY="" to clear any lingering key, then /logout inside Claude Code, quit, and re-launch with yi-claude.

Authentication errors
Ensure ANTHROPIC_API_KEY is set to an empty string (""). If unset (null), Claude Code may fall back to its default Anthropic authentication.

Context length exceeded
Break your task into smaller steps or start a new session.

YiAI Router

YiAI Router provides unified model access for Claude Code / Cursor development workflows. Developers are responsible for complying with local laws and for the content they generate.

Account

Language

Β© 2026 YiAI Infrastructure.Unified Access Layer for AI Coding Workflows