Anthropic
In this guide, you will connect AISIX AI Gateway to Anthropic. Callers reach Claude models through the gateway's OpenAI-compatible API or the native Anthropic Messages API. AISIX owns the credential, model allowlist, rate limits, and usage accounting.
Anthropic is a native upstream: it uses the anthropic adapter and its own x-api-key authentication. Use this configuration to call Claude directly on api.anthropic.com. To reach Claude through AWS, use the AWS Bedrock Upstream instead.
Prerequisites
Before starting, prepare the following:
- A gateway with the admin API on
:3001and the proxy API on:3000. - The admin key from the gateway
config.yaml. - An Anthropic API key from the Anthropic Console and the Claude model ID you want to expose, for example
claude-sonnet-5.
Supported Capabilities
Anthropic is the native backend for the Messages API, and it also serves chat completions through translation.
| Endpoint | Supported | Streaming | Notes |
|---|---|---|---|
/v1/messages | Yes | Yes | Native Anthropic Messages API. |
/v1/messages/count_tokens | Yes | — | Anthropic-backed token counting. |
/v1/chat/completions | Yes | Yes | OpenAI-shaped requests translated to Messages. Non-text content blocks are dropped in translation. |
/v1/embeddings | No | — | Embeddings require the openai adapter. |
/v1/images/generations | No | — | Rejected: image generation requires provider: "openai". |
/v1/rerank | No | — | Anthropic is not in the rerank allowlist (openai, cohere, jina). |
See Provider Compatibility for the exact per-endpoint rules.
Configure the Anthropic Upstream
Create a provider key, model alias, and caller API key for the Anthropic-backed route.
Create a Provider Key
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" \
-d '{
"display_name": "anthropic-prod",
"provider": "anthropic",
"adapter": "anthropic",
"secret": "'"${ANTHROPIC_API_KEY}"'"
}'
❶ 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
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" \
-d '{
"display_name": "claude-sonnet-prod",
"provider": "anthropic",
"model_name": "claude-sonnet-5",
"provider_key_id": "'"${PROVIDER_KEY_ID}"'"
}'
❶ 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:
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
CALLER_KEY_HASH=$(printf '%s' "${AISIX_API_KEY}" | shasum -a 256 | awk '{print $1}')
curl -sS -X POST "http://127.0.0.1:3001/admin/v1/apikeys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
-d '{
"key_hash": "'"${CALLER_KEY_HASH}"'",
"allowed_models": ["claude-sonnet-prod"]
}'
❶ allowed_models must match the model alias you created.
Verify the Upstream
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. The same alias also works on /v1/chat/completions for OpenAI-shaped clients. If AISIX returns an upstream authentication error, check the provider key secret.
Behavior and Limits
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.
On /v1/chat/completions, OpenAI-shaped requests are translated to the Messages API, and non-text content blocks such as images are dropped during translation. For image or document inputs, call /v1/messages directly. See Anthropic Messages.
Claude model IDs from the 4.6 generation onward are pinned snapshots, not evergreen pointers. Check the Anthropic models reference for the current IDs.
Next Steps
- Anthropic SDK Quickstart — call this alias from an Anthropic SDK at
/v1/messages. - Anthropic Messages — the native Messages request and response shape.
- Provider Compatibility — the endpoint-by-endpoint support rules.