---
url: https://limapi.com/docs/agents/opencode.md
---
# OpenCode

OpenCode 是一款终端 AI 编程工具，通过 Anthropic 兼容协议接入 LimAPI。

::: tip 懒人方式
不想手动改配置？使用 [LimAPI Agent 桌面客户端](/agents/limapi-agent) 可一键完成安装与配置。
:::

## 安装 OpenCode

1. 安装 Node.js（v18.0 或更高版本）。
2. 在终端中执行以下命令安装 OpenCode：

```bash
npm install -g opencode-ai
```

运行以下命令验证安装，若有版本号输出，则表示安装成功：

```bash
opencode -v
```

## 配置接入凭证

使用文本编辑器打开配置文件：

* **macOS / Linux**：`~/.config/opencode/opencode.json`
* **Windows**：`C:\Users\<用户名>\.config\opencode\opencode.json`

写入以下内容，将 `YOUR_API_KEY` 替换为你在 [Portal](https://limapi.com/) 创建的 API Key：

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "limapi": {
      "npm": "@ai-sdk/anthropic",
      "name": "LimAPI",
      "options": {
        "baseURL": "https://limapi.com/api/anthropic/v1",
        "apiKey": "YOUR_API_KEY"
      },
      "models": {
        "qwen3.8-max": {
          "name": "Qwen3.8 Max",
          "contextWindow": 1048576,
          "maxOutputTokens": 16384,
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          }
        },
        "qwen3.7-max": {
          "name": "Qwen3.7 Max",
          "options": {
            "reasoning": true
          }
        },
        "qwen3.7-plus": {
          "name": "Qwen3.7 Plus",
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "options": {
            "reasoning": true
          }
        },
        "qwen3.6-plus": {
          "name": "Qwen3.6 Plus",
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "options": {
            "reasoning": true
          }
        },
        "qwen3.6-flash": {
          "name": "Qwen3.6 Flash",
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "options": {
            "reasoning": true
          }
        },
        "claude-opus-5": {
          "name": "Claude Opus 5",
          "contextWindow": 1000000,
          "maxOutputTokens": 32768
        },
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6",
          "contextWindow": 200000,
          "maxOutputTokens": 8192
        },
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro"
        },
        "deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash"
        },
        "kimi-k2.7-code": {
          "name": "Kimi K2.7 Code",
          "options": {
            "reasoning": true
          }
        },
        "kimi-k2.6": {
          "name": "Kimi K2.6",
          "options": {
            "reasoning": true
          }
        },
        "glm-5.2": {
          "name": "GLM 5.2",
          "options": {
            "reasoning": true
          }
        },
        "glm-5.1": {
          "name": "GLM 5.1",
          "options": {
            "reasoning": true
          }
        },
        "glm-5": {
          "name": "GLM 5",
          "options": {
            "reasoning": true
          }
        },
        "MiniMax-M2.5": {
          "name": "MiniMax M2.5"
        }
      }
    }
  }
}
```

| 字段 | 说明 |
|------|------|
| `npm` | 固定为 `@ai-sdk/anthropic`，表示走 Anthropic Messages 协议 |
| `options.baseURL` | LimAPI Anthropic 兼容端点，固定为 `https://limapi.com/api/anthropic/v1` |
| `options.apiKey` | Portal 创建的 API Key |
| `models` | 模型清单，按需增删；如需添加其他模型，以相同格式追加即可，完整列表见 `GET /api/v1/models` |

## 验证配置

保存配置后，重启 OpenCode，输入 `/models`，搜索 **LimAPI**，选择需要使用的模型即可开始对话。模型正常返回响应即配置成功。

## 常见问题

### 报错 401 / Incorrect API key provided

* 确认 `apiKey` 为 Portal 创建的 `sk-` 开头密钥，复制完整无空格；
* 确认 API Key 在 Portal 的「API Keys」页面状态正常、未欠费。

### /models 中找不到 LimAPI 提供商

`opencode.json` 必须为合法 JSON，可用 `cat ~/.config/opencode/opencode.json | python3 -m json.tool` 校验；修改配置后需重启 OpenCode 生效。
