OpenCode
During software development, developers often struggle with slow coding and complex debugging. OpenCode is an AI programming tool that helps developers write and debug code efficiently using large models. However, quickly adding these advanced AI capabilities to existing development environments has become a new challenge. You can easily connect MaaS model APIs to OpenCode using simple settings to quickly integrate API capabilities and improve your development speed. This document aims to help developers efficiently and securely integrate MaaS model APIs into the OpenCode environment.
Prerequisites
- You have registered a Huawei Cloud account. For details, see Signing Up for a Huawei Cloud Account.
- You have subscribed to built-in services or created an endpoint. For details, see Subscribing to Built-in Services and Creating an Endpoint.
Billing
When using the MaaS service, you are charged based on the number of tokens used. For details, see MaaS Text Generation Models.
Constraints
This function is only supported in the CN-Hong Kong region.
Step 1: Install OpenCode
- Install Node.js 18 or later.
node -v # Run this command to verify the Node.js version.
- Open the command-line interface and run the following command to install OpenCode:
npm install -g opencode-ai
- Verify the installation. If the version number is returned, the installation is successful. If the installation fails, check whether the Node.js version is 18 or later. You can run the node -v command to check the current version.
opencode -v
Step 2: Access MaaS Model APIs in OpenCode
- Go to the OpenCode configuration file path (Windows: C:\Users\your-username\.config\opencode\) and edit the opencode.json file. This section uses the GLM-5.2 model as an example. For details, see Table 1.
Table 1 Parameter description Parameter
Description
Example
name
Custom model name
MaaS
baseURL
https://api-ap-southeast-1.modelarts-maas.com/openai/v1 or https://api-ap-southeast-1.modelarts-maas.com/v2
https://api-ap-southeast-1.modelarts-maas.com/openai/v1
apiKey
*****SOYrkryjO-Jcd-X0-YQIA_oALlv*****-xVhElZgwtV3-3aXiuiac6bW********
models
For details about the supported models and their parameter values, see Supported Models.
glm-5.2
- <API_KEY>: Replace it with your own API key.
{ "$schema": "https://opencode.ai/config.json", "provider": { "myprovider": { "npm": "@ai-sdk/openai-compatible", "name": "MaaS", "options": { "baseURL": "https://api-ap-southeast-1.modelarts-maas.com/openai/v1", "apiKey": "<API_KEY>" }, "models": { "glm-5.2": { "name": "glm-5.2" } } } } }
- <API_KEY>: Replace it with your own API key.
- Run the following commands on the terminal to enable OpenCode:
opencode
- Enter /models, select the configured GLM-5.2 model, and use it in OpenCode.

- Start a dialogue.
FAQs
- How do I enable deep thinking in OpenCode?
- Edit the OpenCode configuration file ~/.config/opencode/opencode.json by adding the following option to the models parameter values: {"thinking": {"type": "enabled"}}.
{ "$schema": "https://opencode.ai/config.json", "provider": { "myprovider": { "npm": "@ai-sdk/openai-compatible", "name": "MaaS", "options": { "baseURL": "https://api-ap-southeast-1.modelarts-maas.com/openai/v1", "apiKey": "<API_KEY>" }, "models": { "glm-5.2": { "name": "glm-5.2", "options": { "thinking": { "type": "enabled" } } } } } } } - After the configuration is complete, run the opencode command to restart the system. If thinking is still not displayed during the conversation, press Ctrl+P in the text box, search for think, and select Show thinking to view the thinking process.

- Edit the OpenCode configuration file ~/.config/opencode/opencode.json by adding the following option to the models parameter values: {"thinking": {"type": "enabled"}}.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot
