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

# OpenCode

> 通过自定义 OpenAI 兼容 provider 将 OpenCode 接到 PipeLLM

路由规则请参考 [路由与协议](/zh/guides/routing-protocols)。模型 ID 请参考
[列出模型](/zh/api-reference/list-models)。

OpenCode 支持通过 `opencode.json` 配置自定义 provider。接 PipeLLM 时，最稳的
方式是走 PipeLLM 的 OpenAI converter 路由，这样一个 provider 配置就能访问
Claude、GPT、Gemini 模型。

## 推荐路由

```text theme={"dark"}
https://api.pipellm.ai/openai/v1
```

只有当你明确只需要 OpenAI 兼容原生路由、并且不需要跨协议访问时，才建议用
`https://api.pipellm.ai/v1`。

## 配置位置

OpenCode 会从以下位置读取配置：

* `~/.config/opencode/opencode.json` 作为全局用户配置
* 项目根目录的 `opencode.json` 作为项目级配置

## 快速配置

1. 先导出 PipeLLM API Key：

```bash theme={"dark"}
export PIPELLM_API_KEY="your-pipellm-api-key"
```

2. 在 `opencode.json` 里加入自定义 provider：

```json theme={"dark"}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "pipellm": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "PipeLLM",
      "options": {
        "baseURL": "https://api.pipellm.ai/openai/v1",
        "apiKey": "{env:PIPELLM_API_KEY}"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6"
        },
        "gpt-5": {
          "name": "GPT-5"
        },
        "gemini-3-flash-preview": {
          "name": "Gemini 3 Flash"
        }
      }
    }
  },
  "model": "pipellm/claude-sonnet-4-6"
}
```

3. 启动 OpenCode：

```bash theme={"dark"}
opencode
```

## 说明

* OpenCode 的自定义 provider id 可以任意命名，`pipellm` 只是示例。
* 只要目标是 Chat Completions 风格端点，就应该用
  `@ai-sdk/openai-compatible`。
* 如果某个工作流明确依赖 OpenAI Responses API，那是另一条接法，不应该复用这
  套 Chat Completions 配置。

## 相关文档

<Columns cols={3}>
  <Card title="开发工具" icon="terminal" href="/zh/integrations/overview">
    查看当前支持的编码助手
  </Card>

  <Card title="OpenAI 转换器" icon="shuffle" href="/zh/converter/openai-format">
    保留 OpenAI 兼容格式，跨 provider 调用模型
  </Card>

  <Card title="OpenCode Providers 文档" icon="book" href="https://opencode.ai/docs/providers">
    官方 OpenCode 自定义 provider 示例
  </Card>
</Columns>


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