跳转到主要内容
OpenCodeGitHub)是 一个开源的终端 AI 编码 agent,支持众多 provider。
协议:OpenAI 兼容
  • Base URL: https://api.orcarouter.ai/v1 /v1
通过 OpenAI 协议使用的 Claude 推理模型会拒绝 temperature != 1400 temperature may only be set to 1 when thinking is enabled)。请使用 非推理模型,或启用 reasoningEffort——参见 启用思考

安装

npm install -g opencode-ai

配置

配置文件:~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "orcarouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OrcaRouter",
      "options": { "baseURL": "https://api.orcarouter.ai/v1", "apiKey": "sk-orca-..." },
      "models": { "orcarouter/auto": { "name": "OrcaRouter Auto" } }
    }
  },
  "model": "orcarouter/orcarouter/auto"
}
如果你愿意,可以换成具体模型,例如 google/gemini-2.5-flashanthropic/claude-opus-4.8。模型 ID 始终使用 vendor/model 格式。

运行

opencode run "Reply with exactly: OK"
预期输出:OK

注意事项

  • base URL 必须包含 /v1
  • 模型引用使用 provider/model 格式。由于 provider 名为 orcarouter,而模型 ID 本身也带有 vendor 前缀,因此该 引用是三段式:orcarouter/orcarouter/auto(具体模型则为 orcarouter/anthropic/claude-opus-4.8)。
VS Code 扩展: OpenCode 的官方 VS Code 扩展(sst-dev.opencode) 会在编辑器内运行该 CLI,并共享同一个 opencode.json——不存在 单独的编辑器内端点设置。按上述方法配置一次,扩展即会自动读取。

启用思考 / 推理

在模型的 options 中设置 reasoningEffort
"models": {
  "anthropic/claude-sonnet-4.6": {
    "name": "Sonnet 4.6",
    "options": { "reasoningEffort": "high" }
  }
}
启用 reasoningEffort 也能绕过上面的 temperature 警告—— 启用思考后,temperature = 1 是合法的,因此 400 错误会消失。如需 Anthropic 原生控制,@ai-sdk/anthropic provider 接受 thinking: { type: "enabled", budgetTokens: N }