用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/UitbreidenOS/UitKit --skill claude-batch命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Guidelines and instructions for Agent execution state rollback rules
Guidelines and instructions for Agent execution step counters limits
Guidelines and instructions for Agent execution timeout limits setups
基于 SOC 职业分类
正在显示 SKILL.md
| name | claude-batch |
| description | Run large-scale batch processing with Claude API for bulk text analysis, classification, and generation |
Processing large volumes of prompts (10 or more), non-time-sensitive workloads, or when the user wants to reduce API costs for bulk operations like document processing, evaluations, or dataset annotation.
Each item in the batch has:
custom_id: your identifier — used to match results back to inputsparams: standard Messages API parameters (model, max_tokens, messages, system, tools, etc.)import anthropic
client = anthropic.Anthropic()
requests = [
{
"custom_id": f"doc-{i}",
"params": {
"model": "claude-opus-4-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": f"Summarize this document: {doc}"}
],
},
}
for i, doc in enumerate(documents)
]
batch = client.messages.batches.create(requests=requests)
print(batch.id) # msgbatch_...
print(batch.processing_status) # "in_progress"
import time
def wait_for_batch(batch_id: str) -> anthropic.MessageBatch:
while True:
batch = client.messages.batches.retrieve(batch_id)
if batch.processing_status == "ended":
return batch
print(f"Status: {batch.processing_status} — waiting 30s")
time.sleep(30)
batch = wait_for_batch(batch.id)
print(f"Request counts: {batch.request_counts}")
# RequestCounts(canceled=0, errored=1, expired=0, processing=0, succeeded=199)
# Results stream as JSONL — iterate without loading all into memory
for result in client.messages.batches.results(batch.id):
if result.result.type == "succeeded":
message = result.result.message
print(f"{result.custom_id}: {message.content[0].text[:100]}")
elif result.result.type == "errored":
error = result.result.error
print(f"{result.custom_id}: ERROR {error.type} — {error.message}")
elif result.result.type == "expired":
print(f"{result.custom_id}: EXPIRED — resubmit")
| Type | Meaning | Action |
|---|---|---|
succeeded | Normal completion | Use result.message |
errored | API-level error (invalid params, content policy) | Log and skip or retry |
expired | 24-hour window elapsed before processing | Resubmit the request |
client.messages.batches.cancel(batch.id)
# Already-completed requests are not rolled back — partial results may exist
| Use case | Typical batch size | Est. turnaround |
|---|---|---|
| Document summarization | 100–5,000 | Minutes–hours |
| Eval run over test set | 500–10,000 | Hours |
| Dataset annotation | 1,000–10,000 | Hours |
| Bulk content generation | 50–2,000 | Minutes–hours |
For ongoing high-volume workloads, combine a job queue with the batch API:
batch_id → custom_id[] mapping in a databaseprocessing_status == "ended"Annotating 2,000 customer support tickets with sentiment and category:
tickets = load_tickets_from_db() # 2,000 rows
requests = [
{
"custom_id": str(ticket["id"]),
"params": {
"model": "claude-haiku-4-5",
"max_tokens": 64,
"system": "Respond with JSON only: {\"sentiment\": \"positive|neutral|negative\", \"category\": \"billing|technical|general\"}",
"messages": [{"role": "user", "content": ticket["text"]}],
},
}
for ticket in tickets
]
batch = client.messages.batches.create(requests=requests)
batch = wait_for_batch(batch.id)
results = {}
for result in client.messages.batches.results(batch.id):
if result.result.type == "succeeded":
import json
data = json.loads(result.result.message.content[0].text)
results[result.custom_id] = data
save_annotations_to_db(results)
# Total cost: ~50% less than running 2,000 synchronous calls