> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.fabricgateway.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.fabricgateway.ai/_mcp/server.

# Use Claude Code with Fabric AI Gateway

> Send Claude Code traffic through a Fabric AI Gateway route and confirm that requests arrive.

You can send Claude Code traffic through Fabric AI Gateway by pointing Claude Code at a gateway route and passing a gateway key as a custom header. The gateway then applies your plugins to Claude Code requests, and you can review them in the console. This topic shows you how to start Claude Code through the gateway and confirm that requests arrive.

## Prerequisites

Before you begin, make sure you have the following:

* Claude Code installed on your computer.
* A route that uses the Anthropic Messages API, such as `anthropic-route`, with these three endpoints exposed: `messages`, `count_tokens`, and `models`. Claude Code needs only these endpoints. For the steps, see [Connect an LLM provider](/fabric/gateways/llm-providers).
* A gateway key for the route, and the name of the request header that the route's Key Auth plugin reads.

## Configure Claude Code to use the gateway

Claude Code reads its settings from a `settings.json` file, which is the recommended way to point it at the gateway. To configure Claude Code, do the following:

1. Open your Claude Code user settings file, `~/.claude/settings.json`. To limit the change to one project, use `.claude/settings.json` in that project instead.

2. Add an `env` block with the gateway base URL and the gateway key header:

   ```json
   {
     "env": {
       "ANTHROPIC_BASE_URL": "https://GATEWAY_HOST/anthropic",
       "ANTHROPIC_CUSTOM_HEADERS": "fg-api-key: GATEWAY_KEY"
     }
   }
   ```

3. Replace `GATEWAY_HOST` with your data plane host and `GATEWAY_KEY` with your gateway key.

4. Restart Claude Code.

The settings do the following:

* `ANTHROPIC_BASE_URL` sends requests to the gateway route instead of the Anthropic API. Use the base URL only, not the individual endpoint paths.
* `ANTHROPIC_CUSTOM_HEADERS` adds the gateway key to each request. Use `fg-api-key` as the header name, unless the route's Key Auth instance still shows an older header under **Request header**. For more information, see [Authenticate requests with Key Auth](/fabric/plugins/key-auth).

> **Warning**
>
> Treat the gateway key as a secret. Don't commit a settings file that contains it. For a project-level file, use `.claude/settings.local.json`, which Claude Code doesn't share through version control.

To try the gateway for one session without editing a file, set the same two variables in your shell before you run `claude`.

## How Claude Code authenticates to Anthropic

The gateway supplies the Anthropic credential. It adds the API key saved on the connection when it forwards requests to Anthropic, so you only need to send the gateway key to Fabric.

## Confirm that requests pass through the gateway

To confirm that Claude Code uses the gateway, do the following:

1. In Claude Code, send a message, for example `Hello, is this working?`.
2. In the Fabric console, select **Admin**, and then select **Traces**.
3. Find the requests from your user on the route.

Open a trace to see the request body, which includes the system prompt and the tool definitions that Claude Code sends with each request. If you attached a routing plugin to the route, the trace also shows the extra calls that the plugin makes.

## Next steps

* Add a rate limit or a token counter to the route. For the steps, see [Control traffic with plugins](/fabric/plugins).
* Add fallback routing, so Claude Code keeps working when a provider returns errors. For the steps, see [Route requests across models and providers](/fabric/plugins/routing).
* Review token usage and estimated cost by model on the **LLM** tab of [Review analytics](/fabric/observability/analytics).