Configure Claude Code with the AI Gateway
This guide explains how to configure Claude Code to send requests through Choreo AI Gateway using an AI Gateway and an Anthropic LLM Service Provider.
By routing requests through the AI Gateway instead of invoking Anthropic directly, you can apply security, traffic control, and governance policies such as guardrails and rate limiting. The AI Gateway acts as an intermediary, forwarding requests from Claude Code to Anthropic while enforcing these controls.
Prerequisites
Before you begin, make sure you have:
- An Anthropic API key
- An Agent Control Plane account. Sign up for free.
- Docker and Docker Compose, to run the self-hosted gateway
- Claude Code installed
Step 1: Start an AI Gateway in Agent Control Plane
If an AI Gateway is already created and active, continue to Step 2.
This step follows the same flow as the Quick Start Guide for self-hosted gateways.
If an AI Gateway is not already created, follow these steps:
-
In the left navigation menu, under Infrastructure, select Gateways.
-
Click Add gateway.
-
Enter the following values:
Field Value Display Name My AI Gateway Name my-ai-gatewayEnvironment Select your environment. Public URL https://localhost:8443 -
Click Create.
After you click Create, the Console shows a Set up My AI Gateway panel with four steps for the Docker tab. Run them on the machine that hosts the gateway:
- Download and unzip the gateway package with the command that the panel shows.
- Open the unzipped directory, and run
./scripts/setup.sh. The script creates the listener certificate, the at-rest encryption key, and theapi-platform.envfile. It prints the admin password once, so copy it. - Click Copy next to the third step, and run the command. It appends the control plane host and your gateway token to
api-platform.env. - Start the gateway with
docker compose up.
The Console shows the gateway token only once, when you create the gateway. Run the command in step 3 before you close the panel.
If a default gateway port is already in use on your machine, edit the port mappings in the docker-compose.yaml file before you start the gateway, and use the same host port in the Public URL.
Expected result: The Gateways page shows your gateway with the Active and Self-hosted labels.
The following image shows the Gateways page with the active self-hosted gateway:

Once the AI Gateway is active, you can continue to create the Anthropic LLM Service Provider.
Step 2: Create and Deploy an Anthropic LLM Service Provider
-
In the left navigation menu, under Resources, select LLM service providers.
-
Click Add service provider.
-
Under Basic Details, enter the following values:
Field Value Name Anthropic Version v1.0 Context path /claudecode -
Under Provider Template, select Anthropic.
-
Under Runtime Configuration, paste your Anthropic API key in API key / Credential.
-
Under Deployment Configuration, select the environment that your gateway belongs to. Open the gateway list that appears, and select My AI Gateway. The list defaults to the managed gateway, so change it.
-
Click Add provider.
Expected result: The provider page opens. The Deployment tab shows My AI Gateway with the Deployed status.
For more details on registering providers, see Route LLM Traffic Through a Self-Hosted Gateway.
Step 3: Generate an API Key for Claude Code
Claude Code needs an API key from the AI Gateway to invoke the deployed Anthropic LLM Service Provider.
-
On the provider page, open the API Keys tab.
-
Click Create API key.
-
Enter a Display name, and click Create.
-
Copy and save the generated API key. The Console shows it only once.
Provide this API key to Claude Code in the
API-Keycustom header. -
Open the Overview tab, and copy the Invoke URL.
You use these values when you configure Claude Code.
Step 4: Configure Claude Code to Use the Anthropic LLM Service Provider
You can configure Claude Code with environment variables or with the Claude Code settings.json file.
Configure Environment Variables
Open a terminal session where you want to run Claude Code.
Run the following commands, replacing the placeholders with your values:
export ANTHROPIC_BASE_URL="<INVOKE URL>"
export ANTHROPIC_AUTH_TOKEN="dummy-value"
export ANTHROPIC_CUSTOM_HEADERS="API-Key: <AI GATEWAY API KEY>"
Replace:
<INVOKE URL>with the Invoke URL copied from the LLM Service Provider overview page<AI GATEWAY API KEY>with the API key generated for the LLM Service Provider
These environment variables apply only to the current terminal session. If you open a new terminal session, you must export them again.
To make the configuration permanent, add the environment variables to the Claude Code settings.json file.
- Location:
~/.claude/settings.json - Create the file if it does not already exist.
{
"env": {
"ANTHROPIC_BASE_URL": "<INVOKE URL>",
"ANTHROPIC_AUTH_TOKEN": "dummy-value",
"ANTHROPIC_CUSTOM_HEADERS": "API-Key: <AI GATEWAY API KEY>"
}
}
For more information, see the Claude Code settings documentation.
Configure SSL Certificate Trust
When you use a local AI Gateway over HTTPS, Claude Code must trust the certificate that the gateway presents.
If the AI Gateway uses a valid CA-signed certificate, no additional certificate configuration is required.
If the gateway uses a self-signed certificate, Claude Code can fail to connect because of certificate verification errors. In that case, extract the gateway certificate and point Node.js at it before you run the client:
-
Extract the certificate and save it as
gateway_certificate.pemin the current directory.echo -n | openssl s_client -connect localhost:8443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > gateway_certificate.pemIf you changed the HTTPS host port of the gateway, use that port instead of
8443. -
Export the certificate path in the terminal where you run the client.
export NODE_EXTRA_CA_CERTS="$PWD/gateway_certificate.pem"
For more information, see the Claude Code TLS troubleshooting documentation.
To bypass SSL certificate validation during testing, run:
export NODE_TLS_REJECT_UNAUTHORIZED=0
Step 5: Run Claude Code
After you set the required environment variables, run Claude Code:
claude
Claude Code now sends requests through the AI Gateway instead of calling Anthropic directly.
Use Case Examples
Implement AI Gateway Guardrails for Enhanced Control
AI Gateway guardrails enable granular control over the data exchanged between Claude Code and the Anthropic API.
By applying guardrails, you can enforce security and compliance policies such as:
- Input validation to ensure prompt integrity
- Output filtering to prevent leakage of sensitive data
- Rate limiting to control API usage and avoid cost overruns
For example, you can configure a PII Masking Regex policy on the provider's Guardrails tab to prevent Personally Identifiable Information (PII) from reaching the Anthropic API. If a user submits a prompt containing PII, the policy evaluates the request against defined patterns and redacts the matches before they reach the Anthropic API.
For more information on the PII Masking Regex policy, see the Policy Hub.
Rate Limiting at the AI Gateway
The AI Gateway supports request-based and token-based rate limiting for LLM traffic. This lets you control Claude Code usage when requests are routed through the gateway.
For example, set a consumer-level token limit on the provider's Rate Limiting tab. Each developer's key then gets its own quota, and the gateway returns HTTP 429 once a developer reaches it. For the steps, see Enforce Token-Based Rate Limiting on an LLM Service Provider.
This helps control token consumption and avoid unexpected costs.
Prompt Decorator
The AI Gateway supports the Prompt Decorator policy, which lets you modify or enrich prompts before the gateway sends them to the backend AI provider. This is useful for enforcing consistent instructions, adding system-level context, or guiding model behavior without requiring changes in the client application. For a full walkthrough, see Enforce a Consistent AI Persona.
As an example, you can configure a Prompt Decorator on the provider's Guardrails tab to append an instruction to all incoming prompts.
The following screenshot shows Claude Code responding to a prompt with no Prompt Decorator.
The following screenshot shows Claude Code responding to that same prompt with a Prompt Decorator configured to append the following decoration: "Be very concise. Use as little words as possible when answering."
For more information on the Prompt Decorator policy, see the Policy Hub.
Was this page helpful?



