Docs
API7 GatewayAI GatewayLLM ProvidersConnect to Anthropic Claude
Version: 3.10.x

Connect to Anthropic Claude

Anthropic provides access to Claude models through an API. This guide shows how to route traffic to Anthropic through API7 Gateway using the ai-proxy plugin.

Prerequisites

  • Install Docker.

  • Install cURL to send requests to the services for validation.

  • Have a running API7 Gateway instance.

  • Create a token from the Dashboard and save it to an environment variable:

    export API_KEY=your-dashboard-token   # replace with your Dashboard token
  • Replace {gateway_group_id} with your gateway group ID. Use default if you are following the quickstart.

  • If you are following the Admin API examples, create or reuse a service in API7 Gateway. If you do not have one yet, follow Create or Reuse a Service, then save its ID to an environment variable:

    export SERVICE_ID=your-service-id         # replace with your service ID

Obtain an Anthropic API Key

Create an account and API key by following the Anthropic API documentation. Save the key to an environment variable:

export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxx   # replace with your Anthropic API key

Configure the AI Proxy for Anthropic

Create a route with the ai-proxy plugin:

curl -k "https://localhost:7443/apisix/admin/routes?gateway_group_id={gateway_group_id}" -X PUT \
  -H "X-API-KEY: ${API_KEY}" \
  --data-binary @- <<EOF
  {
    "id": "anthropic-route",
    "service_id": "$SERVICE_ID",
    "paths": ["/anthropic"],
    "plugins": {
      "ai-proxy": {
        "provider": "anthropic",
        "auth": {
          "header": {
            "Authorization": "Bearer $ANTHROPIC_API_KEY"
          }
        },
        "options": {
          "model": "claude-sonnet-4-20250514"
        }
      }
    }
  }
EOF

❶ Set the provider to anthropic.

❷ Attach the Anthropic API key using the Authorization header.

❸ Set the model to claude-sonnet-4-20250514. See the Anthropic models page for available models.

Validate the Configuration

Send a chat completion request:

curl "http://127.0.0.1:9080/anthropic" -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      { "role": "user", "content": "What is the capital of France?" }
    ]
  }'

You should receive a response similar to the following:

{
  "id": "msg_01abc123",
  "object": "chat.completion",
  "model": "claude-sonnet-4-20250514",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 8,
    "total_tokens": 20
  }
}

note

API7 Gateway normalizes all LLM responses to the OpenAI chat completion format, regardless of the backend provider. Clients always receive a consistent response structure. To use native Anthropic protocol, see Protocol Conversion.

To enable streaming responses, set "stream": true in the request body. Use the proxy-buffering plugin to disable NGINX proxy_buffering to avoid server-sent events (SSE) being buffered.

Next Steps

You have learned how to route traffic to Anthropic through API7 Gateway. See the Anthropic API documentation and Models pages for more details.