1. IDEs and AI Programming Assistants
TreeRouter
  • 价格-充值-分组-模型价格介绍
    TREEROUTER
  • 站点操作指南-快速上手调用大模型API
    TREEROUTER
  • 中文文档
    • FAQ常见问题
      • 问题自查方法
      • 入门必看
        • 如何在 TreeRouter 充值?
        • 可以使用哪些大模型 API ?
        • 如何获取 OpenAI Key ? 如何获取 Claude Key ? 如何获取 Gemini Key ?等等
        • 我注册并且充值了,key 在哪?
        • 怎么更换模型使用?
        • 配置模型的时候 URL 用哪个?
        • 接口在中国大陆能使用吗?
        • 按量计费还是按月支付?
        • 怎么检查一次调用消耗了多少 Token?
        • 请问我余额为负了怎么回事?
      • 常见误区
        • 明明余额还有很多,为什么显示令牌无法使用?
        • Key 为什么不能用?为什么我调用 API 没反应?
        • 新建令牌参数怎么填?
        • 为什么调用接口返回“无效的令牌”?
        • API 接口返回报错,报错代码 400 401 403 404 405 413 429 500 503 504 524 是什么意思?
    • 软件/插件 配置treerouter教程
      • IDE 与 AI 编程助手 (IDE & Coding Assistants)
        • Cursor 配置指南
        • VS Code 配置指南
        • Gemini CLI 配置指南
        • Trae 配置指南(插件配置)
        • OpenCode 桌面端 配置指南
        • OpenCode CLI 配置指南 (CC Switch)
        • MiMoCode CLI 安装与配置 TreeRouter
        • ChatGPT(Codex) CLI 安装与配置 TreeRouter
        • ChatGPT(Codex) 桌面端 安装与配置 TreeRouter
        • Claude Code 桌面端 安装与配置 TreeRouter
        • Claude Code CLI 安装与配置 TreeRouter (CC Switch)
        • Claude Code CLI 安装与配置 TreeRouter (Win/Mac)
      • 桌面级 AI 客户端 (Desktop Clients)
        • ChatBox 接入指南
        • Cherry Studio 接入指南
        • WorkBuddy 接入指南
      • 工作流与自动化工具 (Workflows & Automation)
        • CC Switch 安装与配置教程
        • CC Switch 导入 TreeRouter 令牌(API-KEY)
        • Claude Code + CC Switch 配置 DeepSeek / GLM 模型通用指南
        • n8n配置使用treerouter教程
        • Dify 配置使用 treerouter教程
        • Coze 配置使用 treerouter 教程
      • 开源项目与高级部署 (Open Source & Infrastructure)
        • 腾讯云OpenClaw接入treerouter教程
        • OpenClaw 接入 API 教程
        • OpenClaw Web 界面配置 API
        • OpenClaw 在云服务器Linux环境下通过终端配置TreeRouter
        • Hermes Agent Linux安装接入 treerouter 教程
        • Hermes Agent CLI 安装与配置 TreeRouter(CC Switch)
        • Pi Coding Agent 配置 treerouter 教程
    • 模型接口
      • Openai
        • 文本生成
        • 文本生成---上下文阅读
        • 图片理解
        • 图片生成(gpt-image-2)
        • 图片生成(gpt-image-1)
        • 图片编辑/edits
        • 图片编辑 / 网页版
        • 函数调用 tools
        • v1/Responses / 通用
        • 创建文本嵌入
        • 批量创建嵌入
        • 文本转语音 / TTS
        • 语音转文本 / whisper-1
        • 语音转文本 / gpt-4o-transcribe
        • 音频翻译
        • Audio接口 / 输出
        • Audio接口 / 输入
        • 内容补全接口
        • 创建内容审核
        • PDF文件分析
        • deep-research / 深度研究
        • Web search / 联网搜索
        • response_format
        • 图像编辑(gpt-image-2)
      • Anthropic
        • 原生接口
          • 文本生成 (思考配置)
          • 图片理解
          • 文本生成
          • 文本生成 / 强制返回思考
          • 函数调用
          • Web search / 联网搜索
        • OpenAI兼容接口
          • 文本生成
          • 图片理解
          • 文本生成 / 强制返回思考
          • 函数调用
          • Web search / 联网搜索
      • Google
        • OpenAI兼容接口(推荐)
          • 文本生成
          • 文本生成 / 强制返回思考
          • 图片理解
          • 图片生成
          • 图片修改
          • 图片生成 / Imagen 4
          • 音频理解
          • 视频理解
          • 文本转语音 / TTS
          • 图片编辑(Nano-banana)
          • 图片编辑(Nano-banana) base64格式
        • Google Gemini接口
          • 文本生成
          • 文字转语音
          • 音频转文
          • 视频转文
          • 图片理解
          • 文生图片(nanobanana pro)
          • 图片编辑(nanobanana)
          • 图片编辑(nanobanana pro)
        • 视频生成
          • 创建视频任务
          • 轮询任务状态
          • 下载 MP4
      • Midjourney
        • openai兼容/chat格式
          • MJ视频 (chat格式)
        • 原生接口
          • 文生图(Imagine)
          • 图片融合(Blend)
          • 按钮点击(Action)
          • 窗口执行(Modal)
          • 生成视频(Video)
          • 图生文(Describe)
          • 编辑图片(Edit)
          • 上传(upload)
          • 换脸(FaceSwap)
          • 缩短提示词(Shorten)
          • 查询
          • 获取种子(Seed)接口
          • 批量查询
          • 文生图 / OpenAI兼容
      • FLUX
        • /fal-ai/nano-banana 文生图
        • /fal-ai/nano-banana/edit 图片编辑
      • 文生图接口
        • flux / OpenAI兼容接口
        • flux-kontext-pro / OpenAI兼容接口
        • stable-diffusion / OpenAI兼容接口
        • ideogram / OpenAI兼容接口
        • recraftv3 / OpenAI兼容接口
        • flux携带参考图 / OpenAI兼容接口
      • Suno
        • 场景一:stems声曲分离 Vocals Instrumental
        • 生成歌曲
        • 生成歌词
        • 查询任务状态(批量)
        • 查询任务状态(单个)
      • 3D模型
        • Hunyuan3D-2
      • veo
        • 图生视频
        • 文生视频
        • 查询视频生成状态
        • 图生视频(chat格式)
      • 豆包
        • doubao-seedream-4-0-250828-文生图
        • doubao-seedream-4-0-250828-图生图
        • doubao-seedream-4-0-250828-多图生图
      • sora
        • 官方异步格式
          • 创建视频任务
          • 获取视频任务状态
          • 编辑视频(remix)
          • 获取视频内容
        • 渠道异步格式
          • 创建视频任务
          • 获取视频任务状态
          • 转存视频
          • 创建视频(带 Character)
          • 编辑视频(remix)
          • 获取视频内容
          • 创建视频任务 Copy
          • 从已生成的任务中创建角色
          • 使用故事板创建视频
        • chat格式
          • 创建绘画
        • 创建角色接口
          • 创建角色
      • FLUX
        • Flux(Dalle3 Edits(图生图&文生图))
        • Flux 创建(OpenAI dall-e-3格式)
    • 个人API接口文档
      • 获取个人token
      • 一、个人信息
        • 1. 获取个人信息
        • 2. 修改个人信息
        • 3. 注销账户
        • 4. 获取可用模型列表
        • 5. 获取用户分组
        • 6. 更新用户设置(额度预警等)
        • 7. 生成系统访问令牌
      • 二、令牌管理(API Key)
        • 1. 获取令牌列表
        • 2.搜索令牌
        • 3. 获取单个令牌
        • 4.创建令牌
        • 5.更新令牌
        • 6. 删除令牌
        • 7.批量删除令牌
        • 8.获取单个令牌(明文显示)
      • 三、日志与统计
        • 1. 查看个人使用日志
        • 2. 个人日志统计
        • 3. 令牌每日消耗
        • 4. 令牌模型消耗预览(Top 3)
        • 5. 令牌全量模型消耗
        • 6. 导出令牌每日消耗 XLSX
        • 7. 个人额度时序数据
  • English Documentation
    • IDEs and AI Programming Assistants
      • Cursor Configuration Guide
      • VS Code Configuration Guide
      • Gemini CLI Configuration Guide
      • Trae Configuration Guide (Plugin Configuration)
      • OpenCode Desktop Configuration Guide
      • OpenCode CLI Configuration Guide (CC Switch)
      • MiMoCode CLI Installation and TreeRouter Configuration
      • ChatGPT(Codex)CLI Installation and TreeRouter Configuration
      • ChatGPT(Codex)Desktop Installation and TreeRouter Configuration
      • Claude Code Desktop Installation and TreeRouter Configuration
      • Claude Code CLI Installation and TreeRouter Configuration (CC Switch)
      • Claude Code CLI Installation TreeRouter Configuration (win/mac)
    • Desktop AI client
      • treerouter Access chatbox
      • treerouter Access Cherry Studio
      • WorkBuddy Access treerouter Tutorial
    • Workflow and Automation Tools
      • cc_switch Usage Tutorial
      • Coze Configuration and Usage of treerouter Tutorial
      • Dify Configuration and Usage of treerouter Tutorial
      • n8n Configuration and Usage of treerouter Tutorial
      • Open Claw Configure API via Terminal in Cloud Server Linux Environment
      • cc+ccs Configuration deepseek|glm model
    • Open-Source Projects and Advanced Deployment
      • Tencent Cloud OpenClaw Access treerouter Tutorial
      • OpenClaw Access API Tutorial
      • OpenClaw Web Interface Configuration API
      • OpenClaw configures TreeRouter through the terminal on a Linux cloud server
      • Hermes Agent Linux Installation and Access treerouter Tutorial
      • Hermes Agent CLI: Installing and Configuring TreeRouter (CC Switch)
  • 数据模型
    • 示例数据模型
      • 未命名数据模型
      • Pet
      • Category
      • Tag
  1. IDEs and AI Programming Assistants

OpenCode CLI Configuration Guide (CC Switch)

This guide explains how to install OpenCode CLI on Windows and use the model services provided by TreeRouter through CC Switch. After completing the configuration, you can run opencode in PowerShell, CMD, or WSL and access models through TreeRouter.

1. Prerequisites#

Before you begin, make sure that:
You have a working TreeRouter account.
OpenCode CLI is installed or ready to be installed.
CC Switch is installed or ready to be installed.
Your network can access https://treerouter.com/.
The TreeRouter token group you intend to use contains models supported by OpenCode.
If you plan to install OpenCode CLI with npm, install Node.js and npm first. Run the following commands in PowerShell or CMD to check:
If both commands display version numbers, Node.js and npm are installed correctly.

2. Install OpenCode CLI#

OpenCode recommends that Windows users use WSL for a more complete terminal experience. If you already use WSL, run the following command in a WSL terminal:
To use OpenCode CLI directly in PowerShell or CMD, install it with npm:
If Scoop or Chocolatey is already installed, you can use either of the following methods instead:
scoop install opencode
choco install opencode
After installation, close the current terminal and open a new PowerShell, CMD, or WSL terminal. Run the following command to verify the installation:
If a version number appears, OpenCode CLI has been installed successfully.
Verifying the OpenCode CLI installation

3. Install CC Switch#

Follow the official TreeRouter guide to install CC Switch:
CC Switch Installation Guide
After installation, confirm that CC Switch opens normally. You will manually add an OpenCode provider configuration in CC Switch later.
Open CC Switch and confirm that an OpenCode entry appears in the application list at the top.
OpenCode entry in CC Switch

4. Create a Token for OpenCode#

Open the TreeRouter website and sign in:
https://treerouter.com/
After signing in, select Console > Token Management > Add Token.
Opening Token Management and adding a token
Enter the following information on the token creation page:
Name: Enter an easily recognizable name, such as OpenCode Token.
Token Group: Select the group you want to use with OpenCode. Make sure it contains the models you need.
Quota Settings: Set a quota based on your requirements. Leave the default settings if no quota restriction is needed.
Access Restrictions: Leave the default settings unless you have specific network access requirements.
After confirming the information, click Submit.
Creating a token for OpenCode

5. Copy the Token Key#

After the token is created, the token list will appear.
Find the token you just created. Click the Copy button next to Key in that token's row, then select Copy Key.
Important: Select Copy Key, not Copy Connection Information.
Copying the TreeRouter token key

6. Add the OpenCode Configuration to CC Switch#

Open CC Switch, select the OpenCode icon from the application list at the top, and then click the plus (+) button in the upper-right corner.
Adding an OpenCode provider in CC Switch
On the provider page, click Custom Configuration.
Selecting Custom Configuration
Complete the custom configuration form as follows:
Provider Name: Enter an easily recognizable name, such as My OpenCode.
Notes: Optional. Enter a description of how the configuration will be used.
Website URL: Enter https://treerouter.com/v1.
API Key: Paste the key copied from the TreeRouter token list.
Request URL: Enter TreeRouter's OpenAI-compatible endpoint, which is normally https://treerouter.com/v1. If a different endpoint is shown on the TreeRouter website or provided by customer support, use that endpoint instead.
Additional Options: Keep the default keys and values.
Model ID: Enter the ID of the model you want to use in OpenCode CLI. The model must be available in the selected token group.
If the page provides a Get Model List option, click it first. If the model list cannot be retrieved automatically, click Add Model and enter the model ID manually.
After adding the model, select it and click Add or Save.
Complete OpenCode custom provider configuration

7. Enable the Configuration and Test Connectivity#

After the provider is added, CC Switch returns to the OpenCode configuration list.
Find the configuration you just added, such as My OpenCode, and activate it.
After activation, click the Connectivity Test button on the right side of the configuration.
If Connection Successful appears at the top of the page, the CC Switch configuration is working.
Testing the OpenCode provider connection
Important: After activating the configuration, close all open PowerShell, CMD, and WSL terminal windows, then open a new terminal. This ensures that OpenCode CLI reads the latest configuration written by CC Switch.

8. Verify OpenCode CLI#

Open a new PowerShell, CMD, or WSL terminal and navigate to your project directory.
Run the following command to start OpenCode CLI:
If OpenCode prompts you to select a provider, sign in, or initialize the application on first launch, confirm that the OpenCode configuration in CC Switch is marked as In Use, then return to the terminal and continue.
Starting OpenCode CLI
Selecting a provider in OpenCode CLI
Selecting a model in OpenCode CLI
After selecting your model, enter a simple test prompt, for example:
Confirm in one sentence that the connection is working.
If the model responds normally, OpenCode CLI has been configured successfully to use TreeRouter through CC Switch.
Receiving a response in OpenCode CLI
If this is the first time you have used OpenCode in the current project, you can also run:
/init
This command asks OpenCode to analyze the project and create or update AGENTS.md in the project root.

9. Troubleshooting#

opencode Is Not Recognized as a Command#

OpenCode CLI may not have been installed correctly, or the global command directory used by npm, Scoop, or Chocolatey may not be included in your system's PATH environment variable.
Run the installation command again. After installation, close the terminal and open a new PowerShell, CMD, or WSL terminal.

OpenCode CLI Still Uses the Default Service#

Check the following:
The newly added My OpenCode configuration is active in CC Switch.
The OpenCode page is currently selected in CC Switch.
You reopened PowerShell, CMD, or WSL after activating the configuration.
The project directory does not contain a .env file with an old API key or base URL.
Old OPENAI_API_KEY, OPENAI_BASE_URL, or related environment variables have not been set manually on the computer.
If you previously ran opencode auth login, OpenCode may have stored credentials for an old provider. Run the following command to view the signed-in providers:
If old credentials are interfering with the current configuration, remove the old configuration from OpenCode or CC Switch before testing again.

The Connectivity Test Fails#

Check the following:
The TreeRouter token is enabled.
The selected model is available in the token group.
The configuration is active in CC Switch.
The complete API Key was copied.
The Request URL is TreeRouter's OpenAI-compatible endpoint.
The Model ID exactly matches an available model ID in TreeRouter.
Your network can access https://treerouter.com/.

OpenCode Prompts You to Sign In#

If TreeRouter is active in CC Switch but OpenCode CLI still prompts you to sign in, close all terminal windows and open a new terminal before running opencode again.
If the prompt still appears, return to CC Switch, confirm that My OpenCode is marked as In Use, and run the Connectivity Test again.

Can I Import the OpenCode Configuration from TreeRouter with One Click?#

OpenCode CLI currently requires the provider configuration to be added manually in CC Switch. Use the TreeRouter website to create the token and copy its key. Do not use the website's one-click CC Switch import process to configure OpenCode CLI.

The OpenCode Entry Is Missing from CC Switch#

Make sure that CC Switch has been updated to a recent version. If your version does not include the OpenCode entry, follow the TreeRouter CC Switch guide to update or reinstall CC Switch.
修改于 2026-07-23 01:47:24
上一页
OpenCode Desktop Configuration Guide
下一页
MiMoCode CLI Installation and TreeRouter Configuration
Built with