---
title: "Claude Code (gateway)"
description: "Set up Claude Code, in the terminal or the Claude desktop app, with the Respan gateway."
---

Route Claude Code's LLM calls through the Respan gateway for automatic logging, caching, and model switching. Only your `RESPAN_API_KEY` is needed.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Claude Code integration.
Follow https://www.respan.ai/docs/integrations/gateway/claude-code.md
```

## Setup

<Tabs>
<Tab title={"Desktop app"}>

The Claude desktop app does not read `ANTHROPIC_BASE_URL`, `ANTHROPIC_API_KEY`, or `~/.claude/settings.json` to pick its API endpoint. It takes the gateway from its own third-party inference settings, which apply to the whole app (Chat, Cowork, and Code), not only to the Code tab.

<Steps>
<Step title="Turn on Developer Mode">

In the macOS menu bar at the top of the screen (not inside the app window), choose **Help → Troubleshooting → Enable Developer Mode…** and confirm with **Enable**. On Windows, open the ☰ menu at the top left of the app. The app restarts with a new **Developer** menu in the menu bar.

<img src={"/docs/images/integrations/claude-desktop/enable-developer-mode.png"} alt="Enable Developer Mode in the Help, Troubleshooting menu of the Claude desktop app" />

If your organization manages the app, these menu items can be hidden.

</Step>

<Step title="Point the app at the Respan gateway">

Choose **Developer → Configure Third-Party Inference…**.

<img src={"/docs/images/integrations/claude-desktop/developer-menu.png"} alt="Configure Third-Party Inference in the Developer menu of the Claude desktop app" />

In **Connection**:

1. In the dropdown at the top, choose **Gateway**.
2. Under **Gateway base URL**, enter the full URL, `https://gateway.respan.ai`.
3. Under **Gateway API key**, paste `YOUR_RESPAN_API_KEY`.

Leave **Credential kind** and **Gateway auth scheme** at their defaults (**Static API key** and **bearer**). **Test connection** checks the URL and key.

<img src={"/docs/images/integrations/claude-desktop/gateway-connection.png"} alt="Connection form with Gateway selected, the Respan gateway URL, and an API key" />

</Step>

<Step title="Add the models you want">

Further down in **Connection**, under **Model list**, click **Add model** and enter a **Model ID** for each model you want in the model picker, for example `claude-sonnet-5.5` or `claude-haiku-5.5`. The first one is the default.

<img src={"/docs/images/integrations/claude-desktop/model-entry.png"} alt="Model entry with the model ID claude-sonnet-5.5 in the Claude desktop app" />

The app cannot read the model list from the gateway, so the picker stays empty until you add at least one model.

</Step>

<Step title="Apply and restart">

Click **Apply Changes** and let the app restart. It relaunches on the gateway. If it shows the sign-in screen, choose the option that uses your gateway configuration. Sessions in the Code tab now route through Respan.

</Step>
</Steps>

<Note>
While the gateway is active, the app has no Anthropic cloud environments and no Remote Control. To go back to your Claude account, choose the Anthropic sign-in option on the app's sign-in screen.
</Note>

</Tab>
<Tab title={"CLI"}>

These steps are for the `claude` CLI. The Claude desktop app ignores these variables.

<Steps>
<Step title="Install Claude Code">

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

</Step>

<Step title="Set environment variables">

Add to your shell profile (`.bashrc`, `.zshrc`, or PowerShell `$PROFILE`):

```bash
unset ANTHROPIC_AUTH_TOKEN
export ANTHROPIC_BASE_URL="https://gateway.respan.ai"
export ANTHROPIC_API_KEY="YOUR_RESPAN_API_KEY"
```

Use `ANTHROPIC_API_KEY`, not `ANTHROPIC_AUTH_TOKEN`, for Claude Code through the Respan Anthropic gateway. Claude prefers `ANTHROPIC_AUTH_TOKEN` when both are set.

</Step>

<Step title="Or use Claude Code settings (persistent)">

Add to `~/.claude/settings.json` for global config, or `.claude/settings.local.json` in your project for repo-local config:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://gateway.respan.ai",
    "ANTHROPIC_API_KEY": "YOUR_RESPAN_API_KEY",
    "ANTHROPIC_AUTH_TOKEN": ""
  }
}
```

Setting `ANTHROPIC_AUTH_TOKEN` to an empty string clears any inherited token so Claude Code prefers `ANTHROPIC_API_KEY`. Run Claude Code as usual. All LLM calls will route through Respan.

</Step>
</Steps>

<Note>
The Anthropic gateway path is `/api/anthropic/` (with trailing slash). For interactive Claude Code sessions, prefer shell env vars or `~/.claude/settings.json`. If `ANTHROPIC_AUTH_TOKEN` is exported by your shell or terminal app, Claude may still prefer it, so unset or remove it first. On first interactive launch, Claude may prompt: **Detected a custom API key in your environment**. Choose **Yes** to use the Respan API key. If you skipped it earlier, run `/config`, search for `custom`, and enable **Use custom API key**. Non-interactive `claude -p` and `claude --print` use `ANTHROPIC_API_KEY` automatically.
</Note>

</Tab>
</Tabs>

## Switch models

Once routed through the gateway, you can use any Claude model.

```bash
# In your shell
claude --model claude-sonnet-4-5-20250929
claude --model claude-haiku-4-5-20251001
```

See the [full model list](https://platform.respan.ai/platform/models).

## Pin requests to a specific provider

To run Claude Code on one provider, such as your Vertex AI throughput, put the provider's prefix in front of the model ID:

```bash
claude --model vertex_ai/claude-sonnet-4-5
```

For a fallback across providers (e.g. primary Vertex, fall back to Anthropic on failure), use a [fallback](/docs/ai-gateway/routing/fallbacks) instead.
