batch-api
它能做什么
它为一步完成的大量文件转换(例如翻译或改写)准备计划,并以实时价格的一半提交给批处理服务。结果会以新文件的形式稍后返回。适合能够等待数小时、以较低成本完成批量工作的人。
适用场景
- ✓当你需要对大量文件应用同一个单轮修改,并且可以等待数小时获得结果时。
- ✓当你想以较低成本对大量文件进行翻译、改写或提取内容时。
- ✓当你明确想要批处理定价,而不是实时运行时。
技能链接
https://github.com/QwenLM/qwen-code/blob/main/packages/core/src/skills/bundled/batch-api/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我想用更便宜的批处理选项,把所有产品描述文件翻译成西班牙语。我可以等待结果。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体准备一个描述文件和转换内容的计划文件,然后由一条命令提交任务。智能体本身不编写请求,结果会以新文件的形式返回。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
/batch-api — Agent-prepared Batch API workflow
Hard rule for this whole skill: if any qwen batch … command fails, or
the task turns out to be unsuitable, report what happened in a few lines and
stop (the one exception, a plan-field error from run, is in §4). Never fall back to doing the transform yourself in this session — the
user chose the half-price asynchronous path explicitly, and silently doing
the work at full realtime price is exactly what they opted out of. Offering
it as a choice ("I can do this realtime instead, at full price") is fine;
doing it without being asked is not.
The user explicitly chose async batch mode by typing /batch-api. This mode
trades latency for price: the provider bills Batch requests at 50% of the
realtime list price (with no context-cache benefit), and a job takes tens of
minutes to hours to finish (completion window 24h or more). Your job is to
turn the user's task into a small plan file that the deterministic
executor (qwen batch run) submits. You never write request JSONL by hand
and never call the Batch API yourself.
0. Check readiness before anything else
Run every qwen batch … command with the shell tool as
"${QWEN_CODE_CLI:-qwen}" batch … — QWEN_CODE_CLI names the CLI running
this session, so a plain qwen on PATH (possibly an older install without
these subcommands) is only the fallback. First make sure the CLI you reach
has them. Help output never calls a model:
"${QWEN_CODE_CLI:-qwen}" batch --help
If the output does not list batch run <plan>, the qwen it reached is an
older install without these subcommands — say so (the session's CLI is not on
PATH as qwen) and stop. Do not run any other batch command there: an older
CLI treats batch check as a prompt and answers it with a billed model call.
Then:
"${QWEN_CODE_CLI:-qwen}" batch check
It proves the credentials, endpoint and Batch route work and shows the model,
thinking mode and output limit a run would freeze from the user's current
settings — without a billed request. settings.batch.model can select a
separate modelProviders entry; its endpoint, envKey and generationConfig are
used without changing the conversation model. Do not edit authentication or
settings to work around a failed check. If it fails (for example Qwen OAuth, which has no Batch route),
relay its message and stop: do not read files or draft a plan the executor
cannot submit. Pass its note: lines on to the user.
1. Decide suitability honestly — this is your main job
Suitable: many independent, single-turn transforms whose input materials are fully available right now. Examples: translate a set of documents under a fixed style guide, rewrite files to a new format, summarize or extract structured data from each file of a set.
Unsuitable:
- Work that needs iterative feedback — debugging, run-test-fix loops, exploratory refactors. The next step there depends on results that do not exist yet.
- Chained tasks where one item's output is another item's input.
- A handful of items, or a task the user needs answered soon. Batch's wait buys nothing there.
If the task is unsuitable, say so in one short paragraph and stop.
2. Prepare lightly
The whole point is saving money, so do not burn the savings in preparation:
- Discover the target files with glob.
- Read only a small sample (2–3 files) to understand structure and edge cases. Do NOT deeply read every file — the executor reads and embeds the full contents mechanically at submission time.
- Draft the shared rules once: terminology, style, format constraints, and the exact output contract. The model that runs the batch sees only your plan — spell out everything it needs, including "return ONLY the complete transformed document, no commentary".
3. Write the plan file
Write one JSON file to .qwen/batch/plans/<slug>.json (<slug> = short
kebab-case task name) with the write_file tool:
{
"version": 1,
"name": "<slug>",
"kind": "document-transform",
"shared": {
"system": "optional role/system prompt",
"instructions": "the shared transform rules, terminology, output contract"
},
"items": [
{
"id": "intro",
"source": "docs/zh/intro.md",
"target": "docs/en/intro.md"
}
]
}
Rules:
idmust match[A-Za-z0-9][A-Za-z0-9_-]{0,59}(1–60 characters) and be unique per item; it becomes part of the provider-sidecustom_id.- Paths are relative to the curr
常见问题
便宜多少?
批处理服务按实时挂牌价的一半计费,但不享受上下文缓存的优惠。
一个任务需要多长时间?
任务可能需要几十分钟到数小时,完成时间窗口为 24 小时或更长。
如果批处理命令失败会怎样?
智能体会报告发生了什么并停止,而不会悄悄地以全额实时价格继续完成工作。
详情
作者的原始描述
Prepare a many-file, single-turn transform (translate, rewrite, extract) as a plan and submit it to the asynchronous, half-price DashScope Batch API; results are delivered as new files hours later. Invoke explicitly with /batch-api.
repo: QwenLM/qwen-code
热度
- GitHub 星标
- 29k
- 排名
- #9776
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
codegraph
29k帮你的智能体通过调用图、依赖关系、无用代码、热点和语义搜索来分析已建立索引的代码库。
qwen-code-claw
29k帮你的智能体把编程任务交给 Qwen Code,例如理解代码库、修复缺陷、重构代码或生成新项目。
structured-debugging
29k教你的智能体用一步一步的方法调试疑难缺陷:先提出假设,再添加有针对性的检查,验证后找出真正的原因,然后才修复。
tmux-real-user-testing
29k帮你的智能体在 tmux 中像真实用户一样测试终端应用,并为每一步操作保存带屏幕截图的可读步骤日志。