Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode API Settings

OpenCode API Settings

Through OpenCode, you can connect to any LLM (large language model) provider, such as OpenAI, Claude, DeepSeek, Alibaba Cloud Model Studio (Bailian), and others, thereby gaining stronger AI programming capabilities.

If you are using it for the first time, it is recommended to prioritize OpenCode Zen, which is a set of models officially curated by OpenCode, having been tested and optimized, ready to use out of the box and suitable for beginners.

OpenCode Zen It also includes a large number of free large models, so you can basically use it directly without paying.


Step 1: Start configuration

Run directly:

opencode

If it appears EACCES: permission denied, open '' it is a permission issue; please run with administrator privileges, for example:

sudo opencode

You will see the terminal interface (TUI):

Enter in the OpenCode terminal interface:

/connect

Note: using /connect command to add a provider's API key, the credentials will be stored in ~/.local/share/opencode/auth.json it.

Then select:opencode

If you have keys for other large models, you can also select and configure them from this list.

Step 2: Get API Key

Open the following page and log in: https://opencode.ai/auth

Step 3: Paste API Key

Return to the terminal and paste the obtained API Key:

Once done, you can start using OpenCode.

We can press Ecs to exit configuring the LLM provider, then enter the /model command in the conversation window to view supported models:

Models labeled "Free" are the free ones:

After selection, press Ecs to exit configuration, and you can see the currently used large model:

Domestic Coding Plan packages

There are many LLM vendors on the market today; overseas ones include Anthropic, Open AI, Grok, Gemini, etc., but accessing them is inconvenient now; domestic ones include DeepSeek, Qwen, ZLM, Minimax, etc.

When we use Claude Code to write code, the most expensive part is the token; overseas access is inconvenient and costly, while domestic ones now offer monthly plans, so for long-term use a monthly plan is more cost-effective.


Connect to Alibaba Cloud Model Studio (Bailian)

OpenCode is an open-source AI programming tool that can work with the model inference services provided by Alibaba Cloud Model Studio (Bailian) for efficient code development.

We can first use an Alibaba Cloud main account to access the Bailian model service platform https://bailian.console.aliyun.com/, then click Log in in the upper right corner. After logging in, click the gear ⚙️ icon in the upper right corner, select API key, and copy the API key. If you do not have one, you can create one:

You can directly purchase a resource package, which is more cost-effective:https://cn.aliyun.com/benefit?from_alibabacloud=&userCode=i5mn5r7m

Configure in OpenCode

Enter /connect in the input box and click Enter.

In the **Connect a Provider ** list search box, enter alibaba search, select Alibaba (China) and press Enter.

Enter the API Key we applied for and press Enter:

Then we can enter /model to view the models supported by Alibaba and select the ones needed:

This document applies only to the pay-as-you-go mode; Coding Plan users should use a dedicated Base URL and API Key to connect; for details, please refer to the OpenCode Coding Plan documentation for configuration.


Domestic API configuration

API application addresses of domestic vendors:

Vendor/Brand Introduction API application entry (click to access)
DeepSeek (domestic, cost-effective) Official models:
 deepseek-v4-flash       
 deepseek-v4-pro       
 deepseek-chat (将于 2026/07/24 弃用)       
 deepseek-reasoner (将于 2026/07/24 弃用) | [https://platform.deepseek.com/api_keys](https://platform.deepseek.com/api_keys) |

| Volcano Engine Coding Plan | Supports free switching among the latest models Doubao-Seed-2.0-pro/lite/Code, Doubao-Seed-Code, MiniMax-M2.5, Kimi-K2.5, GLM-4.7, Deepseek-V3.2, or scheduling via Auto mode. | https://www.volcengine.com/activity/codingplan | | Alibaba Cloud Model Studio (Bailian, Tongyi Qianwen) | Unified entry for Alibaba Cloud large models, supporting the latest versions such as Qianwen, GLM, Kimi, MiniMax | https://bailian.console.aliyun.com | | GLM (Zhipu Qingyan) | The Tsinghua-affiliated ChatGLM series, supporting GLM-4, GLM-3-Turbo, etc. | https://open.bigmodel.cn | | MiniMax | Domestic multimodal model, supporting mixed calls of text, voice, and images | https://platform.minimaxi.com |

After entering the corresponding console, register/log in → complete real-name authentication → create an API Key to start calling.

API management tools

With many platforms, configuration becomes troublesome; we can use the third-party tool CC Switch to easily manage the API configurations of these popular tools:https://github.com/farion1231/cc-switch/, fully supported on Windows / macOS / Linux.

CC Switch is an all-around auxiliary tool for Claude Code / Codex / Gemini CLI.

CC Switch can help us easily manage the API configurations of these popular tools, like giving your developer toolbox a smart organizing assistant in which all tool configurations are managed in an orderly way.

Download addresses for installation packages on each platform:https://github.com/farion1231/cc-switch/releases。

Here we select the OpenCode icon, then click the add button in the upper right corner:

There are many providers by default; here I choose DeepSeek for demonstration:

Set the API key you obtained:

Set the model deepseek-v4-pro:

After setting up, we can test in the terminal:


sudo opencode run 解释一下 JavaScript 中闭包的原理

For more specific operation settings, refer to the article:https://www.runoob.com/ai-agent/cc-switch.html