Batch APIs trade latency for price: submit jobs asynchronously, get discounted token rates hours later. Ideal for offline evals, backfills, and nightly reports—not live chat.
Another price-tier lever alongside caching and model routing.
Related foundations: recount tokens with tiktoken (Vol. 12) and keep payloads inside the context window (Vol. 11).
Learning Objectives
By the end of this lesson, students should be able to:
- Identify workloads fit for batch vs real-time.
- Estimate discount savings vs interactive endpoints.
- Design idempotent job submission and result pickup.
- Handle partial failures in large batches.
- Keep PII/retention policies intact for delayed jobs.
- Avoid batching user-facing interactive paths.
Batch API discounts are reduced per-token (or per-job) prices for asynchronous, deferred inference with weaker latency SLOs than synchronous chat APIs.
| Good for batch | Keep real-time | Reason |
|---|---|---|
| Eval suites | Chat UX | Hours-ok vs ms-needed |
| Corpus labeling | Tool loops in agents | Throughput vs interactivity |
| Nightly summaries | Fraud stop-the-line | Delay tolerance |
| Prompt A/B offline | Live retrieval chat | SLO mismatch |
Code: Discount Compare
Realtime API
- Low latency
- Full price
- Interactive
Batch API
- Deferred
- Discounted
- Offline scale
Hybrid
- Chat live + batch evals
- Two pipelines
- Common prod pattern
Strengths
- Material COGS reduction
- Smooths provider load
- Great for eval/backfill
Tradeoffs
- Not for chat SLOs
- Operational complexity
- Delayed error discovery
“We will batch the customer’s chat replies overnight to save money.” Interactive products need synchronous paths; batch is for work that can wait.
Knowledge Check
- Short Answer: What do you trade for batch discounts? Answer: Latency / immediacy (async completion).
- True/False: Live chat should default to batch APIs. Answer: False.
- Multiple Choice: Strong batch fit: (a) offline evals, (b) typing indicators, (c) WebSocket pings. Answer: (a).
- Short Answer: Name an ops concern for batches. Answer: Partial failures, retries, idempotency, retention.
- True/False: Discounts still meter tokens. Answer: True.
- Multiple Choice: Hybrid architecture: (a) all batch, (b) realtime UX + batch offline, (c) no metering. Answer: (b).
- Short Answer: Why idempotent job IDs? Answer: Safe retries without double billing/work.
- Short Answer: How does estimation change? Answer: Apply discount factor to the same token formula.
- Multiple Choice: Fraud stop-the-line scoring: (a) batch overnight, (b) realtime, (c) ignore tokens. Answer: (b).
- True/False: Batch eliminates the need for quotas. Answer: False.
Key Takeaways
- Batch = cheaper async tokens.
- Reserve it for delay-tolerant work.
- Engineer idempotent pickup and failure handling.
- Compare savings explicitly in estimators.
- Next: Model Tiering for Cost.
Lab: Split a workload list into batch vs realtime; estimate 30-day savings at 50% discount.
Discussion: What product copy sets user expectations when reports are batch-generated?
Recap: Batch discounts buy dollars with time. Continue with Model Tiering.