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

# Claude Code Environment Variables

> Set the ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN and ANTHROPIC_MODEL environment variables in settings.json or your shell to route Claude Code through Requesty and use 300+ models.

Claude Code is Anthropic's powerful AI coding assistant that works directly in your terminal and IDE. You connect it to Requesty with two environment variables, `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN`, set either in `~/.claude/settings.json` or in your shell.

Using the Requesty integration, you can:

* Use 300+ models while coding, giving you flexibility to choose the best model for each task.
* Track and manage your spend in a single location
* Keep a record of your conversations

# Configuration

## 1. (Recommended) Set ANTHROPIC\_BASE\_URL and ANTHROPIC\_AUTH\_TOKEN in settings.json

You can configure Claude Code using the settings file. You will only have to edit it once.

Create or edit your settings file: `~/.claude/settings.json`

And set the `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` values inside the `env` block:

```json theme={"dark"}
{
	"env": {
		"ANTHROPIC_BASE_URL": "https://router.requesty.ai",
		"ANTHROPIC_AUTH_TOKEN": "your_requesty_api_key",
		"ANTHROPIC_MODEL": "anthropic/claude-fable-5"
	}
}
```

## 2. Quick setup using environment variables

You can also integrate Requesty with Claude Code by exporting the `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` environment variables in your shell:

1. **Get Your API Key**
   Create an API key on the [API Keys Page](https://app.requesty.ai/api-keys).

2. **Set Environment Variables**

   ```bash theme={"dark"}
   export ANTHROPIC_BASE_URL="https://router.requesty.ai"
   export ANTHROPIC_AUTH_TOKEN="your_requesty_api_key"
   export ANTHROPIC_MODEL="anthropic/claude-fable-5"
   ```

<Info>
  We recommend using the `ANTHROPIC_MODEL` environment variable, and not the `/model` directive as Claude might not accept it sometimes.
</Info>

3. **(Optional) Enable Analytics**

   Additionally, you can track cost per branch, repo, and developer by installing the Requesty analytics wrapper:

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

   Then restart your terminal or run `source ~/.zshrc` (or `~/.bashrc`). Every Claude Code session will now automatically tag requests with your git branch, repo, and username, visible in your [Requesty dashboard](https://app.requesty.ai/analytics).

4. **Run Claude**
   Run `claude` in your terminal.

<Info>
  With this setup, Claude Code will route all requests through Requesty, giving you access to models from OpenAI, Anthropic, Google,
  Mistral, and many more providers.
</Info>

### Model Selection

You can choose any model from the [Model Library](https://app.requesty.ai/model-list) or any policy configured for your organization.

**Standard model IDs** follow the format `provider/model-name`:

* `anthropic/claude-fable-5`
* `openai/gpt-4o`
* `google/gemini-2.0-flash-exp`
* `mistral/mistral-large-2411`

**Policies** follow the format `policy/policy-name`:

* `policy/reliable-sonnet-4-5`

### Command Line Configuration

You can also configure Claude Code using the command line:

```bash theme={"dark"}
# Set the model globally
claude config set -g model "anthropic/claude-fable-5"

# Set the model for current project only
claude config set model "openai/gpt-4o"

# Set environment variables globally
claude config set -g env.ANTHROPIC_BASE_URL "https://router.requesty.ai"
claude config set -g env.ANTHROPIC_AUTH_TOKEN "your_requesty_api_key"
```

### Claude Code environment variables reference

These are the environment variables Claude Code reads when routing through Requesty. Set them in the `env` block of `~/.claude/settings.json` or export them in your shell.

| Variable                     | Value                             | Purpose                                                                |
| ---------------------------- | --------------------------------- | ---------------------------------------------------------------------- |
| `ANTHROPIC_BASE_URL`         | `https://router.requesty.ai`      | Points Claude Code at the Requesty gateway instead of Anthropic's API  |
| `ANTHROPIC_AUTH_TOKEN`       | Your Requesty API key             | Authenticates with Requesty, used as a Bearer token                    |
| `ANTHROPIC_MODEL`            | e.g. `anthropic/claude-fable-5`   | Default model, any model ID or `policy/` name from your organization   |
| `ANTHROPIC_SMALL_FAST_MODEL` | e.g. `anthropic/claude-haiku-4-5` | Model used for background and lightweight tasks                        |
| `ANTHROPIC_CUSTOM_HEADERS`   | `X-Requesty-...: value`           | Optional analytics headers, set automatically by the analytics wrapper |

<Info>
  For EU data residency, set `ANTHROPIC_BASE_URL` to `https://router.eu.requesty.ai` instead. See [EU Routing](/features/eu-routing).
</Info>

## Claude Code Analytics

Track exactly how much each branch, repo, and developer costs in Claude Code. One command installs a lightweight shell wrapper that tags every Claude Code session with metadata, visible in your Requesty dashboards.

### What you get

* **Cost per branch**, see which feature branch is burning the most credits
* **Cost per repo**, break down spend across multiple repositories
* **Cost per developer**, know who's spending what
* **Agent version tracking**, see which Claude Code version is generating spend

### Install

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

Then restart your terminal or run `source ~/.zshrc` (or `~/.bashrc`).

That's it. Every Claude Code session will now automatically send these headers to Requesty:

| Header                | Value                      |
| --------------------- | -------------------------- |
| `X-Requesty-Branch`   | Current git branch         |
| `X-Requesty-Repo`     | `org/repo` from git origin |
| `X-Requesty-Ai-Agent` | Claude Code version        |
| `X-Requesty-User`     | OS username                |

<Info>
  Headers are set once at session launch and sent only to Requesty, they are stripped before forwarding to any AI provider. No data leaves Requesty's gateway.
</Info>

### How it works

The installer appends a small shell function to your `~/.zshrc` or `~/.bashrc` that wraps the `claude` command. Each time you start Claude Code, it reads your git context and sets `ANTHROPIC_CUSTOM_HEADERS` before launching. The wrapper is \~10 lines and fully visible in your rc file.

### Uninstall

Remove the block between `# --- Requesty header injection ---` markers in your shell rc file, or just delete the `claude()` function.

### Custom headers

You can add your own `X-Requesty-*` headers for additional dimensions. See [Request Metadata](/features/request-metadata) for more.

## Benefits of Using Requesty with Claude Code

<CardGroup cols={2}>
  <Card title="Access 300+ Models" icon="brain">
    Switch between models from different providers without changing your setup
  </Card>

  <Card title="Cost Management" icon="chart-line">
    Monitor spending and set limits across all your AI interactions
  </Card>

  <Card title="Fallback Policies" icon="shield-check">
    Automatic fallbacks ensure your coding sessions never get interrupted
  </Card>
</CardGroup>

## Troubleshooting

### Model Not Found

If you get a "model not found" error, make sure:

* Your API key is valid and has access to the model (check the approved models in your organization)
* The model ID format is correct (`provider/model-name`)
* The model is available in the [Model Library](https://app.requesty.ai/model-list)

### Connection Issues

If Claude Code can't connect:

* Verify your `ANTHROPIC_BASE_URL` is set to `https://router.requesty.ai`
* Check your `ANTHROPIC_AUTH_TOKEN` is correct
* Ensure you have internet connectivity
