Skip to content

Connect to Qwen (Alibaba Cloud)

Estimated time: 5-10 minutes

Qwen is Alibaba Cloud's large language model, providing API services through the Bailian platform (DashScope). It features comprehensive capabilities, a complete ecosystem, and a rich variety of models.

If you haven't read "What is an API Key", we recommend going back to 1.4 Overview to understand the concepts first.


What You'll Learn

  • Get an Alibaba Cloud Bailian API Key
  • Connect Qwen to OpenCode
  • Choose the right model for your scenario
  • Send your first message and receive a response

🎒 Prerequisites

  • [ ] Completed 1.2 Installation, able to run opencode
  • [ ] Have an Alibaba Cloud account (or can register)

Follow Along

Step 1: Register for Alibaba Cloud Account

Visit: https://bailian.console.alibabacloud.com

If you don't have an Alibaba Cloud account, follow the prompts to register and complete identity verification.


Step 2: Enable Bailian Service

  1. Enter the Bailian console
  2. Follow the prompts to enable DashScope service
  3. Accept the service agreement

Step 3: Get Your API Key

  1. Go to the API-KEY management page
  2. Create a new API Key
  3. Copy and save it immediately

Only shown once!

The API Key will only be displayed once. You won't see the complete Key after closing the window.

Please copy it to a secure location immediately. Don't share it in chats, don't screenshot it, and don't commit it to GitHub.


Step 4: Connect Qwen to OpenCode

Start OpenCode:

bash
opencode

Enter:

/connect

In the provider list, search for and select:

  • International users: Select Alibaba or search for alibaba

Then paste your API Key.

On success, you'll see:

✓ Provider added successfully!

International vs China Version

The two versions use different API endpoints:

  • China version (alibaba-cn): dashscope.aliyuncs.com
  • International version (alibaba): dashscope-intl.aliyuncs.com

If you're outside mainland China, using the wrong version may cause connection timeouts or failures.


Step 5: Select Model and Verify

Enter:

/models

Choose the appropriate model based on your use case:

ScenarioRecommended ModelDescription
Coding & Developmentqwen3-coder-flash1M context, 65K output, code-specialized
General Chatqwen-plus, qwen-turboCost-effective, supports reasoning
Deep Reasoningqwq-plusSupports reasoning, ideal for complex problems
Visual Understandingqwen-vl-maxSupports image input

After selecting a model, send a test message:

Hello, please introduce yourself

If you receive a response, the connection is successful.


Using Environment Variables (Optional)

Besides configuring via the /connect command, you can also use environment variables:

bash
# Method 1: Set at startup
DASHSCOPE_API_KEY=sk-xxx opencode

# Method 2: Add to shell config file
echo 'export DASHSCOPE_API_KEY=sk-xxx' >> ~/.bashrc
source ~/.bashrc

Custom Configuration File (Advanced)

If you need to customize the baseURL or add additional models, you can configure them in opencode.json:

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "alibaba": {
      "options": {
        "baseURL": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
      }
    }
  }
}

Checklist ✅

  • [ ] Can see Qwen models in /models
  • [ ] Can receive AI responses when sending messages
  • [ ] No errors (like API key invalid / connection error)

Common Issues

IssueCauseSolution
API key invalidKey copied incorrectly or service not enabledConfirm Bailian service is enabled, get a new Key
Can't find Alibaba optionOpenCode version too oldUpgrade OpenCode: opencode upgrade
Insufficient balanceFree quota exhaustedTop up in console
Identity verification requiredAlibaba Cloud requires verificationComplete identity verification and retry
Connection timeoutWrong version selectedInternational users should select alibaba
Some models don't support tool_callNot all models support tool callsUse qwen-plus or qwen3-coder-flash

Next Steps