Offline Batch Inference for LLM Workloads in October 2026: Chunking, Custom IDs, and Reconciling Partial Failures Without Duplicate Spend
Not every LLM call needs an answer in two seconds. Nightly classification of support tickets, re-tagging a product catalog, generating embeddings for an archive, running an evaluation suite: all of these can wait minutes or hours. Most major model providers offer a batch interface for exactly this kind of work, typically at a discounted price in exchange for a looser completion window. This post covers how to use that kind of interface safely: what to send, how to split it, how to track it, and how to handle the partial failures that always show up at scale.
Check your provider's current documentation for exact limits, discounts, and completion windows. Those numbers differ by vendor and change over time, so this article avoids quoting them and focuses on the design that works regardless.
When a batch API is the right tool
A batch job trades latency for cost and throughput. It fits when all of the following are true:
- No user is waiting on the result. A person staring at a spinner is the signal to stay on the normal API.
- The requests are independent. Each one can be answered without the output of another.
- You can tolerate a delay of hours, and you have a plan for when it is later than expected.
- The work is large enough to matter. A batch of ten requests adds orchestration for almost no savings.
If your job needs the result of request A to build request B, split it into stages. Each stage is its own batch, and the output of one becomes the input file of the next.
The basic shape of a batch workflow
Provider details differ, but the flow is nearly always the same:
- Write requests to a file, usually one JSON object per line, each with a unique custom ID you control.
- Upload the file and create a batch job that references it.
- Poll the job status, or receive a callback if the provider supports one.
- When it finishes, download the output file and an error file, if any.
- Match results to your records using the custom ID, not the line order.
Step 5 is the one people get wrong. Results are not guaranteed to come back in the order you sent them. The custom ID is the only reliable join key.
Design your custom IDs on purpose
The custom ID is more than a label. It is how you make the whole pipeline idempotent. A good ID encodes enough to tell you what the request was for and which version of the work it belongs to:
ticket-48213:classify:prompt-v7
With an ID like this you can answer practical questions later. Has this ticket already been classified with this prompt version? Which results are stale because the prompt changed? If you re-submit a failed slice, you will not create duplicates, because your own database already knows which IDs have a stored result.
Split large jobs into bounded chunks
Providers cap the number of requests and the file size per batch. Even below those caps, one giant batch is a bad idea. If one request in a million is malformed, or the job expires, you want the blast radius to be small.
A sensible approach:
- Chunk by a fixed request count that stays well under the provider's cap.
- Keep chunks roughly similar in size so they finish at similar times.
- Record each chunk in a table with its own state:
pending,submitted,completed,partially_failed,expired. - Limit how many chunks are in flight at once, since providers may apply separate quotas to queued batch tokens.
A minimal tracking table
You do not need a workflow engine to start. Two tables are enough: one for chunks and one for per-request results.
batch_chunks(
chunk_id, provider_batch_id, status,
request_count, submitted_at, completed_at
)
batch_results(
custom_id, chunk_id, status, -- ok | error | missing
output_text, error_code, attempts
)
The attempts column matters. It lets you cap retries so a single poisonous input does not get resubmitted forever.
Polling without wasting effort
Batch jobs are slow by design, so a tight polling loop is pointless. Poll every few minutes at first, then back off. Store the last known status so a restart of your worker does not lose track of in-flight jobs. The provider batch ID in your chunk table is what lets a fresh process pick up where the previous one left off.
def poll_chunks():
for chunk in db.chunks(status="submitted"):
job = client.batches.retrieve(chunk.provider_batch_id)
if job.status in ("completed", "expired", "failed", "cancelled"):
handle_finished(chunk, job)
# otherwise leave it; next run checks again
Run this from a scheduled task rather than a long-lived loop. It is easier to reason about and survives deploys.
Handling partial failure
A finished batch is not necessarily a successful batch. Expect three kinds of outcomes inside one job:
- Succeeded. Valid output, ready to validate and store.
- Errored. The provider reports an error for that request, often in a separate error file. Some are retryable, such as a transient server error, and some are not, such as an invalid request.
- Missing. Your custom ID appears in neither file. This happens when a batch expires before every request is processed.
Reconcile by set difference. Take the full list of custom IDs you submitted, subtract the ones with stored results, and what remains is your retry set. Mark non-retryable errors as terminal, and put the rest into the next chunk.
submitted = set(chunk.custom_ids)
done = set(r.custom_id for r in ok_results)
failed = set(r.custom_id for r in error_results)
missing = submitted - done - failed
retry = [i for i in failed if is_retryable(i)] + list(missing)
terminal = [i for i in failed if not is_retryable(i)]
Validate outputs like you would a live call
Cheaper and slower does not mean looser. If your live path validates JSON against a schema, the batch path should do the same. Because nobody is watching in real time, a silent drift in output format can ruin an entire run before anyone notices. Apply the same checks, store the failures with their raw output, and alert if the failure rate crosses a threshold you set from a small pilot run.
Run a pilot before the full job
Before submitting the whole dataset, send a small sample, a few hundred requests, through the same batch path. You are checking three things: the request format is accepted, the outputs parse and validate, and the quality is acceptable on real data. Then scale up. Finding a prompt bug after a multi-hour batch has finished is the most expensive way to find it.
Control cost and avoid duplicate spend
- Set a maximum output length on every request. A runaway generation inside a batch costs just as much as one outside it.
- Deduplicate inputs before building the file. Identical items in a catalog or a ticket archive are common.
- Keep the shared prefix identical across requests if your provider supports prompt caching on batch traffic. Check the current documentation before relying on it, since support varies.
- Record token usage per chunk from the provider's response so you can compare actual spend against your estimate.
- Do not resubmit a chunk that is still running. Your status table should make this impossible.
Cancellation and expiry
Decide up front what happens when a batch does not finish within its window. Usually the answer is to keep whatever completed, mark the rest as missing, and resubmit them. Some providers let you cancel a running job. Cancelling still leaves you billed for work already done, so treat it as a last resort and record the partial results.
A checklist you can adopt today
- Confirm the workload is non-interactive and independent per request.
- Design custom IDs that encode the item, the task, and the prompt version.
- Chunk the job and track each chunk in a table with explicit states.
- Poll from a scheduled task and store provider batch IDs.
- Join results by custom ID, never by position.
- Reconcile with set difference and split retryable from terminal errors.
- Validate every output with the same schema as your live path.
- Pilot on a small sample before the full run.
- Cap output length and record token usage per chunk.
Wrapping up
Batch interfaces are one of the simplest ways to lower the cost of large LLM workloads, but the savings only count if the results are correct and complete. Treat a batch as a small distributed system: stable IDs, explicit state, bounded retries, and validation on the way out. Do that, and an overnight job becomes something you can trust instead of something you check nervously in the morning.
Comments
Post a Comment