Skip to content
Back to skills

Batch Api Orchestrator

ASecurity

Decides batch vs realtime for bulk LLM work, prices both, and plans chunking, idempotency keys and partial-failure retries. Use when running evals, backfills, embeddings or bulk extraction through a provider batch API.

  • 1,271 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 6, 2026
ai-agentspythonrustgobashapidocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add borghei/Claude-Skills --skill batch-api-orchestrator --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Batch Api Orchestrator?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Batch Api Orchestrator
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/borghei-batch-api-orchestrator/badge)](https://www.skillsdirectory.com/skills/borghei-batch-api-orchestrator)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: batch-api-orchestrator
description: >
  Decides batch vs realtime for bulk LLM work, prices both, and plans chunking, idempotency keys
  and partial-failure retries. Use when running evals, backfills, embeddings or bulk extraction
  through a provider batch API.
license: MIT + Commons Clause
metadata:
  version: 1.0.0
  author: borghei
  category: engineering
  domain: ai-engineering
  updated: 2026-11-08
  tags: [batch-api, llm, cost-optimization, throughput, async]
---

# Batch API Orchestrator

> **Category:** Engineering
> **Domain:** AI Engineering

## Overview

Decide when to run LLM work through an asynchronous batch API versus realtime/streaming, then design the job so it is cheap, idempotent, and resilient to partial failure. Batch APIs typically cost roughly half of realtime in exchange for higher latency (results arrive over minutes to hours, not milliseconds), which makes them ideal for evals, backfills, embeddings, and bulk classification/extraction — and wrong for anything a human is waiting on. This skill is model- and vendor-agnostic: it reasons about the batch *pattern*, not any one provider's API.

## When to Use

- A job of thousands of LLM requests where no person waits on each answer (evals, backfills, embeddings, bulk classification).
- Choosing between a provider's batch API and realtime calls on cost and latency.
- Designing chunk sizes, retries and reconciliation for a batch job before writing client code.

## Clarify First

Before recommending or designing a batch job, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.

- **Latency tolerance:** is a human waiting (interactive), or can results land in minutes/hours? (sets `--latency-tolerance` and the batch-vs-realtime verdict).
- **Volume & token shape:** how many requests, and the average input/output tokens each? (sets `--requests`, `--avg-input-tokens`, `--avg-output-tokens` for the cost estimate).
- **Pricing & discount:** your realtime per-token prices and the batch discount your vendor offers (sets `--realtime-input-price`, `--realtime-output-price`, `--batch-discount`; there are no default prices).

Ask about the two or three inputs that matter most for this request. If the user says "just draft it," proceed and list your assumptions.

## Quick Start

Run from the repository root.

```bash
# 1. Should this be batch or realtime, and what does it cost? (prices are yours, per 1M tokens)
python3 engineering/batch-api-orchestrator/scripts/batch_cost_estimator.py \
  --input engineering/batch-api-orchestrator/assets/sample_job.json

# 2. Plan chunking / idempotency / retries, checked against your provider's request limit
python3 engineering/batch-api-orchestrator/scripts/batch_job_planner.py \
  --total-items 50000 --max-batch-size 10000 --provider-max-requests 100000
```

Real output of command 1:

```
Batch vs. Realtime Cost Estimate
Read: 50,000 requests, 800 in / 200 out tokens each, $3.0 / $15.0 per 1M, discount 50%, tolerance hours
Realtime: $270.00  (input $120.00, output $150.00)
Batch:    $135.00
Saving if batched: $135.00 (50.0%)
PASS: batch recommended, saves $135.00
```

## Tools Overview

| Tool | Purpose | Key Flags |
|------|---------|-----------|
| `scripts/batch_cost_estimator.py` | Compare realtime vs batch cost and decide batch or realtime from latency tolerance | `--input job.json` or `--requests`, `--avg-input-tokens`, `--avg-output-tokens`, `--realtime-input-price`, `--realtime-output-price`, `--batch-discount`, `--latency-tolerance`, `--format text\|json` |
| `scripts/batch_job_planner.py` | Chunking, idempotency-key, retry and reconciliation plan; flags oversize or single-chunk jobs | `--total-items`, `--max-batch-size`, `--provider-max-requests`, `--retry-policy`, `--max-retries`, `--format text\|json` |

Python 3 standard library only. `--json` remains an alias for `--format json`. The estimator has no
default prices or discount: you must supply all of them, so the result is never based on a guess.
The `--input` file is a JSON object with the flag names in snake_case (see `assets/sample_job.json`).

## Exit codes

| Code | Meaning |
|------|---------|
| 0 | Estimator: batch is appropriate and saves money. Planner: plan is sound. |
| 1 | Findings. Estimator: workload is `realtime` or the discount is 0, so stay on realtime. Planner: batch size above `--provider-max-requests`, the whole job in one chunk of 1,000+ items (internal heuristic), or retry policy `none`. Each finding quotes the input and gives the fix. |
| 2 | Unusable input: missing price or count, zero or negative counts, discount outside [0, 1), unreadable or non-object `--input` file. One-line message on stderr. |

Samples: `assets/sample_job.json` (exit 0), `assets/flawed_job.json` (exit 1), `assets/malformed_job.json` (exit 2); `assets/contract.json` lists all runs.

### Provider limits to check (as of 2026-11, from the providers' batch API docs; confirm before sizing a job)

| | Anthropic Message Batches | OpenAI Batch API |
|---|---|---|
| Discount vs realtime | 50% | 50% |
| Max per batch | 100,000 requests or 256 MB | 50,000 requests per input file, input file up to 200 MB |
| Completion window | most finish within an hour; expire after 24 h | 24 h window |
| Result retention | 29 days | output file deleted 30 days after the batch completes (set 1 hour to 30 days with `output_expires_after`) |
| Prompt caching | stacks with the batch discount | check current docs |

Use these to set `--max-batch-size`, `--provider-max-requests` and `--batch-discount`. Limits change, so read the provider's
batch documentation before sizing a production job.

**Done when:**
1. The cost comparison used your provider's current prices and discount.
2. Every request carries an idempotency key and every result is joined back to its request by id.
3. A small pilot batch (a few hundred items) completed, and failed items were retried on their own.

## Workflows

### 1. Decide batch vs realtime, then size the cost

1. Gather volume and token shape (`--requests`, `--avg-input-tokens`, `--avg-output-tokens`).
2. Plug in *your* vendor prices and batch discount — never assume them.
3. Run `batch_cost_estimator.py` with the real `--latency-tolerance` (`realtime`, `minutes`, `hours` or `days`).
4. Read the verdict: if work is interactive, the tool recommends realtime regardless of savings; otherwise it quantifies the batch savings.
5. Sanity-check against the decision tree in `references/batch-patterns-and-decision-tree.md`.

### 2. Design a resilient bulk job

1. Run `batch_job_planner.py` with `--total-items`, `--max-batch-size`, and a `--retry-policy`.
2. Adopt the generated idempotency-key scheme so re-submitting a chunk never double-charges or double-writes.
3. Wire result reconciliation: match every output back to its request id, and collect the unmatched into a dead-letter set.
4. Apply the partial-failure handling (retry only failed items, never the whole batch) from the reference.
5. Choose polling vs callback for completion, per the reference guidance.

## Scope & Limitations

**In Scope:**
- The batch versus realtime decision, based on latency tolerance (`realtime`, `minutes`, `hours`, `days`)
- Cost comparison of realtime and batch runs with `batch_cost_estimator.py` from request volume, average token counts, the user's own per-token prices and batch discount
- Job plans from `batch_job_planner.py`: chunk sizes, an idempotency-key scheme, retry policy (exponential, fixed or none) and partial-failure handling
- Job design guidance from the references: reconciliation by request id, dead-letter sets, polling versus callbacks, chunk sizing and break-even modelling

**Out of Scope:**
- Submitting, polling or downloading batch jobs; the skill does not call any vendor API or include client code for one
- Wider LLM cost work such as token counting, caching and model routing (see `engineering/llm-cost-optimizer/`)
- Designing the evaluations that often run as batch jobs (see `engineering/agentic-evaluation-framework/` and `engineering/agent-harness/`)
- Streaming and interactive request handling

**Important Caveats:**
- `batch_cost_estimator.py` has no built-in prices; the estimate is only as good as the current vendor prices and discount you supply.
- The roughly half-price batch discount is a rule of thumb. Discounts, maximum batch sizes, completion windows and result retention differ by vendor and change over time.
- Estimates assume every request costs the average token count. Long-tail inputs, retries and failed items add cost the model does not show.

## Anti-Patterns

### Batching interactive work
**Mistake:** Sending user-facing requests through the batch API to save money.
**Why it happens:** The discount is large and the latency cost is invisible in a spreadsheet.
**Instead:** Batch only work nobody waits on. `batch_cost_estimator.py` recommends realtime whenever `--latency-tolerance realtime` is set.

### One giant batch
**Mistake:** Submitting a whole backfill as a single maximum-size batch.
**Why it happens:** Fewer jobs feel simpler to track.
**Instead:** Chunk below the provider limit so a bad prompt or schema error costs one chunk, not the run. Pilot a small chunk first.

### Trusting output order
**Mistake:** Zipping results to inputs by position.
**Why it happens:** Small tests come back in order.
**Instead:** Join on the request id you set (`custom_id` or equivalent) and send unmatched results to a dead-letter set.

## Files

- `scripts/batch_cost_estimator.py` — realtime vs batch cost and a batch/realtime verdict from latency tolerance.
- `scripts/batch_job_planner.py` — chunk plan, idempotency-key scheme and retry plan.
- `references/` — decision tree and job design; cost and throughput economics.

## Reference Documentation

- **[references/batch-patterns-and-decision-tree.md](references/batch-patterns-and-decision-tree.md)** — when-to-batch decision tree; job design (idempotency keys, partial failures, reconciliation, polling vs callback); fitting use cases (evals, backfills, embeddings, bulk classification/extraction); and anti-patterns such as batching interactive requests.
- **[references/cost-and-throughput-economics.md](references/cost-and-throughput-economics.md)** — the cost/throughput tradeoff in depth: the ~half-cost rule of thumb, throughput vs latency, queueing, chunk sizing, and how to model the break-even between a faster realtime path and a cheaper batch path.

## Common Patterns

- **Batch the patient, stream the impatient** — if no human is blocked on the result, default to batch for the cost win; reserve realtime/streaming for interactive UX.
- **Idempotency key per item** — derive a stable key (e.g. hash of input + job version) so retries and re-submissions are safe and never double-billed.
- **Retry the item, not the batch** — on partial failure, re-enqueue only the failed request ids; resubmitting the whole chunk wastes money and re-runs successes.
- **Reconcile by request id** — never rely on output ordering; join results back to inputs by id and route the unmatched to a dead-letter queue for inspection.
- **Right-size chunks** — split by the vendor's max-batch limit and by your own blast-radius tolerance, not into one giant job whose failure is all-or-nothing.
- **Embeddings and evals are the sweet spot** — large, latency-insensitive, embarrassingly parallel workloads capture the full batch discount with the least risk.

Files in this skill

  • SKILL.md5.9 KB
  • references/batch-patterns-and-decision-tree.md6 KB
  • references/cost-and-throughput-economics.md4.6 KB
  • scripts/batch_cost_estimator.py5.9 KB
  • scripts/batch_job_planner.py6.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.