Skip to main content

Anthropic

Connect AISIX AI Gateway to Anthropic so applications can call Claude models through the gateway's OpenAI-compatible API or native Anthropic Messages API. AISIX keeps the Anthropic credential on the gateway side. It authorizes model access with caller API keys and allowlists, and applies the same rate-limit and usage-accounting controls as other model aliases.

Anthropic is a native upstream. It uses the anthropic adapter and Anthropic's x-api-key authentication. To reach Claude through AWS, use AWS Bedrock instead.

Prerequisites

The following examples use a self-hosted AISIX gateway. Before configuring the upstream, prepare the following:

Configure the Anthropic Upstream

Create a provider key, model alias, and caller API key for the Anthropic-backed route.

Create a Provider Key

Create the provider key that stores the Anthropic credential:

# Replace with your values
export AISIX_ADMIN_KEY="YOUR_ADMIN_KEY"
export ANTHROPIC_API_KEY="YOUR_PROVIDER_API_KEY"

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/provider_keys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"display_name": "anthropic-prod",
"provider": "anthropic",
"adapter": "anthropic",
"secret": "${ANTHROPIC_API_KEY}"
}
EOF

provider is anthropic.

adapter is anthropic. AISIX sends the credential as the x-api-key header and adds anthropic-version: 2023-06-01 on outbound calls.

secret stores the Anthropic API key. It follows the credential-handling behavior in Provider Credentials.

You can omit api_base for Anthropic; it defaults to https://api.anthropic.com. Copy the returned provider key ID.

Create a Model

Claude model IDs from the 4.6 generation onward are pinned snapshots, not evergreen pointers. Check the Anthropic models reference for the current IDs.

Create the model alias callers will send in requests:

# Replace with your values
export PROVIDER_KEY_ID="YOUR_PROVIDER_KEY_ID"

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/models" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"display_name": "claude-sonnet-prod",
"provider": "anthropic",
"model_name": "claude-sonnet-5",
"provider_key_id": "${PROVIDER_KEY_ID}"
}
EOF

display_name is the alias callers send in model.

model_name is the Claude model ID, for example claude-sonnet-5, claude-opus-4-8, or claude-haiku-4-5.

provider_key_id attaches the alias to the Anthropic provider key.

Create a Caller API Key

Choose the caller API key value that the application will send to AISIX, then hash it for the admin resource:

# Replace with your values
export AISIX_API_KEY="YOUR_CALLER_API_KEY"

CALLER_KEY_HASH=$(printf '%s' "${AISIX_API_KEY}" | shasum -a 256 | awk '{print $1}')

Create the caller API key resource that can access the model alias:

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/apikeys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"key_hash": "${CALLER_KEY_HASH}",
"allowed_models": ["claude-sonnet-prod"]
}
EOF

The allowed_models value must match the model alias you created.

Callers authenticate to AISIX with a caller API key in the Authorization: Bearer header. AISIX supplies the Anthropic x-api-key and anthropic-version headers to the upstream; clients do not send them.

Verify the Provider Connection

Send a native Messages request through the AISIX proxy:

curl -sS -X POST "http://127.0.0.1:3000/v1/messages" \
-H "Authorization: Bearer ${AISIX_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-prod",
"max_tokens": 64,
"messages": [
{
"role": "user",
"content": "Say hello from Claude."
}
]
}'

The gateway returns an Anthropic Messages response that echoes the caller-facing alias claude-sonnet-prod. If the request fails with an upstream authentication error, check the provider key secret.

The same alias also works on /v1/chat/completions for OpenAI-shaped clients. This translation drops non-text content blocks, so call /v1/messages directly for image or document inputs.

Next Steps

You have now connected AISIX to Anthropic and verified the model alias. Continue with these guides: