在 OpenClaw 中整合 GitHub Copilot:兩種設定方式教學
身為開發者,我們經常在處理 API 金鑰與各種模型供應商的驗證設定上耗費大量時間,尤其是當你想在專案中快速切換模型時,繁瑣的配置流程往往會打斷開發節奏。如果你正在尋找更高效的解決方案,那麼將現有的開發工具整合起來絕對是提升生產力的關鍵。
OpenClaw 整合了 GitHub Copilot 作為強大的 AI 模型供應商,讓你能直接利用現有的 GitHub 訂閱來存取頂尖的 AI 模型,無需額外申請 API 金鑰。
在 OpenClaw 中使用 Copilot 的兩種方式
Section titled “在 OpenClaw 中使用 Copilot 的兩種方式”你可以根據開發習慣選擇最適合的方式來串接 Copilot,無論是透過內建的驗證流程,還是使用現有的 VS Code 代理,都能輕鬆完成設定。
內建供應商 (github-copilot)
Section titled “內建供應商 (github-copilot)”這是最推薦的預設方式,透過原生的裝置登入流程取得 GitHub 權杖,並在 OpenClaw 執行時自動交換為 Copilot API 權杖,完全不需要安裝 VS Code。
-
執行登入指令:
Terminal window openclaw models auth login-github-copilot系統會提示你前往指定的 URL 並輸入一次性代碼,請保持終端機視窗開啟直到流程完成。
-
設定預設模型:
Terminal window openclaw models set github-copilot/claude-opus-4.6或者在設定檔中指定:
{agents: {defaults: { model: { primary: "github-copilot/claude-opus-4.6" } },},}
Copilot Proxy 外掛 (copilot-proxy)
Section titled “Copilot Proxy 外掛 (copilot-proxy)”如果你已經在 VS Code 中執行 Copilot Proxy,或者有特殊的路由需求,可以使用此方式作為本地橋接。OpenClaw 會直接與該代理的 /v1 端點溝通,並使用你在該處設定的模型列表。
注意:選擇此方式時,你必須啟用該外掛並確保 VS Code 擴充功能持續執行。
選用旗標 (Optional flags)
Section titled “選用旗標 (Optional flags)”在執行指令時,你可以搭配這些旗標來簡化操作流程,例如跳過確認步驟或直接設定預設模型。
| Flag | Description |
|---|---|
--yes | Skip the confirmation prompt |
--set-default | Also apply the provider’s recommended default model |
# Skip confirmationopenclaw models auth login-github-copilot --yes
# Login and set the default model in one stepopenclaw models auth login --provider github-copilot --method device --set-default- 互動式 TTY 需求:裝置登入流程需要互動式 TTY,請直接在終端機執行,不要在非互動式的腳本或 CI 流程中使用。
- 模型可用性取決於你的方案:Copilot 的模型存取權限取決於你的 GitHub 方案。若模型被拒絕,請嘗試其他 ID(例如
github-copilot/gpt-4.1)。 - 傳輸選擇:Claude 模型 ID 會自動使用 Anthropic Messages 傳輸,而 GPT、o-series 與 Gemini 模型則維持使用 OpenAI Responses 傳輸。OpenClaw 會根據模型參考自動選擇正確的傳輸方式。
- 環境變數解析順序:OpenClaw 解析 Copilot 驗證的優先順序如下:
| Priority | Variable | Notes |
|---|---|---|
| 1 | COPILOT_GITHUB_TOKEN | Highest priority, Copilot-specific |
| 2 | GH_TOKEN | GitHub CLI token (fallback) |
| 3 | GITHUB_TOKEN | Standard GitHub token (lowest) |
當設定多個變數時,OpenClaw 會使用最高優先級的那個。裝置登入流程 (openclaw models auth login-github-copilot) 會將權杖儲存在驗證設定檔中,其優先級高於所有環境變數。
- 權杖儲存:登入後會將 GitHub 權杖儲存在驗證設定檔中,並在 OpenClaw 執行時自動交換為 Copilot API 權杖,你無需手動管理。
警告:此操作需要互動式 TTY。請直接在終端機中執行登入指令,不要在無頭腳本 (headless script) 或 CI 工作中執行。
記憶體搜尋嵌入 (Memory search embeddings)
Section titled “記憶體搜尋嵌入 (Memory search embeddings)”GitHub Copilot 同時也能作為 memory search 的嵌入供應商。只要你有 Copilot 訂閱並已完成登入,OpenClaw 就能直接使用它進行嵌入運算,無需額外的 API 金鑰。
當 memorySearch.provider 設定為 "auto"(預設值)時,GitHub Copilot 會以優先級 15 進行嘗試——這是在本地嵌入之後,但在 OpenAI 與其他付費供應商之前。若 GitHub 權杖有效,OpenClaw 會自動從 Copilot API 發現可用的嵌入模型並選擇最佳者。
{ agents: { defaults: { memorySearch: { provider: "github-copilot", // Optional: override the auto-discovered model model: "text-embedding-3-small", }, }, },}- OpenClaw 解析你的 GitHub 權杖(來自環境變數或驗證設定檔)。
- 交換為短效的 Copilot API 權杖。
- 查詢 Copilot
/models端點以發現可用的嵌入模型。 - 選擇最佳模型(優先選擇
text-embedding-3-small)。 - 發送嵌入請求至 Copilot
/embeddings端點。
模型可用性取決於你的 GitHub 方案。若沒有可用的嵌入模型,OpenClaw 會跳過 Copilot 並嘗試下一個供應商。
如果你在設定過程中遇到任何問題,歡迎隨時使用 AI Setup Assistant 進行諮詢。
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。