Use the Anthropic SDK with Fabric AI Gateway
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.
- A gateway key for the route. Send it in the
fg-api-keyheader, which every route accepts, unless its Key Auth instance is an older one that sets aheaderslist. 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. - 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:
Python
TypeScript
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.
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:
- Run your code. A successful request prints the model’s reply.
- In the Fabric console, select Traces. To see traces from every namespace, select Admin, and then select Traces.
- 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.
Next steps
- To learn which Messages API endpoints the route supports, see Use the Anthropic Messages API.
- To use Claude Code through the same route, see Use Claude Code with Fabric AI Gateway.
- To fail over to another provider, see Fail over across providers with the LLM Router.

