Source: https://aiprimetech.io/zh/learn/run-hermes-agent-with-claude-api/ [首页](/zh/) / [学习](/zh/learn/) / 通过网关让 Hermes Agent 使用 Claude:自定义提供商设置、成本控制与问题修复 # 通过网关在 Hermes Agent 中使用 Claude:自定义提供商配置、成本控制与问题修复 Hermes Agent 将密钥等敏感信息保存在 ~/.hermes/.env ,其余所有配置保存在 ~/.hermes/config.yaml。通过网关使用 Claude 的可靠方式,是配置一个采用 Anthropic Messages 格式的具名自定义提供商。快捷方式 provider: anthropic 配合不同的基础 URL,看起来正确,但对于任何无法识别的主机,它都会将请求发送到 Anthropic。 ## 安装 Linux / macOS / WSL2复制 ``` curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash ``` Windows复制 ``` iex (irm https://hermes-agent.nousresearch.com/install.ps1) ``` hermes setup 运行完整向导; hermes model 仅处理提供商和模型; hermes doctor 检查现有安装。 ## 将网关添加为自定义提供商 ~/.hermes/.env复制 ``` AIPRIME_API_KEY=your_gateway_key ``` ~/.hermes/config.yaml复制 ``` providers: aiprime: api: https://aiprimetech.io/v1 key_env: AIPRIME_API_KEY transport: anthropic_messages catalog_provider: anthropic model: provider: custom:aiprime default: claude-sonnet-5 ``` | 密钥 | 原因 | transport: anthropic_messages | 使用 Anthropic 的 Messages 格式。未设置此项时,Hermes 会回退到 OpenAI Chat Completions 格式 | key_env | 位于 .env 中、用于保存密钥的变量名称 | catalog_provider: anthropic | 网关的 Claude 模型继承 Anthropic 的上下文和视觉元数据 | provider: custom:aiprime | 选择具名提供商; /model custom:aiprime: 在聊天中切换 向导执行相同的操作: hermes model,然后选择 **自定义端点**,再选择 API 模式 **Anthropic Messages**。如果改选 Chat Completions,请在 URL 中保留 /v1 。 ## 为什么 provider: anthropic 配合基础 URL 无法生效 设置 provider: anthropic 和 base_url: https://aiprimetech.io 看起来正确,但并不起作用:在当前 Hermes 源码中,内置 Anthropic 提供商仅允许为 Anthropic、Claude 和 Azure 主机覆盖基础 URL,因此请求仍会发送到 Anthropic。请使用上面的具名自定义提供商。 ANTHROPIC_BASE_URL 在文档中被描述为用于覆盖 Anthropic 基础 URL 的设置,但 Hermes 中一个尚未解决的缺陷导致模型选择器忽略它。自定义提供商可以避开这两个问题。 ## 哪些因素会增加 token 用量,以及哪些设置可以限制用量 Hermes 执行的工作不止你看到的对话;除非将这些工作路由到其他地方,否则所有用量都会计入同一个密钥。 | 用量来源 | 设置 | Subagents (delegation) | delegation.max_concurrent_children (默认值为 10), delegation.max_iterations (默认值为 250), delegation.max_spawn_depth (默认值为 1);更便宜的 delegation.model | 每轮对话后的后台记忆和技能审查 | auxiliary.background_review.enabled: false,或更低的 max_input_tokens | 辅助任务(压缩、标题、视觉) | auxiliary..provider 和 .model ,以将这些任务发送到更便宜的模型 | 定时任务 | cron.model ,适用于所有任务; hermes cron pause 或 hermes pause | 消息网关(Telegram、Discord 等) | 允许列表,例如 TELEGRAM_ALLOWED_USERS;避免使用 GATEWAY_ALLOW_ALL_USERS=true ~/.hermes/config.yaml(新增配置)复制 ``` delegation: max_concurrent_children: 3 model: claude-haiku-4-5 auxiliary: background_review: enabled: false cron: model: claude-haiku-4-5 ``` hermes prompt-size 显示每次调用都会产生的固定成本; /usage 和 /compress 在长会话中有所帮助。 ## 使用 Claude Pro 或 Max 登录,而非密钥 Hermes 可以登录 Claude 账户,但其文档说明,这种方式仅适用于已购买额外用量额度的 Max 套餐,Pro 订阅用户无法使用。使用网关提供的 API 密钥时,没有订阅使用时间窗口的限制;用量按 token 从余额中扣费。 ## 模型 | 模型 ID | 适用场景 | claude-sonnet-5 | 编程和智能体任务的默认选择:速度快、能力强、价格适中。 | claude-opus-5-5 | 更复杂的推理、大规模重构、长时间运行的智能体任务。 | claude-fable-5-1 | 能力最强,价格也最高;留给最困难的任务使用。 | claude-haiku-4-5 | 价格低、速度快:标题、摘要、分类和小步骤。 Hermes 需要至少 64K 个 token 的上下文窗口;表中的每个模型都符合要求。 ## 故障排查 | 你会看到什么 | 原因 | 解决方法 | 首次运行时出现 HTTP 400 | 模型名称与网关模型 ID 不匹配 | 使用上表中的 ID | 请求被发送到 Anthropic,或因 Anthropic 身份验证错误而失败 | provider: anthropic 使用第三方基础 URL | 使用具名自定义提供商 | 回复乱码或为空 | 传输协议与 URL 不匹配 | transport: anthropic_messages 用于 Claude | 超出上下文长度 | 会话超出配置的上下文窗口 | 设置 model.context_length; /compress | 403 Your request was blocked | 端点前的防火墙拒绝客户端访问 | 添加 extra_headers 使用类似浏览器的 User-Agent | 更新后设置缺失 | 配置结构已更改 | hermes config check中的 curl 检查,然后运行 hermes config migrate | 机器人在 Telegram 或 Discord 上没有回应 | 网关未运行或发送者未获授权 | hermes gateway status;检查 ~/.hermes/logs/gateway.log 正在比较智能体框架?请参阅 [OpenClaw 配置指南](/zh/learn/run-openclaw-with-claude-api/). ## 常见问题 如何让 Hermes Agent 使用自定义 Claude 端点? 在 ~/.hermes/config.yaml 中添加具名提供商,将 api 设为网关 URL,让 key_env 指向 ~/.hermes/.env 中的变量,并设置 transport: anthropic_messages,然后设置 model.provider: custom:。 为什么 Hermes 会忽略我的 Anthropic base_url? 使用 provider: anthropic 时,Hermes 仅接受 Anthropic、Claude 和 Azure 主机的基础 URL 覆盖设置,因此第三方 URL 会被丢弃。请改用具名自定义提供商。 如何减少 Hermes Agent 的 token 用量? 限制子智能体数量(委派设置),将辅助任务和 cron 定时任务路由到更便宜的模型,关闭后台审查,并检查 hermes prompt-size。 Hermes Agent 可以使用 Claude Pro 订阅吗? 根据 Hermes 文档,不可以:Claude 登录方式仅适用于拥有额外用量额度的 Max 订阅。使用 API 密钥则可以完全避开订阅限制。 几分钟内开始使用 Claude 获取 API 密钥,无需 Anthropic 账户,也无需加入候补名单。[获取你的 API 密钥](/register) AI Prime Tech 是独立的 API 网关,与 Anthropic 无关联,未获得其背书,也不是其经销商。Claude 及相关模型名称是其各自所有者的商标。 ## 更多 Claude API 指南 [如何获取 Claude API 密钥](/zh/learn/how-to-get-a-claude-api-key/)[Claude API 定价详解](/zh/learn/claude-api-pricing-explained/)[使用 Claude API 最便宜的方式](/zh/learn/cheapest-way-to-use-claude-api/)[通过 Claude API 不限量使用 Cursor](/learn/use-claude-api-with-cursor/)[不限量访问 Claude Code](/zh/learn/use-claude-api-with-claude-code/)[Claude API 网关与 Anthropic 直连对比](/zh/learn/claude-api-vs-anthropic-direct/)[通过 OpenAI SDK 使用 Claude:OpenAI 兼容端点、流式传输、工具与限制](/zh/learn/openai-compatible-claude-api/)[Claude 模型详解:Claude Opus、Sonnet、Haiku 与 Fable 的模型对比——全部 Claude API 模型、Anthropic 模型名称与价格(2026)](/zh/learn/claude-api-models-compared/)[使用加密货币支付 Claude API 费用](/zh/learn/claude-api-with-crypto-payment/)[无需候补名单即可访问 Claude API](/zh/learn/claude-api-without-waitlist/)[如何减少 Claude 词元用量](/zh/learn/how-to-reduce-claude-token-usage/)[通过 Claude API 不限量使用 Cline](/zh/learn/use-claude-api-with-cline/)[通过 Claude API 不限量使用 Roo Code](/zh/learn/use-claude-api-with-roo-code/)[在 JetBrains IDE 中不限量使用 Claude](/zh/learn/use-claude-api-with-jetbrains/)[通过网关在 Aider 中使用 Claude:ANTHROPIC_API_BASE、配置文件、架构师模式与问题修复](/zh/learn/use-claude-api-with-aider/)[在 VS Code 中不限量使用 Claude](/zh/learn/use-claude-api-with-vscode/)[OpenCode 的 Claude 配置:opencode.json 设置、模型与常见错误](/zh/learn/use-claude-api-with-opencode/)[使用 Claude 不限量运行 OpenClaw](/zh/learn/run-openclaw-with-claude-api/)[兼容 Anthropic 的 API 意味着什么](/zh/learn/anthropic-compatible-api/)[Claude Code API 密钥 — ANTHROPIC_API_KEY:如何获取、配置,以及何时应改用 claude setup-token](/zh/learn/claude-code-api-key-setup/)[Claude Code API 成本 — 定价与降低成本的方法](/zh/learn/claude-code-api-costs/)[Claude API 错误详解:服务器错误 500、过载 529、速率限制 429、错误请求 400 — 以及各自的修复方法](/zh/learn/claude-api-errors-troubleshooting/)[如何购买 Claude API 额度,以及为什么购买 Claude 额度比任何“购买 Claude 账户”的方案都更好](/zh/learn/buy-claude-api-credits/)[Claude 免费 API:有免费的 Claude API 密钥吗?2026 年究竟有哪些内容免费?](/zh/learn/claude-api-free-trial/)[Claude API 与 Claude Pro/Max 订阅——如何选择](/zh/learn/claude-api-vs-subscription/)[通过自定义提供商使用 Codex CLI:config.toml、GPT 与 Claude 模型、IDE 扩展与问题修复](/zh/learn/use-claude-api-with-codex/)[将 Claude 连接到 n8n](/zh/learn/use-claude-api-with-n8n/)[通过 LiteLLM 路由到 Claude](/zh/learn/use-claude-api-with-litellm/)[在 Kilo Code 中使用 Claude](/zh/learn/use-claude-api-with-kilo-code/)[通过网关在 GitHub Copilot Chat 中使用 Claude:自定义端点配置、智能体模式与问题修复](/zh/learn/use-claude-api-with-github-copilot/)[通过网关将 Zed 连接到 Claude](/zh/learn/use-claude-api-with-zed/)[将 Cherry Studio 连接到 Claude](/zh/learn/use-claude-api-with-cherry-studio/)[LangChain 中的 ChatAnthropic:导入、base_url、流式传输、工具和错误](/zh/learn/use-claude-api-with-langchain/)[Anthropic Python SDK:安装、设置 base_url、流式传输和错误处理](/zh/learn/anthropic-python-sdk/)[通过 Vercel AI SDK 使用 Claude:createAnthropic baseURL、流式传输和问题修复](/zh/learn/use-claude-api-with-vercel-ai-sdk/)[使用 Claude 运行 Factory Droid](/zh/learn/use-claude-api-with-factory-droid/)[Claude Code API 详解](/zh/learn/claude-code-api/)[将 Claude API 集成到您的应用中](/zh/learn/claude-api-integration/)[如何不受限制地使用 Claude,以及为什么不存在“Claude Code 破解版本”](/zh/learn/get-unlimited-claude-usage/)