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
Configure the model
- Token Plan
- pay-as-you-go billing method
- Coding Plan
ReplaceYOUR_API_KEYwith your Token Plan API Key:- Token Plan Personal: Create or view API Key
- Token Plan Team: Allocate seats and obtain API Key
If long outputs are truncated, setCLAUDE_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
Verification
Run the following command to verify:
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
- pay-as-you-go billing method
- Coding Plan
ReplaceYOUR_API_KEYwith your Token Plan API Key:- Token Plan Personal: Create or view API Key
- Token Plan Team: Allocate seats and obtain API Key
- 3
Verification
After saving, run the following command for verification:
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:
[1m] suffix after the model name, applicable to Model Studio models that support a 1M context:
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.
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.--permission-mode to specify the default permission mode for this session:
/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:
Connect to Model Studio CLI
- 1
Install the Model Studio CLI
- 2
Configure the API Key
Go to the Model Studio console to obtain an API Key, and then tell Claude Code: - 3
Get started
Describe your requirements directly in natural language, for example:
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?
How do I use a savings plan with pay-as-you-go billing?
How do I skip Anthropic official login verification?
How do I skip Anthropic official login verification?
~/.claude.json (Windows path: C:\Users\<username>\.claude.json), and set hasCompletedOnboarding to true to skip the Anthropic official login verification.The call returns 401 invalid_api_key
The call returns 401 invalid_api_key
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 |
- 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"
After starting Claude Code, the interface displays "Unable to connect to Anthropic services. Failed to connect to api.anthropic.com: ERR_BAD_REQUEST"
- 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
Using the legacy API, switching models does not take effect
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"
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"
/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
Calls fail after model mapping in CC Switch
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.