Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Online inference | A user or program is waiting for each answer; latency SLOs apply. |
| Offline / batch inference | A large set of requests whose answers are needed by a deadline (an hour, a day), not instantly. |
| Batch API | A provider endpoint that accepts a file of requests and returns a file of results later, at a discount. |
| JSONL | A text file with one JSON object per line; the usual format for batch requests and results. |
| Completion window | The time a provider promises to finish a batch in (24 hours at OpenAI and Anthropic). |
| Trough | The low-traffic hours of an online fleet, when GPUs sit partly idle. |
| Preemption | Pausing or evicting lower-priority work so higher-priority work can run (17.c). |
| Idempotent | Safe to run twice: re-running a shard produces the same results without duplicates. |
1. What is it?#
A large and growing share of inference has nobody waiting on it:
- evaluation runs over benchmark suites and regression sets;
- synthetic data and distillation data for training;
- classification, extraction and summarisation of document archives;
- embedding backfills for search;
- RL rollouts (27.d), which are batch inference with a trainer as the customer.
Two ways to run it:
| Provider batch API | Self-hosted offline | |
|---|---|---|
| How | Upload JSONL, poll, download results | vLLM’s LLM.generate, vllm run-batch, or a data framework such as Ray Data driving vLLM |
| Price | 50% of the synchronous price at OpenAI and Anthropic | Your GPU-hours, possibly ones you already paid for |
| Control | Model, prompt, a few parameters | Everything: engine flags, batch sizes, scheduling, hardware |
Facts checked on 13 November 2026.
2. Why does it matter?#
Without a latency SLO, the engine can run at the batch size that maximises throughput instead of the one that keeps inter-token latency low (2.d). The same GPU produces several times more tokens per hour. And an online fleet is sized for its peak, so for much of the day it has idle capacity that batch work can use almost for free. A principal engineer who moves the right work offline, and fills the troughs with it, often saves more than any kernel optimisation.
3. Simple analogy#
A restaurant kitchen. Lunch and dinner orders (online) must come out in minutes. Between services, the same cooks and ovens prepare tomorrow’s sauces and bread (batch): large pots, no rush, cheaper per portion. If a surprise lunch crowd arrives, the bread waits. A catering company (provider batch API) does the same for you at half price if you can wait until tomorrow.
4. Tiny example: filling the troughs#
A fleet of 100 replicas sized for an evening peak, with 10 kept free for bursts and failover. Online replicas produce 15,000 tokens per second at their SLO; the same replica running batch work produces 40,000 (illustrative). Preempting batch work for online spikes loses 10% of trough time.
hour online replicas free for batch batch Mtok this hour
00:00 70 20 2592
03:00 40 50 6526
06:00 15 75 9673
09:00 11 79 10191
12:00 30 60 7776
15:00 60 30 3842
18:00 85 5 695
21:00 89 1 177
fleet cost per day: $153600; online work uses 50% of replica-hours
trough replica-hours: 960; batch tokens that fit: 124.4 billion
dedicated batch replicas would cost $0.44 per million tokensHalf the fleet’s hours are idle. The troughs hold 124 billion batch tokens a day; buying the same work on dedicated replicas would cost about $55,000 a day at $0.44 per million tokens. The catch is operational: batch work must yield instantly when online traffic returns.
5. Technical explanation#
Provider batch APIs#
| OpenAI Batch API | Anthropic Message Batches | |
|---|---|---|
| Discount | 50% versus synchronous | 50% |
| Completion window | 24h only; “often sooner” | Most batches within 1 hour; expire if not done in 24 hours |
| Size limits | 50,000 requests, 200 MB input file; 2,000 batches per hour | 100,000 requests or 256 MB, whichever first |
| Endpoints | /v1/responses, /v1/chat/completions, /v1/embeddings, /v1/completions, /v1/moderations, image generation and edits | Messages (including tools, vision, thinking) |
| Results kept | 30 days by default (configurable from 1 hour to 30 days) | 29 days |
| Rate limits | Separate pool: a cap on queued prompt tokens per model, not the per-model synchronous limits | Limits on HTTP requests and on queued requests in batches |
| Status values | validating, in_progress, finalizing, completed, failed, expired, cancelling, cancelled | processing_status goes from in_progress to ended; request_counts reports processing, succeeded, errored, canceled and expired |
Batches that expire are not all-or-nothing: completed requests are returned (and charged), the rest are cancelled. Discounts stack with prompt caching, but a batch can run longer than a 5-minute cache entry lives; Anthropic’s documentation suggests the 1-hour cache for batches with shared context (27.b).
There is a middle ground at OpenAI: flex processing (service_tier: "flex") runs synchronous
requests at Batch API rates on spare capacity, may return 429 Resource Unavailable (not charged)
when there is none, and needs long client timeouts. It suits work that can wait minutes but not a
day.
Self-hosted: three ways to drive vLLM#
| Tool | Shape | Good for |
|---|---|---|
LLM.generate / LLM.chat (Python) | One process, a list of prompts in, outputs out; the engine schedules them all | Notebooks, evals, single-node jobs |
vllm run-batch -i in.jsonl -o out.jsonl --model ... | OpenAI batch-format files, local or HTTP | Reusing OpenAI batch files on your own GPUs. v0.32.0 accepts /v1/chat/completions, /v1/embeddings, /v1/audio/transcriptions, /v1/audio/translations, /score and /rerank lines |
Ray Data with ray.data.llm (vLLMEngineProcessorConfig, build_processor) | A dataset streamed through a pool of vLLM replicas, with concurrency, batch_size and engine_kwargs | Multi-node jobs over large datasets, with preprocessing and postprocessing |
Tuning for throughput instead of latency#
- Let the batch grow. Raise
max_num_seqsandmax_num_batched_tokens(17.b) until decode is compute-bound or KV memory is full; there is no inter-token latency to protect. - Order the input. Group requests that share a prefix (same document, same instructions) so the prefix cache hits (17.f), and bucket by expected output length to reduce stragglers at the end of the job.
- Prefer fewer, larger replicas only if needed. Data parallelism (many independent replicas) is simplest and scales linearly for batch work; use tensor parallelism only to fit the model or its KV cache.
- Quantize more aggressively if quality allows: FP8 or FP4 weights and KV raise throughput, and batch evaluation can measure the quality cost on the same data.
- Cap output length. One runaway generation holds a slot until
max_tokens.
Sharing a fleet with online traffic#
Two patterns:
- Priority on the same engine. Run vLLM with priority scheduling (17.c); online requests get high priority, batch requests low. The engine preempts low-priority requests when memory runs short. Simple, but batch work still occupies slots and adds to every step’s batch, so online inter-token latency rises a little.
- Elastic pools. The platform moves whole replicas between an online pool and a batch pool as load changes (21.l, 23.d). Cleaner isolation; needs fast model loading or sleeping replicas (20.h) and a batch system that tolerates replicas disappearing.
Either way, batch jobs must be preemptible and resumable: shard the input, write results per shard, make shards idempotent, and record progress so a killed worker loses minutes, not hours. The same design lets batch jobs run on spot or pre-emptible cloud instances.
Choosing provider batch versus self-hosted#
- Provider batch wins when you need a model you do not host, the volume is irregular, or your own fleet has no troughs.
- Self-hosted wins when you already own capacity with troughs, need an open model, need full control (logprobs, custom sampling, long outputs), or run continuously at high volume (23.c has the cost model).
6. Under the hood: the trough model#
// batchfill.go — how much offline work fits in the troughs of an online fleet?
package main
import (
"fmt"
"math"
)
func main() {
const (
fleet = 100.0 // replicas, sized for the evening peak
reserve = 10.0 // replicas kept free for bursts and failover
onlineTokS = 15_000.0 // per replica, at the latency SLO
offlineTokS = 40_000.0 // per replica, no SLO: big batches
replicaUSDh = 64.0
preemptLoss = 0.10 // share of trough time lost to preempting batch work
)
demand := func(h float64) float64 { // online load in replicas, peak at 20:00
return 50 + 40*math.Cos(2*math.Pi*(h-20)/24)
}
fmt.Println("hour online replicas free for batch batch Mtok this hour")
var idleH, batchTok, onlineTok float64
for h := 0; h < 24; h++ {
d := demand(float64(h))
free := math.Max(0, fleet-reserve-d)
tok := free * offlineTokS * 3600 * (1 - preemptLoss)
idleH += free
batchTok += tok
onlineTok += d * onlineTokS * 3600
if h%3 == 0 {
fmt.Printf("%02d:00 %15.0f %15.0f %21.0f\n", h, d, free, tok/1e6)
}
}
day := fleet * 24 * replicaUSDh
fmt.Printf("\nfleet cost per day: $%.0f; online work uses %.0f%% of replica-hours\n",
day, 100*onlineTok/onlineTokS/3600/(fleet*24))
fmt.Printf("trough replica-hours: %.0f; batch tokens that fit: %.1f billion\n", idleH, batchTok/1e9)
fmt.Printf("dedicated batch replicas would cost $%.2f per million tokens\n",
replicaUSDh/(offlineTokS*3600/1e6))
}Output:
hour online replicas free for batch batch Mtok this hour
00:00 70 20 2592
03:00 40 50 6526
06:00 15 75 9673
09:00 11 79 10191
12:00 30 60 7776
15:00 60 30 3842
18:00 85 5 695
21:00 89 1 177
fleet cost per day: $153600; online work uses 50% of replica-hours
trough replica-hours: 960; batch tokens that fit: 124.4 billion
dedicated batch replicas would cost $0.44 per million tokensThe demand curve is a single daily wave for clarity. Real fleets also have weekly cycles, regional offsets and bursts; global fleets with users in several time zones have shallower troughs.
7. Performance implications#
- Throughput per GPU rises with batch size until compute-bound or KV-bound; offline jobs should sit at that knee, which can be 2–4 times the tokens per second of a latency-bound online replica.
- Stragglers end jobs late. The last few long generations of a job run at tiny batch sizes; bucket by length or start long items first.
- Prefix ordering is free speed. Sorting a million extraction requests by document can turn most of the prefill into cache hits.
- Batch work on online replicas costs online latency. Even at low priority it enlarges every step; measure inter-token latency with and without it.
8. Production implications#
- Classify every workload as online, near-line (minutes; flex-style) or offline (hours), and route it accordingly; teams default to online because it is easiest.
- Run a batch platform: a queue of jobs with deadlines and priorities, sharded inputs, idempotent writes, progress tracking and cost attribution per team.
- Make preemption cheap: sleeping replicas, fast loading, and short shards.
- Account honestly: trough capacity is cheap only while it is genuinely spare; once batch work drives fleet growth, charge it the full rate.
- Version the inputs and the model for every batch run; evals and synthetic data must be reproducible.
9. Common mistakes#
- Running nightly evals and data generation through the online API at full price and latency priority.
- Writing one giant output file at the end, so a crash at 95% loses everything.
- Running batch work on online replicas without priorities, and blaming the online regression on “traffic”.
- Leaving
max_num_seqsat online defaults for offline jobs. - Ignoring prefix order in extraction jobs over long shared documents.
- Assuming a batch API returns everything or nothing on expiry.
10. Hands-on exercise#
A. Same file, two engines. Write 1,000 chat requests as OpenAI batch JSONL. Run them with
vllm run-batch on one GPU, then send the same requests to a vllm serve instance with 32
concurrent clients. Compare total time and tokens per second.
B. Batch-size sweep. With LLM.generate, sweep max_num_seqs from 16 to 1,024 on a fixed
prompt set. Plot output tokens per second and find the knee.
C. Prefix order. Build 10,000 extraction requests over 200 long documents. Run them shuffled, then sorted by document. Compare prefill tokens computed and wall time.
D. Troughs. Replace the demand curve in batchfill.go with a week of your own fleet’s hourly
load. How many batch tokens fit, and how much reserve do you need?
11. Interview questions#
- Why does the same GPU produce more tokens per hour offline than online?
- When would you use a provider batch API instead of your own idle GPUs, and the reverse?
- How do you run batch work on an online fleet without hurting online SLOs?
- Design a system to run 500 million extraction requests per day, resumably.
- What makes the end of a batch job slow, and how do you fix it?
- Explain flex processing and when it beats both batch and standard requests.
12. Further reading#
Checked on 13 November 2026.
- OpenAI — Batch API guide
- OpenAI — Flex processing
- Anthropic — Batch processing (Message Batches API)
- Ray Data — Working with LLMs (
ray.data.llm) - vLLM v0.32.0 — OpenAI-compatible server
- Batching in servers: 20.d. Priority scheduling in vLLM: 17.c. Cost per token: 23.c.