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

# OpenCode

> OpenCode 整合指南：透過 MixRoute 使用多模型程式設計助手

<link rel="alternate" hrefLang="en" href="https://mixroute.ai/docs/integrations/open-code" />

<link rel="alternate" hrefLang="zh-Hans" href="https://mixroute.ai/docs/zh-hans/integrations/open-code" />

<link rel="alternate" hrefLang="zh-Hant" href="https://mixroute.ai/docs/zh-hant/integrations/open-code" />

<link rel="alternate" hrefLang="ja" href="https://mixroute.ai/docs/ja/integrations/open-code" />

<link rel="alternate" hrefLang="x-default" href="https://mixroute.ai/docs/integrations/open-code" />

## 一、產品簡介

OpenCode 是一款開源 AI 程式設計助手，支援 75+ 模型與本地部署。透過 **MixRoute**，可在 OpenCode 中統一使用各類主流與最新模型（如 GPT、Claude、Gemini 等），並支援自訂提供商與模型配置。

**下載地址**：[https://opencode.ai/](https://opencode.ai/)

## 二、快速配置（MixRoute）

### 1. 取得 API 金鑰

在 [MixRoute 控制台](https://api.mixroute.ai/) 建立並複製 API 金鑰。

### 2. 在 OpenCode 中配置自訂提供商

<Steps>
  <Step title="開啟設定">
    開啟 OpenCode，進入 **伺服器 / 提供商** 設定

    <img src="https://mintcdn.com/personal-a5418d9f/ZfLuoc0MUZgivF8J/images/oc-en-1.png?fit=max&auto=format&n=ZfLuoc0MUZgivF8J&q=85&s=8e9833d8bc51e730ebcabfca38966fa8" alt="Oc En 1" width="3120" height="2008" data-path="images/oc-en-1.png" />
  </Step>

  <Step title="新增提供商">
    新增 **自訂提供商**（Configure an OpenAI compatible provider）

    <img src="https://mintcdn.com/personal-a5418d9f/ZfLuoc0MUZgivF8J/images/oc-en-2-1.png?fit=max&auto=format&n=ZfLuoc0MUZgivF8J&q=85&s=0ed94955cce342d66c517f838e5f6965" alt="Oc En 2 1" width="2216" height="1357" data-path="images/oc-en-2-1.png" />
  </Step>

  <Step title="填寫配置">
    <AccordionGroup>
      <Accordion title="智能路由節點接入">
        <Tip>
          [Smart Routing](https://console.mixroute.ai/smart-route) 是一項智能模型路由能力，能夠根據輸入任務的複雜程度，自動將請求分配至最合適的模型，最終起到降低API開銷增強效率的目的。

          約束和使用指南見[此處](/docs/zh-hant/smart-routing)。
        </Tip>

        * **提供商 ID**：如 `mixroute-route`（小寫、數字、連字符或底線）
        * **顯示名稱**：如 `Mixroute Api Route`
        * **基礎 URL**：`https://api.mixroute.ai/v1`（必須以 `/v1` 結尾）
        * **API 金鑰**：貼上 Mixroute Api 智能路由節點金鑰

        <Info>
          請注意智能路由節點的金鑰是相對獨立，不與傳統API金鑰共用
        </Info>
      </Accordion>

      <Accordion title="傳統方式接入">
        * **提供商 ID**：如 `mixroute`（小寫、數字、連字符或底線）
        * **顯示名稱**：如 `MixRoute API`
        * **基礎 URL**：`https://api.mixroute.ai/v1`（必須以 `/v1` 結尾）
        * **API 金鑰**：貼上 Mixroute Api 金鑰
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="新增模型">
    在 **模型** 中新增需要使用的模型（如 `gpt-5.5`、`claude-opus-4-8` 等）

    <img src="https://mintcdn.com/personal-a5418d9f/ZfLuoc0MUZgivF8J/images/oc-en-4.png?fit=max&auto=format&n=ZfLuoc0MUZgivF8J&q=85&s=ffd5756dc65b4110be1c2157286feadb" alt="Oc En 4" width="1440" height="1159" data-path="images/oc-en-4.png" />
  </Step>

  <Step title="儲存使用">
    儲存後，在模型選擇中使用 **提供商ID/模型ID**（如 `mixroute/gpt-5.5`）
  </Step>
</Steps>

### 3. 切換模型

在對話或設定中選擇已配置的提供商與模型（如 `mixroute/gpt-5.5`）即可切換。

<Tip>
  * 若使用自建或備用服務，將 **基礎 URL** 改為對應位址，例如 `http://your-server:3003/v1`。
  * 預設模型可在專案或全域 `opencode.json` 中設定 `"model": "mixroute/模型ID"`。
</Tip>

## 三、部分模型需使用 Responses API（重要）

部分模型的存取介面與常規 Chat Completions 不同，需使用 **Responses API**。若在 OpenCode 中選用這類模型時出現類似錯誤：

> The chatCompletion operation does not work with the specified model

說明當前請求走了 **Chat Completions**，而該模型在伺服端只開放 **Responses API**，需透過配置改為使用正確介面。

### 配置方式

對需要走 Responses API 的模型增加：

```jsonc theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "disabled_providers": [],
  "provider": {
    "mixroute": {
      "name": "mixroute",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.mixroute.ai/v1"
      },
      "models": {
        "gemini-3.8-flash": {
          "name": "gemini-3.8-flash"
        }
      }
    },
    "mixroute-responses": {
      "name": "mixroute-responses",
      "npm": "@ai-sdk/openai",
      "options": {
        "baseURL": "https://api.mixroute.ai/v1",
        "apiKey": "mixroute-key"
      },
      "models": {
        "gpt-5.6-luna": {
          "name": "gpt-5.6-luna"
        },
        "gpt-5.6-terra": {
          "name": "gpt-5.6-terra"
        },
        "gpt-5.6-sol": {
          "name": "gpt-5.6-sol"
        }
      }
    }
  }
}
```

## 四、設定成功示例

下圖為使用 MixRoute API 在 OpenCode 中正常對話的示例：

<img src="https://mintcdn.com/personal-a5418d9f/ZfLuoc0MUZgivF8J/images/oc-en-6-1.png?fit=max&auto=format&n=ZfLuoc0MUZgivF8J&q=85&s=4defc77f3379febc15f7ba9f794cb662" alt="Oc En 6 1" width="1806" height="1857" data-path="images/oc-en-6-1.png" />


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