Skip to main content

Claude Code

Use Alibaba Cloud Model Studio models in Claude Code.

Quick start

Select the client you use and complete the configuration.
  • CLI
  • CC Switch
  • IDE plug-in
  • Desktop app
  1. 1

    Configure the model

    • Token Plan
    • pay-as-you-go billing method
    • Coding Plan
    Replace YOUR_API_KEY with your Token Plan API Key:
    export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
    export ANTHROPIC_BASE_URL="https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"
    export ANTHROPIC_MODEL="auto"
    export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.6-flash"
    export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.8-flash"
    export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen4-max"
    export CLAUDE_CODE_SUBAGENT_MODEL="auto"
    export CLAUDE_CODE_MAX_CONTEXT_TOKENS="983616"
    
    If long outputs are truncated, set CLAUDE_CODE_MAX_OUTPUT_TOKENS=131072. qwen4-max has a context length of 1M tokens; the maximum output in non-thinking mode is 131,072 tokens, and the combined maximum for thinking and the final answer is 262,144 tokens; the defaults are reasoning_effort=high and thinking_budget=131072.
    The above environment variables apply only to the current terminal session. To persist the configuration, use Connect via a configuration file.
  2. 2

    Verification

    Run the following command to verify:
    claude -p "你好"
    

Connect via a configuration file

In addition to the methods above, you can also connect via a configuration file.
  1. 1

    Open or create a configuration file

    • macOS / Linux: ~/.claude/settings.json
    • Windows: C:\Users\<username>\.claude\settings.json
  2. 2

    Write the configuration

    • Token Plan
    • pay-as-you-go billing method
    • Coding Plan
    Replace YOUR_API_KEY with your Token Plan API Key:
    {
        "env": {
            "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
            "ANTHROPIC_BASE_URL": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
            "ANTHROPIC_MODEL": "auto",
            "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-flash",
            "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.8-flash",
            "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen4-max",
            "CLAUDE_CODE_SUBAGENT_MODEL": "auto",
            "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "983616"
        }
    }
    
  3. 3

    Verification

    After saving, run the following command for verification:
    claude -p "你好"
    

Configure the context window size

Claude Code uses the 200K context window by default. When the model supports 1M, the context window can be extended to 1M (1,000,000 tokens). Method 1: Set via environment variables Add CLAUDE_CODE_MAX_CONTEXT_TOKENS to the env field in ~/.claude/settings.json:
{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.7-plus",
        "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000"
    }
}
Method 2: Via the model name suffix Add the [1m] suffix after the model name, applicable to Model Studio models that support a 1M context:
{
    "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_BASE_URL": "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
        "ANTHROPIC_MODEL": "qwen3.7-plus[1m]",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.7-plus[1m]",
        "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.7-plus[1m]",
        "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-plus[1m]"
    }
}
After modifying the configuration, open a new terminal window and restart Claude Code for the changes to take effect.

Permission mode configuration

Claude Code provides the following permission modes:
  • default: asks the user for confirmation for each operation.
  • acceptEdits: automatically approves file edits, while other operations still ask.
  • plan: read-only planning mode that does not perform modifications.
  • auto: a classifier determines whether an operation is allowed to execute, reducing confirmation prompts. In interactive terminals and VS Code sessions, Claude Code v2.1.283 and later uses this mode by default.
  • dontAsk: does not ask; operations that require asking are directly rejected.
  • bypassPermissions: bypasses all permission checks.
  • delegate: delegation mode.
When using auto mode with the Token Plan endpoint, the classifier check may fail to return a result. With some models, Not run · auto mode's check had no usable answer appears, causing the operation not to be executed.When you encounter this message, you can set permissions.defaultMode to default or acceptEdits, or adjust the model used by the classifier (ANTHROPIC_DEFAULT_SONNET_MODEL; Claude Code v2.1.302 and later can also set CLAUDE_CODE_AUTO_MODE_MODEL) and then restart the session.
Method 1: command line arguments Use --permission-mode to specify the default permission mode for this session:
claude --permission-mode plan
claude --permission-mode acceptEdits
Method 2: interactive command Enter /permissions in a session to manage pre-approved and pre-denied rules for tools, supporting bash, edit, and MCP tools. Method 3: settings.json configuration Configure in the permissions field of ~/.claude/settings.json:
{
    "permissions": {
        "allow": ["Bash(git:*)", "Read", "Edit"],
        "deny": ["Bash(rm:*)"],
        "defaultMode": "default"
    }
}

Connect to Model Studio CLI

  1. 1

    Install the Model Studio CLI

    请帮我全局安装阿里云百炼 CLI 命令行工具:npm install -g bailian-cli
    
  2. 2

    Configure the API Key

    Go to the Model Studio console to obtain an API Key, and then tell Claude Code:
    配置我的 API Key 是:sk-xxxxxxxxxxxxx
    
  3. 3

    Get started

    Describe your requirements directly in natural language, for example:
    帮我生成 6 张亚马逊电商主图,产品是白色无线蓝牙耳机。
    帮我生成一段 30 秒的白色无线蓝牙耳机产品演示视频。
    

Error codes

If you encounter errors during configuration, refer to the FAQ documentation for the corresponding plan:

FAQ

The pay-as-you-go billing connection method remains unchanged, using the Model Studio general API Key and Base URL. After you purchase a savings plan, it takes effect automatically, and call fees are automatically deducted in the deduction order. For details, see Savings plan.

How do I skip Anthropic official login verification?

Edit or create ~/.claude.json (Windows path: C:\Users\<username>\.claude.json), and set hasCompletedOnboarding to true to skip the Anthropic official login verification.
{
  "hasCompletedOnboarding": true
}
This error indicates that the API Key type does not match the ANTHROPIC_BASE_URL. Model Studio provides three connection methods, each using a different base_url and a dedicated API Key, and the two must be used as a matched pair:

Connection method

base_url

API Key

Token Plan

https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic

Token Plan API Key

pay-as-you-go billing method

https://dashscope-intl.aliyuncs.com/apps/anthropic

Model Studio API Key (starting with sk-)

Coding Plan

https://coding-intl.dashscope.aliyuncs.com/apps/anthropic

Coding Plan API Key

Troubleshooting steps are as follows:
  1. Check the request URL.View the value of ANTHROPIC_BASE_URL in ~/.claude/settings.json.
  2. Confirm the API Key type.Compare against the table above and confirm that the type of the API Key you use matches the base_url.
  3. Fix the configuration.When using a Model Studio pay-as-you-go API Key, set ANTHROPIC_BASE_URL to https://dashscope-intl.aliyuncs.com/apps/anthropic.
This error indicates that Claude Code is trying to connect to the official Anthropic service instead of Alibaba Cloud Model Studio. This is usually caused by environment variables that are not correctly configured or have not taken effect. Follow these steps to troubleshoot:
  1. Check the configuration.After starting Claude Code, run the /status command to confirm whether ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN correctly point to the Model Studio URL. If the output is empty or points to a non-Model Studio URL, check whether the settings.json configuration is correct.
  2. Confirm hasCompletedOnboarding.Check whether hasCompletedOnboarding in the ~/.claude.json file is set to true. If it is not set, Claude Code will attempt to connect to the official Anthropic service for login verification after startup.
  3. Reopen the terminal.After modifying the configuration file, you need to open a new terminal window and run claude again for the configuration to take effect.
  4. Update Claude Code.If none of the above steps works, the Claude Code version may be too old. Run npm install -g @anthropic-ai/claude-code@latest to update to the latest version and try again.
The legacy compatibility endpoint https://dashscope-intl.aliyuncs.com/api/v2/apps/claude-code-proxy only supports retired models, and specifying other models will not take effect. To call available models, migrate to the new API as described in this document.
This message comes from the connectivity check that CC Switch performs when saving a provider—it probes the model list endpoint (such as /v1/models) at the configured request URL. The Anthropic-compatible endpoint of Model Studio (ending with /apps/anthropic) only provides the conversation endpoint /v1/messages and does not provide a model list endpoint, so the probe returns 404, and CC Switch accordingly reports "No available model list endpoint found".This message does not affect the normal use of Claude Code and can be ignored.Claude Code initiates conversations through /v1/messages, and the model used is directly specified by the model mapping in the Advanced Options of CC Switch, without relying on automatic discovery through the model list endpoint. When the request URL and API Key are configured correctly, simply click Enable and start a new Claude Code session to chat normally.If conversations still fail, confirm the following: the request URL ends with /apps/anthropic without an extra /v1, and the model mapping in the Advanced Options has been filled in with a model supported by the corresponding plan.
If, after the model mapping is configured, calls fail in Claude Code and return an AccessDenied error (HTTP 403, error code access_denied), check whether the model is marked as "Retiring" in Models of the Model Studio console. Models marked as "Retiring" still appear in the list, but API calls return 403 AccessDenied. Troubleshooting steps are as follows:
  1. Check whether the model is marked as "Retiring".Search for the model you use in Models of the Model Studio console and view its status label.
  2. Switch to the latest available model.Replace the old model in the model mapping (such as qwen-coder-turbo-0919) with the latest available version (such as qwen3.8-max).
  3. Reconfigure the model mapping and test.Update the model mapping in the Advanced Options of CC Switch, click Enable, and start a new Claude Code session to verify.
Models marked as "Retiring" in Models of the Model Studio console may become unavailable at any time. Pay attention to model life cycles and check model availability in Models.