Anthropic ↗ 帮助构建可靠、可解释和可引导的 AI 系统。
基础 URL
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic在请求中包含 API 密钥
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic/v1/messages \
--header 'x-api-key: {anthropic_api_key}' \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'anthropic-version: 2023-06-01' \
--header 'Content-Type: application/json' \
--data '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is Cloudflare?"}
]
}'curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic/v1/messages \
--header 'x-api-key: {anthropic_api_key}' \
--header 'anthropic-version: 2023-06-01' \
--header 'Content-Type: application/json' \
--data '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is Cloudflare?"}
]
}'使用存储密钥 (BYOK) / Unified Billing
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic/v1/messages \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'anthropic-version: 2023-06-01' \
--header 'Content-Type: application/json' \
--data '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is Cloudflare?"}
]
}'在请求中包含密钥
import Anthropic from "@anthropic-ai/sdk";
const baseURL = `https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayId}/anthropic`;
const anthropic = new Anthropic({
apiKey: "{ANTHROPIC_API_KEY}",
baseURL,
defaultHeaders: {
Authorization: `Bearer {cf_api_token}`,
},
});
const message = await anthropic.messages.create({
model: "claude-sonnet-4-5",
messages: [{ role: "user", content: "What is Cloudflare?" }],
max_tokens: 1024,
});import Anthropic from "@anthropic-ai/sdk";
const baseURL = `https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayId}/anthropic`;
const anthropic = new Anthropic({
apiKey: "{ANTHROPIC_API_KEY}",
baseURL,
});
const message = await anthropic.messages.create({
model: "claude-sonnet-4-5",
messages: [{ role: "user", content: "What is Cloudflare?" }],
max_tokens: 1024,
});使用存储密钥 (BYOK) / Unified Billing
import Anthropic from "@anthropic-ai/sdk";
const baseURL = `https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayId}/anthropic`;
const anthropic = new Anthropic({
baseURL,
defaultHeaders: {
Authorization: `Bearer {cf_api_token}`,
},
});
const message = await anthropic.messages.create({
model: "claude-sonnet-4-5",
messages: [{ role: "user", content: "What is Cloudflare?" }],
max_tokens: 1024,
});你也可以通过 REST API 使用 OpenAI API schema 访问 Anthropic 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "anthropic/{model}"
}