中国站
帮助中心 > 人工智能 > 大模型服务 > 第三方工具调用 > OpenCode 配置使用教程

OpenCode 配置使用教程

OpenCode 配置使用教程

OpenCode 按照官方文档安装即可,官网有很详细教程
https://opencode.ai/docs/#%E5%AE%89%E8%A3%85

配置模型
安装完成后,编辑配置文件,在 ~/.config/opencode/opencode.json,添加模型提供商

  1. {
  2. "$schema": "https://opencode.ai/config.json",
  3. "provider": {
  4. "jnm": {
  5. "npm": "@ai-sdk/openai",
  6. "name": "jnm",
  7. "options": {
  8. "baseURL": "http://xxx/v1"
  9. },
  10. "models": {
  11. "gpt-5.3-codex": {
  12. "name": "GPT-5.3-codex",
  13. "thinking": true,
  14. "modalities": {
  15. "input": [
  16. "text",
  17. "image",
  18. "pdf"
  19. ],
  20. "output": [
  21. "text"
  22. ]
  23. },
  24. "limit": {
  25. "context": 400000,
  26. "output": 128000
  27. },
  28. "options": {
  29. "store": false,
  30. "reasoningEffort": "xhigh",
  31. "textVerbosity": "high",
  32. "reasoningSummary": "auto",
  33. "include": [
  34. "reasoning.encrypted_content"
  35. ]
  36. }
  37. },
  38. "gpt-5.2-codex": {
  39. "name": "GPT-5.2 Codex",
  40. "options": {
  41. "include": [
  42. "reasoning.encrypted_content"
  43. ],
  44. "store": false
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }

配置密钥
方式一:使用命令行(推荐)

  1. # 登录或更新某个供应商的 Key
  2. opencode auth login
  3. # 查看当前已配置的所有供应商和 Key 状态
  4. opencode auth list
  5. # 删除指定供应商的 Key
  6. opencode auth logout <供应商名称>

方式二:手动编辑配置文件
在 ~/.local/share/opencode/auth.json 中添加对应供应商的 API Key

  1. {
  2. "供应商名称": {
  3. "type": "api",
  4. "key": "你的API密钥"
  5. }
  6. }

小技巧:在 OpenCode 中按 Ctrl + T 可切换不同的推理强度(variants)。