接入 Anthropic Claude
Anthropic 通过 API 提供 Claude 模型能力。你可以使用 ai-proxy 插件将 Claude 调用接入 API7 AI 网关,由网关集中处理凭证、访问控制、审计和用量治理。
前提条件
获取 Anthropic 访问密钥
参考 Anthropic API 文档创建访问密钥,并写入环境变量:
export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxx
配置 Claude 代理
- Admin API
- ADC
curl "http://127.0.0.1:7080/apisix/admin/routes?gateway_group_id=default" -X PUT \
-H "X-API-KEY: $ADMIN_API_KEY" \
-d '{
"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"
}
}
}
}'
adc.yaml
services:
- name: Anthropic Service
routes:
- name: anthropic-route
uris:
- /anthropic
plugins:
ai-proxy:
provider: anthropic
auth:
header:
Authorization: Bearer ${ANTHROPIC_API_KEY}
options:
model: claude-sonnet-4-20250514
建议配置
- 对外部用户场景启用
ai-prompt-guard,降低提示词注入风险。 - 使用
ai-rate-limiting控制 Claude 模型调用的令牌预算。 - 如需使用 Anthropic SDK 调用兼容 OpenAI 协议的后端,请参考协议转换。