Updated on 2026-10-16 GMT+08:00

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

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

  1. Install Node.js 18 or later.
    node -v # Run this command to verify the Node.js version.
  2. Open the command-line interface and run the following command to install OpenCode:
    npm install -g opencode-ai
  3. 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

  1. 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

    Obtain an API key.

    *****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"
              }
            }
          }
        }
      }
  2. Run the following commands on the terminal to enable OpenCode:
    opencode
  3. Enter /models, select the configured GLM-5.2 model, and use it in OpenCode.

  4. Start a dialogue.

FAQs

  • How do I enable deep thinking in OpenCode?
    1. 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"
                        }
                   }
              }
            }
          }
        }
      }
    2. 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.