Skip to main content
Toolkit/Framework

OpenAI-compatible - Batch Chat

For non-real-time scenarios like data annotation and content generation, the Batch Chat API offers a low-cost, high-concurrency alternative using the same synchronous call method. Limited-time 50% discount available.

This API supports only single-request submissions. To submit multiple requests at once, package them in a file. See OpenAI-compatible - Batch (file input).

How it works

  1. Submit request: The client sends a request and establishes a connection.
  2. Queue and wait: The request enters a queue while the client maintains the connection.
  3. Return result: The server returns the complete result over the established connection after processing.
    The connection disconnects with a timeout error if the maximum wait time is exceeded.

Availability

  • China (Beijing)
  • Text generation models: qwen3.8-max, qwen3.7-max, qwen3.7-plus, qwen3.6-plus, qwen3.7-flash, qwen3.6-flash, qwen3.5-plus, qwen3.5-flash, qwen3-max, qwen-plus, qwen-flash, deepseek-v3.2
  • Image and video understanding models: qwen3.8-max, qwen3.7-plus, qwen3.6-plus, qwen3.7-flash, qwen3.6-flash, qwen3.5-plus, qwen3.5-flash, qwen3.5-omni-plus, qwen3-vl-plus, qwen3-vl-flash
  • In the batch processing scenario, the maximum context tokens per request is 256 K for qwen3.8-max, qwen3.7-max, qwen3.7-plus, qwen3.6-plus, qwen3.7-flash, qwen3.6-flash, qwen3.5-plus, qwen3.5-flash, and qwen3.5-omni-plus.
  • Some models support thinking mode. Enabling this mode generates thinking tokens and increases costs.
  • The qwen3.8, qwen3.7, qwen3.6, and qwen3.5 series models have thinking mode enabled by default. If you use a hybrid thinking model, you must explicitly set the enable_thinking parameter. Set this parameter to true to enable the mode or false to disable it.
  • In the JSONL request body, enable_thinking is a top-level parameter of body and must be placed at the same level as model. Do not place it inside extra_body.

Usage

Prerequisites

pip3 install -U openai

Step 1: Configure the API endpoint

Switch from real-time to batch inference by modifying the API endpoint (base_url) based on your call method: SDK: Set base_url to https://batch.dashscope.aliyuncs.com/compatible-mode/v1 HTTP: POST https://batch.dashscope.aliyuncs.com/compatible-mode/v1/chat/completions

Step 2: Make a call

The following examples show how to call the Batch Chat API. Default timeout is 3600 seconds (1 hour); no extra configuration is needed in most cases.
Custom timeout range: 60–3600 seconds.
  • Python
  • Java
  • Node.js
  • Go
  • C# (HTTP)
  • PHP (HTTP)
  • curl
Request example
import os
from openai import OpenAI

client = OpenAI(
   # If environment variable not set, replace with api_key="sk-xxx".
   # Avoid hard-coding API keys in production to reduce leak risk.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://batch.dashscope.aliyuncs.com/compatible-mode/v1",  # Batch Chat API endpoint
).with_options(timeout=1800.0) # Timeout: 1800s (30 min). Max: 3600s.

completion = client.chat.completions.create(
    model="qwen-plus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who are you?"},
    ]
)
print(completion.choices[0].message.content)
Response example
I am Qwen, a large-scale language model from Alibaba Group. I can answer questions, create text such as stories, official documents, emails, and scripts, perform logical reasoning, write code, and more. I can also express opinions and play games. If you have any questions or need help, feel free to let me know!

Limitations

  • Wait time: Maximum 3600 seconds (1 hour) for synchronous waiting. Set custom timeout: 60–3600 seconds.
  • Concurrency limits:Maximum 10,000 pending requests per model per account. Exceeding requests rejected with error code. New requests accepted only after pending requests complete.
  • Call rate: Maximum 1000 QPS per account, or 10,000 calls per 10 seconds.
    Theoretical maximum only. Actual availability depends on system load. Implement retry logic.

Billing

  • Unit price: Billing based on input/output tokens in successful requests. List price matches real-time call price. Limited-time 50% discount available on official website. See Model list.
  • Billing scope: Only successful requests billed. Failed requests (system errors or timeouts) not billed.
  • Batch inference is a separate billing item. It supports AI general-purpose savings plan, but not discounts, such as subscription (other savings plans) or free quotas for new users. It also does not support features such as context cache.
  • Some models, such as qwen3.5-plus and qwen3.5-flash, have thinking mode enabled by default. This mode generates additional thinking tokens, which are billed at the output token price and increase costs. To control costs, set the enable_thinking parameter based on task complexity. For more information, see Deep thinking.

Error codes

If the model call fails and returns an error message, see Error codes for resolution.

FAQ

  1. Is there a difference in request time between Batch Chat and the real-time API? Yes. Requests are queued for scheduling, so end-to-end time is typically longer than real-time API. Maximum wait: 1 hour. Connection disconnects with error if timeout exceeded.
  2. How do I choose between Batch Chat and Batch File? Choose Batch Chat for many independent dialogue requests with high concurrency via synchronous calls. Choose Batch File for processing a single large file with many requests via asynchronous retrieval.
  3. Does Batch Chat guarantee that all requests will be completed? No. Completion depends on shared resource allocation. Requests may queue if resources busy. Connection times out if not executed within maximum wait time. Timed-out requests are not billed; retry later.

References