Recently, new code generation models Qwen3-Code
It has attracted a lot of attention in the developer community. However, some developers have encountered unexpected cost issues when using their API services. Some developers have reported that after writing a small amount of code, they encountered the problem of exceeding the API usage limit and incurred unexpected costs. There are even cases that show that a single code submission led to hundreds of dollars of bills, this "code did not write much, the bill first to report" situation, undoubtedly bringing trouble to developers.
Fortunately, the Magic Tower community (ModelScope
) provides a solution to this problem.ModelScope
is an open source modeling community launched by Alibaba to promote the exchange and application of AI models. The platform provides free inference API call credits for a number of models, including the Qwen3-Code
The free daily quota is up to 2,000, which is quite enough for most development and testing scenarios.
The following section describes how to pass the ModelScope
free of charge Qwen3-Code
combining Qwen CLI
tools for development.
Get free API credentials
First, in the ModelScope
Search on the community website and enter Qwen3-Code
You can find the "View Code Demonstration" option on the model page.
When clicked, three core pieces of information are provided in the sample code:base_url
,api_key
cap (a poem) model
The
from openai import OpenAI
client = OpenAI(
base_url='https://api-inference.modelscope.cn/v1/',
api_key='YOUR_MS_API_KEY', # 替换为你自己的ModelScope Token
# ModelScope Token, 示例: ms-4c51dab7-2022-4f56-a009-13adb22
)
response = client.chat.completions.create(
model='Qwen/Qwen3-Coder-480B-A35B-Instruct', # ModelScope Model-Id
messages=[
{
'role': 'system',
'content': 'You are a helpful assistant.'
},
{
'role': 'user',
'content': '你好'
}
],
stream=True
)
for chunk in response:
print(chunk.choices.delta.content, end='', flush=True)
API Key
Requires user login ModelScope
account before it can be generated and viewed. In addition, using the ModelScope
of the inference service must first bind a valid Aliyun account on the backend management page.
If the binding is not completed, you will receive the following error when calling the API:
{"errors":{"message":"Please bind your Alibaba Cloud account before use."},"request_id":"774509ee-a256-406b-b00d-900"}
Configuring the Qwen CLI Tool
Once you have completed the preparation of your API credentials, you can begin configuring the Qwen CLI
TheQwen CLI
is a command-line tool that allows developers to work with the Qwen
models to interact and enable fast code generation and completion.
First, the global installation Qwen CLI
::
npm i -g @qwen-code/qwen-code
After successful installation, execute the following command to start the tool:
qwen
Next, configure the environment variables by setting the ModelScope
The free API information provided is available to Qwen CLI
The
# API 密钥
export OPENAI_API_KEY="YOUR_MS_API_KEY"
# API 基础 URL
export OPENAI_BASE_URL="https://api-inference.modelscope.cn/v1/"
# 模型名称
export OPENAI_MODEL="Qwen/Qwen3-Coder-480B-A35B-Instruct"
If an error occurs during configuration or needs to be reset, you can simply delete the user's home directory under the .qwen
configuration file and then reconfigure it.
Providing developers with free API call credits is a smart ecological strategy. It not only significantly lowers the entry threshold and cost of use for developers, but also inspires broader community participation and innovation, ultimately contributing to the prosperity of the modeling ecosystem.