在 OpenCode 中使用阿里雲百鍊模型。
快速開始
- 1
連線服務商
執行
opencode,輸入/connect,按計費方案選擇服務商並輸入 API Key:Token Plan
選擇 Alibaba Token Plan (China),輸入對應版本的 Token Plan API Key:
- Token Plan 個人版:建立或查看 API Key
- Token Plan 團隊版:分配席位並取得 API Key
按量計費
選擇 Alibaba (China),輸入 百鍊 API Key。
Coding Plan
選擇 Alibaba Coding Plan (China),輸入 Coding Plan API Key。
- 2
選擇模型
輸入
/models,選擇需要的模型。 - 3
驗證
執行以下命令驗證:
opencode run "你好"
透過設定檔接入
除了上述方式,也可以透過設定檔接入。
- 1
開啟或新建設定檔
- macOS / Linux:
~/.config/opencode/opencode.json - Windows:
C:\Users\<使用者名稱>\.config\opencode\opencode.json
- macOS / Linux:
- 2
寫入設定
將
YOUR_API_KEY替換為對應方案的 API Key。Token Plan 個人版
{ "$schema": "https://opencode.ai/config.json", "provider": { "bailian-token-plan": { "npm": "@ai-sdk/anthropic", "name": "Alibaba Cloud Model Studio", "options": { "baseURL": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1", "apiKey": "YOUR_API_KEY" }, "models": { "auto": { "name": "Auto", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 393216 } }, "qwen4-max-preview": { "name": "Qwen4.0 Max Preview", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen4-max": { "name": "Qwen4 Max", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 262144 } }, "qwen3.8-max": { "name": "Qwen3.8 Max", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen3.8-flash": { "name": "Qwen3.8 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen3.7-max": { "name": "Qwen3.7 Max", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.7-plus": { "name": "Qwen3.7 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.6-flash": { "name": "Qwen3.6 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4.1-flash-1017": { "name": "DeepSeek V4.1 Flash 1017", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4-pro": { "name": "DeepSeek V4 Pro", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4-pro-0813": { "name": "DeepSeek V4 Pro 0813", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4-flash-0731": { "name": "DeepSeek V4 Flash 0731", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "glm-5.3": { "name": "GLM-5.3", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } }, "glm-5.2": { "name": "GLM-5.2", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } } } } } }Token Plan 團隊版
{ "$schema": "https://opencode.ai/config.json", "provider": { "bailian-token-plan": { "npm": "@ai-sdk/anthropic", "name": "Alibaba Cloud Model Studio", "options": { "baseURL": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1", "apiKey": "YOUR_API_KEY" }, "models": { "auto": { "name": "Auto", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 393216 } }, "qwen4-max-preview": { "name": "Qwen4.0 Max Preview", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen4-max": { "name": "Qwen4 Max", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 262144 } }, "qwen3.8-max": { "name": "Qwen3.8 Max", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen3.8-flash": { "name": "Qwen3.8 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen3.7-max": { "name": "Qwen3.7 Max", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.7-plus": { "name": "Qwen3.7 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.6-plus": { "name": "Qwen3.6 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.6-flash": { "name": "Qwen3.6 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4.1-flash-1017": { "name": "DeepSeek V4.1 Flash 1017", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4-pro": { "name": "DeepSeek V4 Pro", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4-pro-0813": { "name": "DeepSeek V4 Pro 0813", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4-flash-0731": { "name": "DeepSeek V4 Flash 0731", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "kimi-k2.7-code": { "name": "Kimi K2.7 Code", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 262144, "output": 98304 } }, "kimi-k2.6": { "name": "Kimi K2.6", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 262144, "output": 98304 } }, "kimi-k2.5": { "name": "Kimi K2.5", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 262144, "output": 98304 } }, "glm-5.3": { "name": "GLM-5.3", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } }, "glm-5.2": { "name": "GLM-5.2", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } }, "glm-5.1": { "name": "GLM-5.1", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } }, "glm-5": { "name": "GLM-5", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } }, "MiniMax-M2.5": { "name": "MiniMax M2.5", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 196608, "output": 32768 } } } } } }按量計費
將
{WorkspaceId}替換為真實的 Workspace ID。{ "$schema": "https://opencode.ai/config.json", "provider": { "bailian-payg": { "npm": "@ai-sdk/anthropic", "name": "Alibaba Cloud Model Studio", "options": { "baseURL": "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1", "apiKey": "YOUR_API_KEY" }, "models": { "qwen3.8-max": { "name": "Qwen3.8 Max", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "qwen3.7-plus": { "name": "Qwen3.7 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.8-flash": { "name": "Qwen3.8 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 131072 } }, "deepseek-v4-pro-0813": { "name": "DeepSeek V4 Pro 0813", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } } } } } }Coding Plan
{ "$schema": "https://opencode.ai/config.json", "provider": { "bailian-coding-plan": { "npm": "@ai-sdk/anthropic", "name": "Alibaba Cloud Model Studio", "options": { "baseURL": "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1", "apiKey": "YOUR_API_KEY" }, "models": { "qwen3.7-plus": { "name": "Qwen3.7 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "qwen3.6-plus": { "name": "Qwen3.6 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } }, "kimi-k2.5": { "name": "Kimi K2.5", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 262144, "output": 98304 } }, "glm-5": { "name": "GLM-5", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 202752, "output": 16384 } }, "MiniMax-M2.5": { "name": "MiniMax M2.5", "modalities": { "input": [ "text" ], "output": [ "text" ] }, "limit": { "context": 196608, "output": 32768 } }, "qwen3.5-plus": { "name": "Qwen3.5 Plus", "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "limit": { "context": 1000000, "output": 65536 } } } } } }說明使用 qwen4-max-preview 時,單次輸出上限預設為 32000,需要更長輸出可設定
OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX。說明使用 qwen4-max 時,單次輸出上限預設為 32000,需要更長輸出可設定
OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX。qwen4-max 的上下文長度為 1M Token;非思考模式最大輸出 131,072 Token,思考與最終回答合計最大 262,144 Token;預設 reasoning_effort=high,thinking_budget=131072。
錯誤碼
配置過程中遇到報錯,參考對應計費方案的常見問題文件:
- Token Plan:個人版常見問題 · 團隊版常見問題
- 按量計費:錯誤代碼
- Coding Plan:Coding Plan 常見問題
常見問題
如何按量計費接入節省計劃?
按量計費接入方式不變,使用百煉通用 API Key 和 Base URL。購買節省計劃後自動生效,呼叫費用按抵扣順序自動抵扣。詳情參見節省計劃。
模型列表中沒有需要的模型
先升級 OpenCode 到最新版本,再執行 /models 檢視。仍沒有時,可在 opencode.json 中自定義 provider 並新增模型。
呼叫時返回 401 Unauthorized
API Key 與所選服務商不匹配,或使用了其他計費方案的 Key。重新執行 /connect,選擇對應計費方案的服務商並輸入正確的 Key。