> 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 the Anthropic SDK with Fabric AI Gateway

> Point the Anthropic SDK at a Fabric AI Gateway route and send your gateway key in the fg-api-key header.

You can send Anthropic SDK traffic through Fabric AI Gateway by changing the client's base URL to a gateway route and adding your gateway key as a default header. Your code doesn't change otherwise. This topic shows you how to configure the Python and TypeScript SDKs and confirm that requests arrive.

## Prerequisites

Before you begin, make sure you have the following:

* The Anthropic SDK for Python (`anthropic`) or TypeScript (`@anthropic-ai/sdk`).
* A route that uses the Anthropic Messages API. For the steps, see [Connect an LLM provider](/configure/connections/llm-providers).
* A gateway key for the route. Send it in the `fg-api-key` header, which every route accepts, 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 and send a request](/use/authenticate).
* The base URL of the route. In the console, select **LLMs** > **Routes**, find the route, and then select **Copy LLM base URL**.

## Configure the client

Set the client's base URL to the route's base URL, without `/v1`. The SDK adds `/v1/messages` itself. Send the gateway key in the `fg-api-key` header, and keep it in an environment variable:

```bash
export FABRIC_GATEWAY_KEY="GATEWAY_KEY"
```

#### Python

```python
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="BASE_URL",
    api_key="unused",
    default_headers={"fg-api-key": os.environ["FABRIC_GATEWAY_KEY"]},
)

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello world!"}],
)
print(message.content[0].text)
```

#### TypeScript

```typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "BASE_URL",
  apiKey: "unused",
  defaultHeaders: { "fg-api-key": process.env.FABRIC_GATEWAY_KEY! },
});

const message = await client.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 256,
  messages: [{ role: "user", content: "Hello world!" }],
});
console.log(message.content);
```

Replace `BASE_URL` with the URL that you copied, and `GATEWAY_KEY` with your gateway key. Use a model that the connection allows.

The SDK requires an API key, but you don't need a real Anthropic key. When it forwards the request, the gateway adds the Anthropic key saved on the connection in place of the SDK's `x-api-key` header, so any placeholder value works. The SDK sends the `anthropic-version` header for you.

> **Warning**
>
> Treat the gateway key as a secret. Don't commit it to source control.

## Confirm that requests pass through the gateway

To confirm that the SDK uses the gateway, do the following:

1. Run your code. A successful request prints the model's reply.
2. In the Fabric console, select **Traces**. To see traces from every namespace, select **Admin**, and then select **Traces**.
3. Find the request on the route.

If the request returns `401 Unauthorized`, check that the `fg-api-key` header carries a key for this route. For more information, see [Troubleshoot authentication errors](/configure/authentication/key-auth#troubleshoot-authentication-errors).

## Next steps

* To learn which Messages API endpoints the route supports, see [Use the Anthropic Messages API](/use/llm/anthropic-messages).
* To use Claude Code through the same route, see [Use Claude Code with Fabric AI Gateway](/guides/coding-agents/claude-code).
* To fail over to another provider, see [Fail over across providers with the LLM Router](/configure/routing/failover).