OpenCode is a terminal-based AI coding assistant. You can connect it to Alibaba Cloud Model Studio using a pay-as-you-go plan, Coding Plan, Token Plan Personal Edition, or Token Plan Team Edition.
Install OpenCode
- Install or update Node.js to version 18.0 or later.
- In your terminal, run the following command to install OpenCode:
Configure access credentials
Open the following configuration file in a text editor. If the directory or file does not exist, create it.
- macOS / Linux:
~/.config/opencode/opencode.json - Windows:
C:\Users\<Your-Username>\.config\opencode\opencode.json
- Token Plan Personal Edition: A personal subscription that deducts personal Credits based on token consumption.
- Token Plan Team Edition: A seat-based subscription where token consumption is deducted from Credits.
- Coding Plan: A fixed-fee monthly subscription billed by the number of model invocations.
- Pay-as-you-go: A post-paid method based on actual usage.
Token Plan Personal Edition
You must have an active Token Plan Personal Edition subscription. You can purchase one on the Token Plan Personal Edition page.
Replace YOUR_API_KEY with your dedicated Token Plan Personal Edition API Key. For a list of available models, see supported models.
Token Plan Team Edition
You must have an active Token Plan Team Edition subscription. You can purchase one on the Token Plan Team Edition page.
Replace YOUR_API_KEY with your dedicated Token Plan Team Edition API key. For a list of available models, see supported models.
Coding Plan
Replace YOUR_API_KEY with your dedicated Coding Plan API key. For a list of available models, see supported models.
Pay-as-you-go
Replace YOUR_API_KEY with your Alibaba Cloud Model Studio API key. For a list of available models, see Anthropic compatible API.
The baseURL is region-specific, replace {WorkspaceId} in the URL with your actual Workspace ID. Ensure that your API key corresponds to the selected region:
- China (Beijing):
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic/v1 - Singapore:
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1.
models object in the same format.
Verify the configuration
After saving the configuration file, restart OpenCode. Enter /models, search for Alibaba Cloud Model Studio, then select a model to start a conversation.
FAQ
Error codes
If you encounter an error during configuration, refer to the FAQ for your billing method:
- Pay-as-you-go: Anthropic compatible API - error codes
- Coding Plan: Coding Plan FAQ
- Token Plan Personal Edition: Token Plan Personal Edition FAQ
- Token Plan Team Edition: Token Plan Team Edition FAQ