For scenarios that do not require real-time responses, such as data annotation and content generation, real-time inference APIs suffer from high costs and limited concurrency. The Batch Chat API of Alibaba Cloud Model Studio retains the same synchronous invocation style as the real-time API—you simply send a request and wait for the final result to be returned. This feature currently enjoys a limited-time 50% discount on the official website, directly reducing your inference costs by 50%.
This interface only supports submitting a single request. To submit multiple requests at once, you can submit them via a file. For details, see OpenAI-compatible-Batch (file input).
How it works
- Request submission: The client sends a request and establishes a connection.
- Connection maintenance: The request enters a queue, and the client keeps the connection open while waiting.
-
Synchronous return: Once the request has been processed, the server returns the complete result to the client in one pass over the previously held connection.
If the maximum waiting time is exceeded, the connection is automatically closed and a timeout error is returned.
Scope
- China (Beijing)
- Text generation models: qwen4-max, qwen3.8-max, qwen3.8-flash, qwen3.7-max, qwen3.7-plus, qwen3.6-plus, qwen3.7-flash, qwen3.6-flash, qwen3.5-plus, qwen3.5-flash, qwen-plus, qwen-flash
- Image and video understanding models: qwen4-max, qwen3.8-max, qwen3.8-flash, qwen3.7-plus, qwen3.6-plus, qwen3.7-flash, qwen3.6-flash, qwen3.5-plus, qwen3.5-flash, qwen3.5-omni-plus, qwen3.5-omni-flash, qwen3-vl-plus
How to use
Prerequisites
-
You have activated the Alibaba Cloud Model Studio service and obtained an API Key.
We recommend configuring your API Key in environment variables to reduce the risk of API Key leakage.
- If you make calls through the OpenAI SDK, you need to install the SDK.
Step 1: Configure the API endpoint
Simply change the API endpoint (base_url) to easily switch your existing real-time inference requests to batch inference. Configure the correct API endpoint according to your invocation method.
SDK configuration: Set base_url to https://batch.dashscope.aliyuncs.com/compatible-mode/v1
HTTP invocation: The request endpoint is POST https://batch.dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
Step 2: Make the call
This section uses a text conversation as an example to show how to call the Batch Chat API.
The default waiting timeout for a request is 3600 seconds (1 hour); in most cases, no additional configuration is required.
The following example shows how to proactively set a custom timeout (60-3600 seconds) for reference.
- Python
- Java
- Node.js
- Go
- C#(HTTP)
- PHP(HTTP)
- curl
Sample requestSample response
Limits
- Waiting time: After a request is submitted, the result is awaited synchronously, and the server keeps the connection open for up to 3600 seconds (1 hour). You can set a custom timeout based on your actual needs, with a valid range of 60-3600 seconds.
- Concurrency limit: A single account can maintain up to 10,000 pending requests per model. New requests that exceed this limit are rejected with a corresponding error code until pending requests complete and free up available slots.
-
Request rate: A single account can submit requests at a maximum rate of 1000 QPS (10,000 requests / 10 seconds).
This limit is a theoretical maximum set by the system. In actual usage, the API's available resources are dynamically affected by the overall system load. We recommend implementing retry logic in your code.
Billing Details
- Billing unit price: You are billed for the input and output tokens of successful requests, at the same rates as real-time model invocations. For a limited time, the official website offers a 50% discount for Batch Chat calls, with the final fee being 50% of the real-time invocation price. For more information, see Models.
- Billing scope: Only requests that are successfully executed in a task are billed. Any failed requests (including system errors or timeouts) are not billed.
Error codes
If a model invocation fails and returns an error message, see Error codes for troubleshooting.
FAQ
- Is there a difference in processing time between Batch Chat requests and real-time APIs? Yes. Batch Chat requests must queue for scheduling, so the end-to-end processing time is usually longer than that of real-time APIs. The maximum waiting time on the server side is 1 hour. If a request is not executed within this time, the connection is automatically closed and an error is returned.
- How do I choose between Batch Chat and Batch File? Choose Batch Chat when your business logic requires submitting a large number of independent conversation requests with high concurrency via synchronous API calls. Choose Batch File when you need to process a single large file containing many requests and can accept asynchronously retrieving the result file.
- Does Batch Chat guarantee that all requests are completed? No. Batch Chat uses Batch resources, and completion depends on system resource allocation. If system resources are busy, requests may wait in the queue. If a request is still not scheduled for execution after the maximum waiting time, the connection times out and closes. In this case, the request is not billed, and you can retry later.
Related documentation
- For the complete parameter list for real-time model invocations, see OpenAI-compatible Chat.
- To perform batch processing by submitting files and retrieving results asynchronously, see OpenAI-compatible Batch (file input).