# Connect to Anthropic Claude

[Anthropic](https://www.anthropic.com/) provides access to Claude models through an API. This guide shows how to route traffic to Anthropic through API7 Gateway using the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* Install [Docker](https://docs.docker.com/get-docker/).

* Install [cURL](https://curl.se/) to send requests to the services for validation.

* Have a running API7 Gateway instance.

* Create a [token from the Dashboard](https://docs.api7.ai/api7-gateway/reference/obtain-dashboard-token.md) 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](https://docs.api7.ai/api7-gateway/ai-gateway/get-started.md#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[​](#obtain-an-anthropic-api-key "Direct link to Obtain an Anthropic API Key")

Create an account and API key by following the [Anthropic API documentation](https://docs.anthropic.com/en/api/getting-started). 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[​](#configure-the-ai-proxy-for-anthropic "Direct link to Configure the AI Proxy for Anthropic")

Create a route with the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin:

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/routes/anthropic-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d @- <<EOF

  {

    "name": "anthropic-route",

    "service_id": "$SERVICE_ID",

    "paths": ["/anthropic"],

    "plugins": {

      "ai-proxy": {

        "provider": "anthropic",

        "auth": {

          "header": {

            "Authorization": "Bearer $ANTHROPIC_API_KEY"

          }

        },

        "options": {

          "model": "claude-sonnet-5-5"

        }

      }

    }

  }

EOF
```

❶ Set the provider to `anthropic`.

❷ Attach the Anthropic API key using the `Authorization` header.

❸ Set the model to `claude-sonnet-5-5`. See the [Anthropic models page](https://docs.anthropic.com/en/docs/about-claude/models) for available models.

adc.yaml

```
services:

  - name: Anthropic Service

    routes:

      - uris:

          - /anthropic

        name: anthropic-route

        plugins:

          ai-proxy:

            provider: anthropic

            auth:

              header:

                Authorization: "Bearer ${ANTHROPIC_API_KEY}"

            options:

              model: claude-sonnet-5-5

    labels:

      docs-example: anthropic-service
```

❶ Set the provider to `anthropic`.

❷ Attach the Anthropic API key using the `Authorization` header.

❸ Set the model to `claude-sonnet-5-5`. See the [Anthropic models page](https://docs.anthropic.com/en/docs/about-claude/models) for available models.

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=anthropic-service
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=anthropic-service
```

## Validate the Configuration[​](#validate-the-configuration "Direct link to 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-5-5",

  "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](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/protocol-conversion.md).

To enable streaming responses, set `"stream": true` in the request body. Use the [`proxy-buffering`](https://docs.api7.ai/hub/proxy-buffering.md) plugin to disable NGINX `proxy_buffering` to avoid server-sent events (SSE) being buffered.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have learned how to route traffic to Anthropic through API7 Gateway. See the [Anthropic API documentation](https://docs.anthropic.com/en/api/getting-started) and [Models](https://docs.anthropic.com/en/docs/about-claude/models) pages for more details.

* [Protocol Conversion](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/protocol-conversion.md) — Use native Anthropic protocol with any backend provider, or route Anthropic requests to OpenAI.
* [Multi-LLM Routing and Fallback](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/multi-llm-routing-and-fallback.md) — Combine Anthropic with other providers for failover.
