搜尋文件...

開始輸入以搜尋文件

opencode
OpenCode

OpenCode 設定指南

把 UnoRouter 加為 OpenCode 的自訂供應商,並挑選任一模型作為使用中的代理程式。

概覽

OpenCode 會從 JSON 設定讀取供應商。用 OpenAI 相容轉接器加入 UnoRouter,就能使用任何 UnoRouter 模型。

快速設定

把這些貼進用戶端。已登入時會自動填入你的金鑰。

text
基礎 URL: https://api.unorouter.com/v1
API 金鑰: YOUR_API_KEY

登入以自動填入 API 金鑰

相容性

Chat Completions串流工具呼叫

逐步設定

  1. 1
    開啟 OpenCode 設定檔

    用文字編輯器開啟 OpenCode 設定檔。若檔案不存在,請自行建立。

    powershell
    $f = "$env:USERPROFILE\.config\opencode\opencode.json"
    md -Force (Split-Path $f) | Out-Null; New-Item $f -ea 0 | Out-Null; Invoke-Item $f

    登入以自動填入 API 金鑰

  2. 2
    取代檔案內容

    將 UnoRouter 的 provider 設定區塊加入你的設定。請與現有檔案合併,保留你已有的 mcp 或 agent 區塊。

    json
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "unorouter-live": {
          "name": "UnoRouter",
          "npm": "@ai-sdk/openai-compatible",
          "options": {
            "apiKey": "YOUR_API_KEY",
            "baseURL": "https://api.unorouter.com/v1"
          },
          "models": {
            "ling-3.1-flash:free": {},
            "agnes-3.0-flash:free": {},
            "minicpm5-2b:free": {},
            "k2-horizon:free": {},
            "qwen3.8-flash-next:free": {}
          }
        }
      }
    }

    登入以自動填入 API 金鑰

  3. 3
    確認模型已載入

    儲存檔案後,在終端機執行 opencode models。你列出的每個 id 都應該出現,並以你的 provider 鍵作為前綴。

  4. 4
    選擇模型

    開啟模型選擇器並切換到新模型。轉接器會處理串流與工具呼叫。

推薦模型

在這裡可用的免費模型。把任意模型 id 貼進用戶端即可。

ling-3.1-flash:freeagnes-3.0-flash:freeminicpm5-2b:freek2-horizon:freeqwen3.8-flash-next:free

注意事項

  • OpenCode 對相容 OpenAI 的 provider 並沒有即時模型探索功能。你想使用的每個模型,都必須以正確的 id 寫入 "models" 區塊。
  • 不要把 provider 鍵直接命名為 "unorouter"。該 id 已存在於 models.dev 註冊表,OpenCode 會改用註冊表的清單而非你的清單,導致較新的模型不見。上面的 "-live" 後綴可以避開衝突。
  • 請使用 UnoRouter 目錄中正確的模型 id。移除複製貼上時附帶的 provider 前綴,若 id 帶有 :free 後綴則保留。
  • 自訂 provider 鍵若缺少 "models" 區塊,載入的模型數會是零,該 provider 會完全從選擇器中消失。
產生 API 金鑰模型