Use Alibaba Cloud Model Studio models in Claude Code.
Quick start
Select the client you use and complete the configuration.
CLI
- 1
Configure the model
Token Plan
Replace
YOUR_API_KEYwith your Token Plan API Key:- Token Plan Personal: Create or view API Key
- Token Plan Team: Allocate seats and obtain 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"NoteIf 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.pay-as-you-go billing method
Replace
YOUR_API_KEYwith an Alibaba Cloud Model Studio API Key, and replace{WorkspaceId}with your actual Workspace ID. The following example uses Singapore.export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY" export ANTHROPIC_BASE_URL="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic" export ANTHROPIC_MODEL="qwen3.7-max" export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.6-flash" export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.7-max" export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3.7-max" export CLAUDE_CODE_SUBAGENT_MODEL="qwen3.7-max"Coding Plan
Replace
YOUR_API_KEYwith a Coding Plan API Key.export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY" export ANTHROPIC_BASE_URL="https://coding-intl.dashscope.aliyuncs.com/apps/anthropic" export ANTHROPIC_MODEL="qwen3.7-plus" export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.7-plus" export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.7-plus" export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3.7-plus" export CLAUDE_CODE_SUBAGENT_MODEL="qwen3.7-plus"NoteThe above environment variables apply only to the current terminal session. To persist the configuration, use Connect via a configuration file.
- 2
Verification
Run the following command to verify:
claude -p "你好"
CC Switch
- 1
Install CC Switch
Download and install it from CC Switch.
- 2
Add the Model Studio provider
In CC Switch, select the Claude Code icon, click +, fill in the configuration on the corresponding tab, and add it.
Token Plan
- Provider name: Model Studio-Token Plan
- Token Plan Personal API Key: Create or view
- Token Plan Team API Key: Allocate seats and obtain
- Request URL:
https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic
pay-as-you-go billing method
- Provider name: Model Studio-pay-as-you-go
- API Key: Model Studio API Key
- Request URL:
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic
Coding Plan
- Provider name: Model Studio-Coding Plan
- API Key: Obtain from the console
- Request URL:
https://coding-intl.dashscope.aliyuncs.com/apps/anthropic
- 3
Configure model mapping
Expand Advanced options, and set the main model and the Haiku, Sonnet, and Opus models. For example:
- Main model:
qwen3.8-max - Default Haiku model:
qwen3.8-flash - Default Sonnet model:
qwen3.8-flash - Default Opus model:
qwen3.8-max
- Main model:
- 4
Switch to the Claude Desktop panel
In the left sidebar of CC Switch, switch to the Claude Desktop panel; if it is not displayed, enable it in Settings → General → App visibility.
- 5
Import a provider
You can import a provider already configured in Claude Code, or click + to add one. For Model Studio model IDs, enable Model mapping required, and fill in the actual models for Sonnet, Opus, and Haiku.
- 6
Enable local routing
Go to Settings → Routing → Local routing, and turn on the switch on the home page; enable local routing in the Claude Desktop panel, with the default address
127.0.0.1:15721. - 7
Enable and restart the desktop app
Click Enable on the provider card. Do not manually enter the API Key in the desktop app. Keep CC Switch running, and fully exit and restart the desktop app.
IDE plug-in
- 1
Install the plug-in
Install the Claude Code plug-in from the extension marketplace of your IDE.
- 2
Configure the model
Write to
settings.jsonas described in Connect via a configuration file, or complete the configuration in the CLI first. - 3
Open Claude Code
Restart the IDE, click the Claude Code icon, enter
/in the dialog box, select General config, and set the model in Selected Model.
Desktop app
The Claude Code desktop app connects to Model Studio through the CC Switch local gateway.
- 1
Install the Claude Code desktop app
Download and install it from the Claude download page.
- 2
Configure CC Switch
Complete the provider and routing configuration on the CC Switch tab.
- 3
Restart the desktop app
Keep CC Switch running, and fully exit and restart the Claude Code desktop app.
Connect via a configuration file
In addition to the methods above, you can also connect via a configuration file.
- 1
Open or create a configuration file
- macOS / Linux:
~/.claude/settings.json - Windows:
C:\Users\<username>\.claude\settings.json
- macOS / Linux:
- 2
Write the configuration
Token Plan
Replace
YOUR_API_KEYwith your Token Plan API Key:- Token Plan Personal: Create or view API Key
- Token Plan Team: Allocate seats and obtain 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" } }pay-as-you-go billing method
Replace
YOUR_API_KEYwith the Alibaba Cloud Model Studio API Key, and replace{WorkspaceId}with the actual Workspace ID. The Singapore region is used as an example here.{ "env": { "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY", "ANTHROPIC_BASE_URL": "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic", "ANTHROPIC_MODEL": "qwen3.7-max", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.6-flash", "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.7-max", "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.7-max", "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-max" } }Coding Plan
Replace
YOUR_API_KEYwith a Coding Plan API Key.{ "env": { "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY", "ANTHROPIC_BASE_URL": "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic", "ANTHROPIC_MODEL": "qwen3.7-plus", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.7-plus", "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen3.7-plus", "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen3.7-plus", "CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.7-plus" } } - 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 variablesAdd 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.
NoteWhen 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.
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.
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
Install the Model Studio CLI
请帮我全局安装阿里云百炼 CLI 命令行工具:npm install -g bailian-cli - 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
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:
- Token Plan: Personal plan FAQ · Team plan FAQ
- Pay-as-you-go billing: Error codes
- Coding Plan: Coding Plan FAQ
FAQ
How do I use a savings plan with pay-as-you-go billing?
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.
The call returns 401 invalid_api_key
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 |
| Token Plan API Key |
pay-as-you-go billing method | Model Studio API Key (starting with | |
Coding Plan | Coding Plan API Key |
Troubleshooting steps are as follows:
- Check the request URL.View the value of
ANTHROPIC_BASE_URLin~/.claude/settings.json. - 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. - Fix the configuration.When using a Model Studio pay-as-you-go API Key, set
ANTHROPIC_BASE_URLtohttps://dashscope-intl.aliyuncs.com/apps/anthropic.
After starting Claude Code, the interface displays "Unable to connect to Anthropic services. Failed to connect to api.anthropic.com: ERR_BAD_REQUEST"
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:
- Check the configuration.After starting Claude Code, run the
/statuscommand to confirm whetherANTHROPIC_BASE_URLandANTHROPIC_AUTH_TOKENcorrectly point to the Model Studio URL. If the output is empty or points to a non-Model Studio URL, check whether thesettings.jsonconfiguration is correct. - Confirm hasCompletedOnboarding.Check whether
hasCompletedOnboardingin the~/.claude.jsonfile is set totrue. If it is not set, Claude Code will attempt to connect to the official Anthropic service for login verification after startup. - Reopen the terminal.After modifying the configuration file, you need to open a new terminal window and run
claudeagain for the configuration to take effect. - 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@latestto update to the latest version and try again.
Using the legacy API, switching models does not take effect
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.
When adding a provider using CC Switch, the prompt says "No available model list endpoint found. Please check the Base URL or confirm whether the provider has opened the port"
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.
Calls fail after model mapping in CC Switch
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:
- 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.
- 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 asqwen3.8-max). - 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.