> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jiji.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode

> 在开源终端编程助手 OpenCode 中配置吉吉API。

[OpenCode](https://opencode.ai) 是开源的终端 AI 编程助手，支持接入多家模型服务。

## 安装

<CodeGroup>
  ```bash 安装脚本 theme={null}
  curl -fsSL https://opencode.ai/install | bash
  ```

  ```bash npm theme={null}
  npm i -g opencode-ai --registry=https://registry.npmmirror.com
  ```

  ```bash Homebrew theme={null}
  brew install sst/tap/opencode
  ```
</CodeGroup>

npm 方式需要先准备 [Node.js 环境](/environment/setup)。

## 配置

编辑全局配置文件 `~/.config/opencode/opencode.json`，文件不存在时新建：

```json opencode.json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "jiji": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "吉吉API",
      "options": {
        "baseURL": "https://www.jiji.cc/v1",
        "apiKey": "{env:JIJI_API_KEY}"
      },
      "models": {
        "gpt-6.1-sol": { "name": "GPT 6.1 Sol" }
      }
    },
    "anthropic": {
      "options": {
        "baseURL": "https://www.jiji.cc/v1",
        "apiKey": "{env:JIJI_API_KEY}"
      }
    }
  }
}
```

| 配置项 | 说明 |
| - | - |
| `jiji` | 自定义服务商，用 OpenAI 兼容格式调用 GPT 等模型。`models` 中列出要使用的模型 ID |
| `anthropic` | 覆盖内置 Anthropic 服务商的请求地址，用于调用 Claude 模型 |
| `{env:JIJI_API_KEY}` | 从环境变量读取 Key |

然后在终端设置环境变量：

<CodeGroup>
  ```bash macOS/Linux theme={null}
  echo 'export JIJI_API_KEY="your-api-key-here"' >> ~/.zshrc
  source ~/.zshrc
  ```

  ```powershell Windows theme={null}
  setx JIJI_API_KEY "your-api-key-here"
  ```
</CodeGroup>

<Note>
  OpenCode 内置的 Anthropic 服务商使用 Vercel AI SDK，请求地址需要带 `/v1`。这与 Claude Code 的写法不同。
</Note>

## 验证

```bash theme={null}
opencode
```

进入界面后输入 `/models`，选择吉吉API 下的模型，发送消息能正常回复即配置完成。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.