Batch Chat 与 Batch File 区别详解

Batch Chat 与 Batch File 区别详解 · Qwen3.7-Max

Batch Chat 与 Batch File 区别详解基于 Qwen3.7-Max 定价页面的完整分析

千问 AI 平台为 Qwen3.7-Max 提供了两种调用计费模式:Batch Chat(实时对话)与 Batch File(异步批量文件处理),二者在调用方式、响应速度和定价机制上存在显著差异。

一、概述:两种调用模式

Qwen3.7-Max 的定价页面中,千问 AI 平台明确区分了两种计费方式:Batch ChatBatch File。这两者并非简单的价格档位差异,而是代表了两种截然不同的 API 调用架构。

核心区别:Batch Chat 是同步实时的对话 API 调用,每次请求即时返回结果;Batch File 是异步批量的文件处理 API,通过上传 JSONL 文件提交大量请求,系统在 24 小时内异步处理并返回结果文件。
用户请求 选择调用模式
Batch Chat 即时响应 标准计费
Batch File 上传JSONL 异步处理 下载结果 5折计费
图 1 Batch Chat 与 Batch File 调用流程对比

二、定价对比

Qwen3.7-Max 的定价页面列出了两种模式的完整价格信息。需要注意的是,当前平台处于限时5折促销期,Batch Chat 的促销价与 Batch File 的常规价恰好相同,但这只是临时巧合。

计费项 标准价格 Batch Chat(限时5折) Batch File
输入 / Input ¥12 / M tokens ¥12¥6 ¥6
输出 / Output ¥36 / M tokens ¥36¥18 ¥18
输入(缓存命中) ¥2.4 / M tokens ¥2.4¥1.2
表 1 Qwen3.7-Max Batch Chat 与 Batch File 定价对比(数据来源:千问 AI 平台定价页)
关键提醒:Batch Chat 的 5 折是限时促销,促销结束后将恢复标准价格(¥12/M 输入、¥36/M 输出)。而 Batch File 的 5 折是永久性折扣,始终为标准价格的 50%。促销结束后,Batch File 的成本优势将显著体现。

三、Batch Chat 详解

Batch Chat 指的是通过标准的 /v1/chat/completions 端点进行同步实时的对话 API 调用。每次发送一条消息(或一组 messages),模型即时生成回复并返回。这是最常用的 API 调用方式。

3.1 核心特征

调用方式

同步请求-响应模式。客户端发送 HTTP 请求,等待模型处理完成后直接返回结果。支持流式输出(stream=True)。

响应速度

即时返回,通常在数秒内完成。适合需要低延迟的交互式场景。

API 端点

/v1/chat/completions

定价机制

标准价格计费(当前限时5折)。输入 ¥12/M tokens,输出 ¥36/M tokens。

3.2 支持的高级功能

Batch Chat 作为标准对话 API,支持 Qwen3.7-Max 的全部高级功能:

流式输出(Streaming):通过 stream=True 参数,模型生成内容时逐步返回 token,实现打字机效果。

思考模式(Thinking):通过 enable_thinking=True 参数启用深度思考,模型会先生成思维链再给出最终回复。

函数调用(Function Calling):将大模型与外部工具和系统连接,实现 Agent 能力。

结构化输出(Structured Output):确保模型返回符合预期格式的 JSON 字符串。

上下文缓存(Context Cache):缓存长上下文的公共前缀,减少重复计算。

四、Batch File 详解

Batch File 是千问 AI 平台提供的异步批量推理服务。用户将多条请求打包成 JSONL 格式文件上传,系统在后台队列中异步处理,结果在 24 小时内生成。费用仅为实时调用价格的 50%[1]

4.1 工作原理

准备JSONL文件 上传文件 创建批量任务 异步处理 查询状态 下载结果
图 2 Batch File 异步批量处理工作流程

4.2 输入文件格式

输入文件为 JSONL 格式,每行一个独立的请求:

{"custom_id":"req-1","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen3.7-max","messages":[{"role":"user","content":"用两句话概括量子计算。"}]}}
{"custom_id":"req-2","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen3.7-max","messages":[{"role":"user","content":"2+2 等于几?"}]}}
文件限制:每个文件最多 50,000 条请求,总大小不超过 500 MB,单行不超过 6 MB。所有请求必须使用同一个模型,每个 custom_id 必须唯一且不超过 256 个字符。所有请求的 url 必须设为 /v1/chat/completions

4.3 任务状态流转

validating in_progress finalizing completed

终态包括:completed(完成)、failed(失败)、expired(过期)、cancelled(已取消)。建议每 1-2 分钟轮询一次状态。

4.4 结果文件格式

任务完成后,系统生成输出文件(成功响应)和错误文件(失败详情,如有)。输出文件中的每行通过 custom_id 与原始请求对应:

{"id":"batch_req_xxx","custom_id":"req-1","response":{"status_code":200,"body":{"choices":[{"message":{"content":"..."}}],"usage":{...}}}}

五、核心区别对比

对比维度 Batch Chat Batch File
调用模式 同步实时 异步批量
响应时间 即时(数秒) 24 小时内
API 端点 /v1/chat/completions /v1/batches + /v1/files
输入格式 JSON 请求体 JSONL 文件
请求规模 单次请求 最多 50,000 条/文件
定价机制 标准价格(限时5折) 永久5折
输入价格 ¥12/M(促销¥6/M) ¥6/M
输出价格 ¥36/M(促销¥18/M) ¥18/M
结果获取 直接返回 下载结果文件
流式输出 支持 不支持
上下文限制 991K(输入)/ 131K(输出) 256K(Batch 场景)
思考模式 支持 enable_thinking 支持(body 顶层参数)
缓存叠加 支持 Context Cache 不可叠加
适用场景 交互式对话、实时问答 大规模批量处理、离线分析
表 2 Batch Chat 与 Batch File 全维度对比

六、调用方式与代码示例

6.1 Batch Chat 调用方式

Batch Chat 使用标准的 OpenAI SDK 兼容接口,直接调用 chat.completions.create() 方法:

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

# Batch Chat: 同步实时调用
response = client.chat.completions.create(
    model="qwen3.7-max",
    messages=[{"role": "user", "content": "用两句话概括量子计算。"}],
)

print(response.choices[0].message.content)

支持流式输出和思考模式:

# 流式输出 + 思考模式
response = client.chat.completions.create(
    model="qwen3.7-max",
    messages=[{"role": "user", "content": "证明根号2是无理数"}],
    extra_body={"enable_thinking": True},
    stream=True,
)

for chunk in response:
    delta = chunk.choices[0].delta
    if hasattr(delta, "reasoning_content") and delta.reasoning_content:
        print(delta.reasoning_content, end="", flush=True)
    if hasattr(delta, "content") and delta.content:
        print(delta.content, end="", flush=True)

6.2 Batch File 调用方式

Batch File 调用分为四个步骤:上传文件 → 创建任务 → 查询状态 → 下载结果

  1. 步骤一:上传 JSONL 文件 file_object = client.files.create( file=Path(“input.jsonl”), purpose=”batch” ) print(file_object.id) # file-batch-xxx 文件上传后返回 ID,可复用。无需每次重新上传相同文件。
  2. 步骤二:创建批量任务 batch = client.batches.create( input_file_id=”file-batch-xxx”, endpoint=”/v1/chat/completions”, completion_window=”24h”, # 24h 到 336h(14天) metadata={ “ds_name”: “My batch job”, “ds_description”: “批量处理任务”, } ) print(batch.id) # batch_xxx endpoint 必须与输入文件中的 url 一致。completion_window 可设为 24h 到 336h(14天)。
  3. 步骤三:查询任务状态 batch = client.batches.retrieve(“batch_xxx”) print(batch.status) # validating → in_progress → finalizing → completed 建议每 1-2 分钟轮询一次。状态变为 completed 后可下载结果。
  4. 步骤四:下载结果 content = client.files.content(“file-batch_output-xxx”) content.write_to_file(“result.jsonl”) 同时可下载 error_file_id 查看失败请求的详情。结果通过 custom_id 与原始请求匹配。

完整代码示例:

from openai import OpenAI
from pathlib import Path
import os, time

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

# Step 1: 上传文件
file_object = client.files.create(
    file=Path("input.jsonl"),
    purpose="batch"
)
print(f"文件ID: {file_object.id}")

# Step 2: 创建批量任务
batch = client.batches.create(
    input_file_id=file_object.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
    metadata={"ds_name": "Qwen3.7-Max batch job"}
)
print(f"任务ID: {batch.id}")

# Step 3: 轮询状态
while True:
    batch = client.batches.retrieve(batch.id)
    print(f"状态: {batch.status}")
    if batch.status in ("completed", "failed", "expired", "cancelled"):
        break
    time.sleep(60)

# Step 4: 下载结果
if batch.status == "completed":
    content = client.files.content(batch.output_file_id)
    content.write_to_file("result.jsonl")
    print("结果已保存到 result.jsonl")

6.3 JSONL 输入文件准备

可使用 CSV 转 JSONL 脚本批量生成输入文件:

import csv, json

def build_messages(content):
    return [{"role": "user", "content": content}]

with open("input.csv") as fin, open("input.jsonl", "w") as fout:
    for row in csv.reader(fin):
        request = {
            "custom_id": row[0],
            "method": "POST",
            "url": "/v1/chat/completions",
            "body": {
                "model": "qwen3.7-max",
                "messages": build_messages(row[1])
            }
        }
        fout.write(json.dumps(request, ensure_ascii=False) + "\n")

6.4 使用控制台操作

除了 API 调用,也可通过千问 AI 平台控制台操作 Batch File:

  1. 打开批量 API 页面 登录千问 AI 平台控制台,进入「批量 API」页面。
  2. 创建批量推理任务 填写任务名称和描述,设置最大等待时间(1-14天),上传 JSONL 输入文件。
  3. 监控和管理任务 在任务列表中查看进度(已处理/总请求数)和状态,可取消校验中或执行中的任务。
  4. 下载结果 任务状态变为 completed 后,在详情页面下载输出文件和错误文件。

七、使用场景推荐

⚡ Batch Chat 适用场景

聊天机器人 / 智能客服:需要即时回应用户输入,延迟敏感。

实时问答系统:用户提出问题,系统立即返回答案。

交互式编程助手:如代码补全、实时调试建议。

流式输出场景:需要打字机效果逐字显示。

Agent / 函数调用:需要模型实时决策并调用外部工具。

小规模请求:请求量不大,无需批量处理。

📂 Batch File 适用场景

大规模数据标注:批量处理数万条文本的分类、摘要、情感分析。

批量翻译:一次性翻译大量文档或段落。

文档批量处理:对大量文档进行摘要、信息抽取、格式转换。

离线分析任务:无需实时响应的数据分析、报告生成。

内容批量生成:批量生成产品描述、营销文案等。

成本敏感场景:追求最低 Token 成本的大规模处理。

八、注意事项

上下文限制:在 Batch 场景下,Qwen3.7-Max 单次请求的上下文 Token 数最大支持 256K(而非实时调用的 991K)。如果单条请求的上下文超过 256K,需要拆分或截断。
思考 Token 计费:Qwen3.7-Max 默认开启思考功能,会产生额外的思维链 Token 并按输出价格计费。在 JSONL 请求体中,enable_thinking 是 body 的顶层参数,须与 model 同级传入,不能放在 extra_body 中。建议显式设置 enable_thinking: false 以降低成本(如不需要思考功能)。
折扣不可叠加:批量折扣不与上下文缓存或其他折扣叠加。如果请求中命中了 Context Cache,将按缓存命中价格计费,而非批量5折价格。
文件存储限制:每个账号最多 10,000 个文件 / 100 GB。请及时删除旧文件释放空间。任务保留期仅最近 30 天,过期任务无法通过列表接口查询。
频率限制:创建任务 1,000 次/分钟(最多 1,000 个并发),查询 1,000 次/分钟,列表 100 次/分钟,取消 1,000 次/分钟。
测试模型:可将 model 设为 batch-test-modelendpoint 设为 /v1/chat/ds-test,即可在不产生推理费用的情况下验证文件格式。限制:文件不超过 1 MB、不超过 100 行、最多 2 个并发任务。

Batch Chat vs Batch File: Complete GuideComprehensive Analysis Based on Qwen3.7-Max Pricing

The Qianwen AI platform offers two billing modes for Qwen3.7-Max: Batch Chat (real-time conversation) and Batch File (asynchronous batch file processing), which differ significantly in calling methods, response speed, and pricing.

1. Overview: Two Calling Modes

On the Qwen3.7-Max pricing page, the Qianwen AI platform explicitly distinguishes two billing modes: Batch Chat and Batch File. These are not simply different price tiers but represent two fundamentally different API calling architectures.

Core Difference: Batch Chat is a synchronous real-time conversation API call where each request returns immediately. Batch File is an asynchronous batch file processing API where you upload a JSONL file with multiple requests, and the system processes them asynchronously within 24 hours and returns result files.
User Request Choose Mode
Batch Chat Instant Response Standard Pricing
Batch File Upload JSONL Async Processing Download Results 50% Off Pricing
Figure 1 Batch Chat vs Batch File workflow comparison

2. Pricing Comparison

The Qwen3.7-Max pricing page lists complete price information for both modes. Note that the platform is currently in a limited-time 50% off promotion, making Batch Chat’s promotional price temporarily equal to Batch File’s regular price — but this is a temporary coincidence.

Billing Item Standard Price Batch Chat (50% Off Promo) Batch File
Input ¥12 / M tokens ¥12¥6 ¥6
Output ¥36 / M tokens ¥36¥18 ¥18
Input (Cache Hit) ¥2.4 / M tokens ¥2.4¥1.2
Table 1 Qwen3.7-Max Batch Chat vs Batch File pricing comparison (Source: Qianwen AI platform pricing page)
Key Reminder: The 50% off for Batch Chat is a limited-time promotion — after it ends, prices revert to standard rates (¥12/M input, ¥36/M output). The 50% off for Batch File is a permanent discount, always 50% of the standard price. Once the promotion ends, Batch File’s cost advantage becomes significant.

3. Batch Chat Explained

Batch Chat refers to synchronous real-time conversation API calls through the standard /v1/chat/completions endpoint. You send a message (or a set of messages), and the model generates and returns a response immediately. This is the most common API calling method.

3.1 Key Characteristics

Calling Method

Synchronous request-response pattern. The client sends an HTTP request and waits for the model to process and return results. Supports streaming output (stream=True).

Response Speed

Immediate, typically completing within seconds. Suitable for low-latency interactive scenarios.

API Endpoint

/v1/chat/completions

Pricing

Standard pricing (currently 50% off promo). Input ¥12/M tokens, Output ¥36/M tokens.

3.2 Supported Advanced Features

As the standard conversation API, Batch Chat supports all advanced features of Qwen3.7-Max:

Streaming Output: With stream=True, the model returns tokens incrementally as they are generated, creating a typewriter effect.

Thinking Mode: With enable_thinking=True, the model generates a chain-of-thought before providing the final answer.

Function Calling: Connect the model to external tools and systems, enabling Agent capabilities.

Structured Output: Ensure the model returns JSON strings conforming to the expected format.

Context Cache: Cache common prefixes of long contexts to reduce redundant computation.

4. Batch File Explained

Batch File is the asynchronous batch inference service provided by the Qianwen AI platform. Users package multiple requests into a JSONL file and upload it. The system processes them in a background queue and generates results within 24 hours. The cost is only 50% of real-time calling.[1]

4.1 How It Works

Prepare JSONL Upload File Create Batch Async Process Poll Status Download Results
Figure 2 Batch File asynchronous processing workflow

4.2 Input File Format

The input file is in JSONL format, with one independent request per line:

{"custom_id":"req-1","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen3.7-max","messages":[{"role":"user","content":"Summarize quantum computing in two sentences."}]}}
{"custom_id":"req-2","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen3.7-max","messages":[{"role":"user","content":"What is 2+2?"}]}}
File Limits: Each file can contain up to 50,000 requests, with a total size not exceeding 500 MB, and each line not exceeding 6 MB. All requests must use the same model, each custom_id must be unique and no longer than 256 characters. The url for all requests must be set to /v1/chat/completions.

4.3 Task Status Flow

validating in_progress finalizing completed

Terminal states include: completed, failed, expired, cancelled. Recommended polling interval: every 1-2 minutes.

4.4 Result File Format

After task completion, the system generates an output file (successful responses) and an error file (failure details, if any). Each line in the output file corresponds to the original request via custom_id:

{"id":"batch_req_xxx","custom_id":"req-1","response":{"status_code":200,"body":{"choices":[{"message":{"content":"..."}}],"usage":{...}}}}

5. Key Differences

Dimension Batch Chat Batch File
Calling Mode Synchronous real-time Asynchronous batch
Response Time Immediate (seconds) Within 24 hours
API Endpoint /v1/chat/completions /v1/batches + /v1/files
Input Format JSON request body JSONL file
Request Scale Single request Up to 50,000/file
Pricing Standard (50% off promo) Permanent 50% off
Input Price ¥12/M (promo ¥6/M) ¥6/M
Output Price ¥36/M (promo ¥18/M) ¥18/M
Result Retrieval Direct return Download result file
Streaming Supported Not supported
Context Limit 991K (input) / 131K (output) 256K (Batch mode)
Thinking Mode Supported (enable_thinking) Supported (body top-level)
Cache Stacking Supports Context Cache Not stackable
Use Case Interactive chat, real-time Q&A Large-scale batch, offline analysis
Table 2 Full comparison of Batch Chat vs Batch File

6. Calling Methods & Code Examples

6.1 Batch Chat Calling Method

Batch Chat uses the standard OpenAI SDK compatible interface, directly calling chat.completions.create():

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

# Batch Chat: synchronous real-time call
response = client.chat.completions.create(
    model="qwen3.7-max",
    messages=[{"role": "user", "content": "Summarize quantum computing in two sentences."}],
)

print(response.choices[0].message.content)

Supports streaming output and thinking mode:

# Streaming + Thinking mode
response = client.chat.completions.create(
    model="qwen3.7-max",
    messages=[{"role": "user", "content": "Prove that sqrt(2) is irrational"}],
    extra_body={"enable_thinking": True},
    stream=True,
)

for chunk in response:
    delta = chunk.choices[0].delta
    if hasattr(delta, "reasoning_content") and delta.reasoning_content:
        print(delta.reasoning_content, end="", flush=True)
    if hasattr(delta, "content") and delta.content:
        print(delta.content, end="", flush=True)

6.2 Batch File Calling Method

Batch File calling involves four steps: Upload File → Create Task → Query Status → Download Results.

  1. Step 1: Upload JSONL File file_object = client.files.create( file=Path(“input.jsonl”), purpose=”batch” ) print(file_object.id) # file-batch-xxx The returned file ID can be reused. No need to re-upload identical files.
  2. Step 2: Create Batch Task batch = client.batches.create( input_file_id=”file-batch-xxx”, endpoint=”/v1/chat/completions”, completion_window=”24h”, # 24h to 336h (14 days) metadata={ “ds_name”: “My batch job”, “ds_description”: “Batch processing task”, } ) print(batch.id) # batch_xxx endpoint must match the url in the input file. completion_window can be 24h to 336h (14 days).
  3. Step 3: Query Task Status batch = client.batches.retrieve(“batch_xxx”) print(batch.status) # validating → in_progress → finalizing → completed Recommended polling interval: every 1-2 minutes. Download results when status becomes completed.
  4. Step 4: Download Results content = client.files.content(“file-batch_output-xxx”) content.write_to_file(“result.jsonl”) Also download error_file_id for failed request details. Results are matched to original requests via custom_id.

Complete code example:

from openai import OpenAI
from pathlib import Path
import os, time

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

# Step 1: Upload file
file_object = client.files.create(
    file=Path("input.jsonl"),
    purpose="batch"
)
print(f"File ID: {file_object.id}")

# Step 2: Create batch task
batch = client.batches.create(
    input_file_id=file_object.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
    metadata={"ds_name": "Qwen3.7-Max batch job"}
)
print(f"Task ID: {batch.id}")

# Step 3: Poll status
while True:
    batch = client.batches.retrieve(batch.id)
    print(f"Status: {batch.status}")
    if batch.status in ("completed", "failed", "expired", "cancelled"):
        break
    time.sleep(60)

# Step 4: Download results
if batch.status == "completed":
    content = client.files.content(batch.output_file_id)
    content.write_to_file("result.jsonl")
    print("Results saved to result.jsonl")

6.3 Preparing JSONL Input File

Use a CSV-to-JSONL script to batch-generate input files:

import csv, json

def build_messages(content):
    return [{"role": "user", "content": content}]

with open("input.csv") as fin, open("input.jsonl", "w") as fout:
    for row in csv.reader(fin):
        request = {
            "custom_id": row[0],
            "method": "POST",
            "url": "/v1/chat/completions",
            "body": {
                "model": "qwen3.7-max",
                "messages": build_messages(row[1])
            }
        }
        fout.write(json.dumps(request, ensure_ascii=False) + "\n")

6.4 Using the Console

In addition to API calls, Batch File can be operated through the Qianwen AI platform console:

  1. Open the Batch API page Log in to the Qianwen AI platform console and navigate to the “Batch API” page.
  2. Create a batch inference task Fill in task name and description, set max wait time (1-14 days), upload the JSONL input file.
  3. Monitor and manage tasks View progress (processed/total requests) and status in the task list. Tasks in validating or in_progress status can be cancelled.
  4. Download results After status becomes completed, download output and error files from the task detail page.

7. Use Case Recommendations

⚡ Batch Chat Use Cases

Chatbots / Customer Service: Requires immediate response to user input, latency-sensitive.

Real-time Q&A Systems: User asks a question, system returns an answer instantly.

Interactive Coding Assistants: Code completion, real-time debugging suggestions.

Streaming Scenarios: Need typewriter effect with incremental display.

Agent / Function Calling: Model needs to make real-time decisions and call external tools.

Small-scale Requests: Low request volume, no need for batch processing.

📂 Batch File Use Cases

Large-scale Data Labeling: Batch processing tens of thousands of texts for classification, summarization, sentiment analysis.

Batch Translation: Translate large volumes of documents or paragraphs at once.

Document Batch Processing: Summarize, extract information, or convert formats for large document sets.

Offline Analysis: Data analysis and report generation without real-time requirements.

Bulk Content Generation: Generate product descriptions, marketing copy, etc. in bulk.

Cost-sensitive Scenarios: Large-scale processing with minimal Token cost.

8. Important Notes

Context Limit: In Batch mode, Qwen3.7-Max supports a maximum context of 256K tokens per request (vs. 991K for real-time calls). If a single request’s context exceeds 256K, it must be split or truncated.
Thinking Token Billing: Qwen3.7-Max has thinking enabled by default, generating additional chain-of-thought tokens billed at output prices. In the JSONL request body, enable_thinking is a top-level body parameter that must be at the same level as model, not inside extra_body. Consider explicitly setting enable_thinking: false to reduce costs if thinking is not needed.
Non-stackable Discounts: Batch discounts cannot be combined with Context Cache or other discounts. If a request hits Context Cache, it will be billed at the cache hit price, not the batch 50% off price.
File Storage Limits: Each account supports up to 10,000 files / 100 GB. Delete old files to free up space. Tasks are retained for only 30 days; expired tasks cannot be queried via the list API.
Rate Limits: Create 1,000/min (max 1,000 concurrent), query 1,000/min, list 100/min, cancel 1,000/min.
Test Model: Set model to batch-test-model and endpoint to /v1/chat/ds-test to validate file format without incurring inference costs. Limits: file ≤ 1 MB, ≤ 100 lines, max 2 concurrent tasks.