跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

Claude Desktop

最后更新 查看 MarkdownAgent 设置

将 Claude Desktop ↗ 指向 AI Gateway,而不是直接指向 Anthropic,即可获得 Anthropic 请求的可观测性、缓存和集中式凭据,同时无需改变 Claude Desktop 的使用方式。Claude Desktop 可以将第三方推理请求发送到自定义网关;此配置会将这些请求发送到 AI Gateway 的 Anthropic 端点,并使用 Cloudflare 网关令牌或 Cloudflare Access 进行身份验证。AI Gateway 可通过统一计费或已存储的提供程序密钥 (BYOK)为你提供 Anthropic 凭据。

如果你的网关受 Cloudflare Access 保护,请参阅与 Cloudflare Access 搭配使用。

前提条件

开始之前,你需要:

使用网关令牌

  1. 在 Claude Desktop 中,选择 Help(帮助) > Troubleshooting(故障排除) > Enable Developer Mode(启用开发者模式)。

  2. 选择 Developer(开发者) > Configure Third-Party Inference(配置第三方推理)。

  3. 在 Connection(连接) 中,将连接类型设为 Gateway。

  4. 在 Gateway credentials(网关凭据) 中,将 Credential kind(凭据类型) 设为 Static API key(静态 API 密钥)。

  5. 将 Gateway API key(网关 API 密钥) 设为你的 Cloudflare gateway 令牌。

    将 <CF_AIG_TOKEN> 替换为你的 gateway 令牌。

    <CF_AIG_TOKEN>
  6. 将 Gateway auth scheme(网关身份验证方案) 设为 Bearer。

  7. 将 gateway base URL 设为你的 gateway 的 Anthropic 端点。

    将 <ACCOUNT_ID> 和 <GATEWAY_ID> 替换为你的值。

    https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/<GATEWAY_ID>/anthropic
  8. 在 Models(模型) 中,添加要使用的 Claude 模型。

    字段 值
    模型 ID claude-sonnet-4-5
    显示名称 Claude Sonnet 4.5
    层级别名 sonnet
  9. 在 Gateway credentials(网关凭据) 中,选择 Test connection(测试连接)。

  10. 开始 Claude Desktop 对话。请求现在会通过 AI Gateway 路由。

与 Cloudflare Access 搭配使用

如果你的网关受 Cloudflare Access保护,Claude Desktop 可以使用短期 Access 令牌进行身份验证,而无需网关令牌。请使用本地辅助脚本通过 cloudflared 获取令牌。

开始之前,请设置受 Access 保护的自定义域,并配置允许你的身份通过的策略。在运行 Claude Desktop 的计算机上安装 cloudflared。

  1. 创建本地辅助脚本,并将 ai-gateway.example.com 替换为你的网关自定义域:

    aig-access.shsh
    #!/bin/sh
    exec cloudflared access login --no-verbose --app https://ai-gateway.example.com

    --no-verbose 标志只会将 JSON Web Token (JWT) 输出到标准输出,这是辅助脚本所需的。如果 Claude Desktop 找不到 cloudflared,请将脚本中的命令替换为 command -v cloudflared 返回的完整路径。

  2. 为脚本添加可执行权限:

    chmod +x aig-access.sh
  3. 在 Claude Desktop 中,选择 Help(帮助) > Troubleshooting(故障排除) > Enable Developer Mode(启用开发者模式)。

  4. 选择 Developer(开发者) > Configure Third-Party Inference(配置第三方推理)。

  5. 在 Connection(连接) 中,将连接类型设为 Gateway。

  6. 在 Gateway credentials 中,将 Credential kind 设为 Helper script,将 Gateway auth scheme 设为 Bearer。

  7. 将网关基础 URL 设为 https://ai-gateway.example.com/anthropic,并将 ai-gateway.example.com 替换为你的网关自定义域。

  8. 在 Helper Script 中,将路径设为本地 aig-access.sh 脚本的位置。请使用文件的完整路径。

  9. 在 Models(模型) 中,添加要使用的 Claude 模型。

  10. 在 Gateway credentials 中,选择 Test connection。根据提示完成 Access 登录流程,然后启动 Claude Desktop 对话。

要确认流量已到达 AI Gateway,请参阅验证是否生效。

这篇文档对您有帮助吗?