使用本指南将 Claude Code 连接到 CometAPI。 官方参考资料:Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
模型可用性会随时间变化。要查看当前的 Claude model ID,请检查
CometAPI Models page。
前提条件
- 从你的 dashboard 获取一个 CometAPI key(以
sk-开头) - 已安装 Git
- 支持的操作系统:macOS、Linux 或 Windows
安装 Claude Code
配置 CometAPI 端点
创建或编辑 settings 文件:- macOS / Linux:
~/.claude/settings.json - Windows:
%USERPROFILE%\.claude\settings.json
sk-your-cometapi-key 替换为你实际的 CometAPI key,然后启动 Claude Code:
故障排查
settings.json 没有生效?
- 彻底重启你的终端(关闭所有窗口后重新打开)
- 如果仍然无效,创建
~/.claude.json并添加: - 作为后备方案,直接导出环境变量:
Invalid API Key 或 Please run /login?
检查 ~/.claude/settings.json 是否存在,以及 JSON 格式是否有效(没有尾随逗号、引号正确)。可在 jsonlint.com 验证。
之前登录过 Anthropic 官方服务?
Claude Code 会优先使用缓存的官方凭据。在 Claude Code 内运行 /logout,关闭它,然后重新启动。如果仍然失败:
offline?
Claude Code 通过 Google 检查连接状态。offline 仅表示无法访问 Google——这不会影响 CometAPI 的使用。
Fetch / 网页浏览失败?
Claude Code 的 Fetch 功能会先调用 Anthropic 的原生服务,这需要直接访问互联网。你可能需要配置系统级代理。