Skip to main content

Use AnyAPI in Claude Code

Claude Code is Anthropic’s official terminal-native AI coding agent. It lets you delegate complex coding tasks — file edits, multi-step refactors, test generation, and more — directly from your terminal.
AnyAPI works with Claude Code via the Anthropic Messages API (/v1/messages). No local proxy required.

Quick Start

1. Get your API key

Sign up at anyapi.ai and create an API key in the dashboard.

2. Install Claude Code

macOS / Linux / WSL:
curl -fsSL https://claude.ai/install.sh | bash
Windows PowerShell:
irm https://claude.ai/install.ps1 | iex

3. Configure environment variables

Add these lines to your shell profile (~/.zshrc or ~/.bashrc):
export ANTHROPIC_BASE_URL="https://api.anyapi.ai"
export ANTHROPIC_AUTH_TOKEN="your-anyapi-key-here"
export ANTHROPIC_API_KEY=""   # Must be explicitly empty
export ANTHROPIC_MODEL="anthropic/claude-sonnet-4.6"
Then reload your shell:
source ~/.zshrc  # or source ~/.bashrc
Important: ANTHROPIC_API_KEY must be set to an empty string "", not just unset. If it has any value, Claude Code will try to authenticate with Anthropic directly instead of using AnyAPI.
Note: Do not put these in a project-level .env file — Claude Code does not read standard .env files.

4. Clear any cached Anthropic login

If you previously logged in to Claude Code with an Anthropic account, run this inside Claude Code:
/logout
Then quit and relaunch claude.

5. Start Claude Code

cd /path/to/your/project
claude

6. Verify

Run /status inside Claude Code:
/status
Auth token: ANTHROPIC_AUTH_TOKEN
Anthropic base URL: https://api.anyapi.ai

Model Format

AnyAPI uses the vendor/model format. Always include the vendor prefix:
export ANTHROPIC_MODEL="anthropic/claude-sonnet-4.6"   # correct
# export ANTHROPIC_MODEL="claude-sonnet-4.6"           # may not resolve
Browse available models at anyapi.ai/ai-models or query the API:
curl -sS -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  https://api.anyapi.ai/v1/models | jq -r '.data[].id'

Configuration Examples

DeepSeek:
export ANTHROPIC_BASE_URL="https://api.anyapi.ai"
export ANTHROPIC_AUTH_TOKEN="your-key"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_MODEL="deepseek/deepseek-v4-flash"
Kimi K2:
export ANTHROPIC_BASE_URL="https://api.anyapi.ai"
export ANTHROPIC_AUTH_TOKEN="your-key"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_MODEL="moonshotai/kimi-k2.6"
Claude Sonnet (via Anthropic on AnyAPI):
export ANTHROPIC_BASE_URL="https://api.anyapi.ai"
export ANTHROPIC_AUTH_TOKEN="your-key"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_MODEL="anthropic/claude-sonnet-4.6"

Troubleshooting

403 RBAC: access denied

Your key doesn’t have access to the requested model, or the model name is wrong.
  1. Check your balance and plan at dash.anyapi.ai
  2. Verify the model name using the /v1/models endpoint above
  3. Make sure you’re using vendor/model format

Please run /login on startup

Claude Code is ignoring your environment variables.
  1. Make sure ANTHROPIC_API_KEY="" is explicitly set to empty string
  2. Run /logout inside Claude Code, then restart
  3. Confirm variables are in your shell profile, not a .env file

Auth conflict warnings / unexpected model-not-found errors

Usually caused by a cached Anthropic OAuth session conflicting with ANTHROPIC_AUTH_TOKEN.
  1. Run /logout inside Claude Code
  2. Quit and relaunch claude
  3. Verify with /status that the base URL shows https://api.anyapi.ai

Browser opens for login unexpectedly

ANTHROPIC_API_KEY is either unset or has a real value. Set it to an empty string:
export ANTHROPIC_API_KEY=""

Support

Next Steps

All Integrations

Browse all supported tools

Model Catalog

Browse 300+ available models