> 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](/configure/connections/llm-providers).
* A gateway key for the route. For the steps, see [Create a gateway key](/configure/connections/llm-providers#create-a-gateway-key). For how callers send it, see [Authenticate and send a request](/use/authenticate).

## 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": "BASE_URL",
       "ANTHROPIC_CUSTOM_HEADERS": "fg-api-key: GATEWAY_KEY"
     }
   }
   ```

3. Replace `BASE_URL` with the route's base URL and `GATEWAY_KEY` with your gateway key. To get the base URL, select **LLMs** > **Routes**, find the route, and then select **Copy LLM base URL**.

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. Every route accepts it, unless its Key Auth instance is an older one that sets a `headers` list. In that case, send the key in one of the listed headers, and ask your admin which. For more information, see [Authenticate requests with Key Auth](/configure/authentication/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 **Traces**. To see traces from every namespace, 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 to the route. For the steps, see [Control traffic with plugins](/configure/plugins).
* Add fallback routing, so Claude Code keeps working when a provider returns errors. For the steps, see [Fail over across providers with the LLM Router](/configure/routing/failover).
* Review token usage and estimated cost by model on the **LLM** tab of [Review analytics](/use/monitor/analytics).