> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code Integration

> Use AnyAPI models in Anthropic's official terminal-native AI coding agent, Claude Code.

# Use AnyAPI in Claude Code

[Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) 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](https://anyapi.ai) and create an API key in the [dashboard](https://dash.anyapi.ai/?page=api-keys).

### 2. Install Claude Code

**macOS / Linux / WSL:**

```bash theme={"system"}
curl -fsSL https://claude.ai/install.sh | bash
```

**Windows PowerShell:**

```powershell theme={"system"}
irm https://claude.ai/install.ps1 | iex
```

### 3. Configure environment variables

Add these lines to your shell profile (`~/.zshrc` or `~/.bashrc`):

```bash theme={"system"}
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:

```bash theme={"system"}
source ~/.zshrc  # or source ~/.bashrc
```

<Note>
  **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>

<Info>
  **Note:** Do not put these in a project-level `.env` file — Claude Code does not read standard `.env` files.
</Info>

### 4. Clear any cached Anthropic login

If you previously logged in to Claude Code with an Anthropic account, run this inside Claude Code:

```bash theme={"system"}
/logout
```

Then quit and relaunch `claude`.

### 5. Start Claude Code

```bash theme={"system"}
cd /path/to/your/project
claude
```

### 6. Verify

Run `/status` inside Claude Code:

```bash theme={"system"}
/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:

```bash theme={"system"}
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](https://anyapi.ai/ai-models) or query the API:

```bash theme={"system"}
curl -sS -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  https://api.anyapi.ai/v1/models | jq -r '.data[].id'
```

***

## Configuration Examples

**DeepSeek:**

```bash theme={"system"}
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:**

```bash theme={"system"}
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):**

```bash theme={"system"}
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](https://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:

```bash theme={"system"}
export ANTHROPIC_API_KEY=""
```

***

## Support

* **AnyAPI Dashboard**: [dash.anyapi.ai](https://dash.anyapi.ai)
* **AnyAPI Discord**: [Discord community](https://discord.gg/rJgyzGynHw)
* **AnyAPI Email**: [support@anyapi.ai](mailto:support@anyapi.ai)
* **Claude Code Docs**: [docs.anthropic.com/en/docs/claude-code](https://docs.anthropic.com/en/docs/claude-code/overview)

## Next Steps

<CardGroup cols={2}>
  <Card title="All Integrations" icon="plug" href="/integrations/overview">
    Browse all supported tools
  </Card>

  <Card title="Model Catalog" icon="list" href="https://anyapi.ai/ai-models">
    Browse 300+ available models
  </Card>
</CardGroup>
