Skip to content

连接 Claude(Anthropic 官方)

预计时间:10-15 分钟

Claude 是 Anthropic 的模型,在复杂代码任务上表现出色。

在国内网络环境下,通常需要先完成 1.3 网络配置,否则可能出现连接超时。


学完你能做什么

  • 获取 Anthropic API Key
  • 在 OpenCode 里连接 Anthropic(Claude)
  • 发送第一句话并收到回复

🎒 开始前的准备

  • [ ] 完成了 1.2 安装,能运行 opencode
  • [ ] 完成了 1.3 网络配置(否则可能超时)
  • [ ] 已能访问 https://console.anthropic.com 并拿到 API Key

跟我做

第 1 步:注册 Anthropic 账号

访问:https://console.anthropic.com

按页面提示注册并登录。


第 2 步:添加付款方式(通常必需)

Anthropic 通常要求绑定信用卡才能使用 API。

如果你没有可用的国际信用卡,可以考虑先使用国内直连模型(如 DeepSeek),或使用 1.4a 免费模型


第 3 步:获取 API Key

进入 API Keys 页面:

创建 Key,并立刻复制保存。


第 4 步:在 OpenCode 中连接 Anthropic

启动 OpenCode:

bash
opencode

输入:

/connect

选择 Anthropic,粘贴 API Key。

成功后会看到类似:

✓ Provider added successfully!
✓ Anthropic is now your active provider

第 5 步:发送第一句话(验证成功)

Hello, please introduce yourself

检查点 ✅

  • [ ] 发送消息能收到 AI 回复
  • [ ] 没有报错(如 connection timeout / API key invalid

踩坑提醒

现象原因解决
connection timeout网络代理问题检查代理配置,参考 1.3 网络配置
API key invalidKey 格式错误Claude Key 通常以 sk-ant- 开头

下一步

遇到问题?

配置过程中卡住了?加入社群,和 500+ 同路人一起交流,实时答疑。