Qwen-Coder is a language model designed for code tasks. You can use the API to generate code, complete code, and call tools to interact with external systems.
It is recommended to use the latest general-purpose model instead of the Qwen-Coder model. See Text Generation to select a model that fits your scenario.
Quick Start
API prerequisites: You have obtained and configured an API Key and configured the API Key as an environment variable. If calling via an SDK, you need to install the OpenAI or DashScope SDK.
The following example demonstrates how to call the qwen3-coder-flash model to write a Python function that finds prime numbers.
- OpenAI-compatible Chat Completions API
- DashScope
- Python
- Node.js
- curl
Request ExampleResponse
Core Capabilities
Calling Tools
To enable the Model to interact with the external environment (for example, reading and writing files, calling APIs, and operating databases), you can provide it with a series of tools. The Model decides whether and how to call these tools based on your instructions. For details, see Function Calling.
The complete tool calling workflow includes:
- Define tools and initiate a request: Define the tool list in the request, and present to the model the task that needs to be completed using tools.
- Execute tools: Parse what the model returns
tool_calls, and call the corresponding tool function you have implemented locally to execute the task. - Return execution result: Package the tool's execution result into a specific format and send it back to the model, allowing it to complete the final task based on the result.
write_file tool to save it to a local file.
- OpenAI-compatible Chat Completions API
- DashScope
- Python
- Node.js
- curl
Code completion
Qwen-Coder implements code completion through Prefix Continuation (Partial Mode), which applies to all Qwen-Coder models and regions. This feature lets the model automatically complete the remaining part based on the code (prefix) you have half-written.
By adding a message with role set to assistant in the messages list and setting partial: true, you can implement this. The assistant message's content is the code prefix you provide. For details, see Prefix Continuation.
- OpenAI-compatible
- DashScope
- Python
- Node.js
- curl
Request ExampleResponse
Applied to Production Environment
To optimize the usage efficiency of the Qwen code Model and reduce costs, refer to the following suggestions:
- Enable Stream: Setting
stream=Truereturns intermediate results in real time, reducing timeout risks and improving user experience. - Lower the temperature parameter: Code generation tasks usually require deterministic and accurate results. It is recommended to lower the
temperatureparameter to reduce the randomness of the generated results. - Use a model that supports context caching: In scenarios with a large amount of repeated prefixes (such as code completion, code review), it is recommended to use a model that supports Context Cache to effectively reduce costs.
- Control tool count: To ensure the efficiency and cost-effectiveness of model calls, it is recommended that the number of tools
toolspassed in a single call not exceed 20. Passing a large number of tool descriptions consumes excessive input tokens, which not only increases costs and slows response speed, but also makes it harder for the model to select the correct tool. For details, see Function Calling.
Billing and Rate Limiting
-
Basic Billing: Billed based on the input
Tokencount and outputTokencount of each request. Different models have different unit prices; for specific prices, please refer to Models. -
Special Billing Items:
- Tiered Pricing: The
qwen3-coderseries models adopt tiered pricing. When the input Token count of a single request reaches a specific tier, all input and output Tokens of that request are billed at the unit price of that tier. - Context Cache: For models that support context caching, when multiple requests contain large amounts of repeated input (such as code review), the cache mechanism can significantly reduce costs. Input text that hits the implicit cache is billed at 20% of the unit price, and input text that hits the explicit cache is billed at 10% of the unit price. For details, see Context Cache.
- Tool calling (Function Calling): When using the tool calling feature, the tool descriptions you define in the
toolsparameter are counted as input content into the totalTokencount and incur fees.
- Tiered Pricing: The
- Rate Limit: API calls are subject to dual limits of requests per minute (RPM) and Tokens per minute (TPM). For details, see Rate Limit.
- Free Quota (Beijing region only) (Singapore region only): The validity period is calculated from the date of activating Model Studio or model application approval. Within the 90-day validity period, each Qwen-Coder model provides 1 million Tokens of the new user free quota respectively.
API Reference
For the Input Parameters and output parameters of the Qwen Code Model, see Text Generation.
FAQ
Why does using development tools like Qwen Code, Claude Code, etc. consume a large amount of Token?
When calling the Qwen-Coder model through external development tools to handle problems, the tool may call the API multiple times, thereby consuming a large amount of Token. For specific methods on monitoring and reducing Token consumption, please refer to the Qwen Code and Claude Code docs. You can enable the Free Quota Only feature to avoid additional costs after the free quota is exhausted.
You can also purchase an AI coding plan, which adopts a fixed monthly fee and provides a monthly request quota for use in AI tools. For details, please refer to Coding Plan Overview.
How to view model call volume?
You can view model calls in monitoring charts within minutes after a model call occurs. Log in to the model monitoring page (Beijing or Singapore), select Operations Management > Monitoring from the left navigation bar to enter the monitoring overview page, set the query conditions (for example, select the time range, workspace, etc.), then locate the target model in the Models area and click View Details to view the call statistics of the model. For details, see the Monitoring & Alerts docs.
Monitoring data is updated at the minute level and is for reference only, not for billing purposes.
How to make the model output only code without any explanatory text?
You can refer to the following methods:
- Prompt constraints: Give explicit instructions in the prompt, for example: "Return only code, without any explanations, comments, or markdown markers."
- Set
stopsequences: Use phrases such asstop=["\n# Explanation:", "Description", "Explanation:", "Note:"]to terminate generation early when the model starts producing explanatory text. For details, see the Qwen API reference.