Processing thousands of LLM requests is less about sending more API calls and more about controlling work. This guide shows how to design a reliable batch LLM processing workflow with validation, queues, concurrency limits, retries, checkpoints, reconciliation, and a repeatable cost estimate that can be updated when model pricing or workload assumptions change.
Overview
A bulk LLM job might classify support tickets, extract fields from documents, generate embeddings, summarize records, or evaluate prompt variants. Sending every request in a loop is rarely sufficient. A provider may enforce request-per-minute, token-per-minute, daily, payload-size, or account-level limits. Individual calls may time out, return malformed output, or succeed while the client fails to record the response.
A dependable design treats each request as a durable job with an identity, input, status, attempt count, and result location. The usual flow is:
- Validate and normalize the input dataset.
- Partition the dataset into manageable work items.
- Place items on a durable queue or submit them to a provider-managed batch system.
- Run workers under explicit concurrency and token budgets.
- Retry only failures that are likely to succeed on another attempt.
- Checkpoint completed results independently from the worker process.
- Reconcile submitted, completed, failed, and missing items before declaring success.
There are three common execution patterns:
| Pattern | Best fit | Operational trade-off |
|---|---|---|
| Provider-managed batch endpoint | Large, delay-tolerant workloads | Less worker infrastructure, but completion timing, limits, status semantics, and supported features must be verified for the selected provider. |
| Provider asynchronous job endpoint | Requests that need a job ID and later polling | Simple submission model, but your system still needs polling, result collection, expiry handling, and reconciliation. |
| Direct API behind your own queue | Near-real-time processing or workflows requiring custom control | Most flexible, but your team owns rate limiting, retries, persistence, observability, and safe restarts. |
Do not assume that a feature named “batch” has the same guarantees across providers. Before implementation, confirm whether the operation supports your model, input format, structured output, tools, files, maximum request size, cancellation behavior, partial results, and completion notification.
How to estimate
Start with a workload model rather than a provider bill. Define the number of records, the expected input and output tokens per record, the percentage of requests that will be retried, and the concurrency you can safely sustain.
A simple token estimate is:
Total input tokens = records × average input tokens
Total output tokens = records × average output tokens
Include retry overhead:
Billable or attempted tokens = base tokens × (1 + retry overhead)
For example, suppose a dataset contains 20,000 records. Assume each request uses 900 input tokens and produces 180 output tokens. If you reserve an illustrative 8% retry overhead, the estimated attempted usage is:
- Base input: 20,000 × 900 = 18,000,000 tokens
- Base output: 20,000 × 180 = 3,600,000 tokens
- With 8% overhead: 19,440,000 input tokens and 3,888,000 output tokens
These are planning numbers, not a price quote. To estimate spend, apply the selected provider's current input and output rates to the corresponding token totals, then add any applicable storage, retrieval, file, embedding, or orchestration costs. Keep input and output calculations separate because providers may price them differently.
Estimate duration using the tightest constraint, not only worker count. If your workers can produce 40 requests per second but the account or model quota allows only 12 requests per second, the effective rate is closer to 12. Token-based limits may be even more restrictive:
Safe request rate = minimum(worker capacity, request quota, token quota ÷ average tokens per request)
For a queue-based implementation, begin below the documented limit and leave headroom for variation in prompt length. A concurrency limit of 10 does not guarantee 10 requests can run safely if a few records are much larger than average.
Inputs and assumptions
Validate before enqueueing
Reject or quarantine records that are missing required fields, exceed the model context budget, contain invalid encoding, or cannot be serialized into the request format. Assign every record a stable ID derived from your source system or a deterministic hash. Never use a worker-generated random ID as the only way to match a response to its input.
Store a request manifest with fields such as job_id, record_id, model identifier, prompt or template version, input hash, creation time, and status. This makes it possible to detect duplicates and explain which version produced a result. For security-sensitive workloads, follow a separate secret-management process; the AI API authentication and secret management guide covers key storage, rotation, and deployment checks.
Partition work deliberately
Partitioning affects recovery. Very large partitions can make a failure expensive to repeat, while very small partitions increase scheduling and bookkeeping overhead. Choose a unit that can be retried independently and whose results can be committed incrementally. For provider-managed jobs, use the provider's documented file or request limits rather than assuming that an entire dataset can be uploaded at once.
Use a queue with explicit states
A useful state model is pending, leased, succeeded, retryable, permanent_failure, and cancelled. A lease or visibility timeout prevents a crashed worker from holding work forever. A successful write should be idempotent: if the same record is delivered twice, the second delivery should not create a second business result.
Classify failures
- Retryable: temporary network errors, timeouts, service-unavailable responses, and rate-limit responses, subject to provider guidance.
- Potentially retryable: malformed provider responses or output validation failures, after capturing the raw response and determining whether the prompt or parser is at fault.
- Permanent: invalid authentication, unsupported model or feature, invalid request schema, consistently oversized input, or a record that fails business validation.
Use exponential backoff with jitter. Cap the delay and the number of attempts, and record the reason for every retry. A retry policy without a cap can turn an upstream outage into an expensive queue storm.
For predictable outputs, require a schema and validate it before marking a job complete. The structured outputs guide provides a useful pattern for schema design and validation. Prompt behavior should also be measured with a test set; see the prompt testing playbook before changing a production template.
Worked examples
Example 1: Direct queue with controlled concurrency
Assume 50,000 short classification requests, an average of 700 input tokens and 40 output tokens, and a target of 20 concurrent workers. Before launch, run a small sample to measure actual latency, token usage, validation failures, and rate-limit responses. If the sample shows that the provider quota is the limiting factor, reduce concurrency or add a token-aware limiter rather than simply adding workers.
Persist each result as soon as it passes validation. The checkpoint should include the record ID, response, model version, prompt version, token usage if available, attempt count, and completion timestamp. If the process stops after 31,000 records, restart by selecting records that are not in the succeeded state. Do not rerun the entire dataset unless the output is intentionally non-idempotent or the prompt version has changed.
Example 2: Cost comparison before a model change
Suppose a current workflow uses 10 million input tokens and 2 million output tokens per run. A proposed model changes the average output length to 2.4 million tokens and reduces validation failures. Compare both the direct token cost and the operational cost of retries, manual review, and reruns. A lower published rate is not automatically a lower run cost if the new output is longer or produces more unusable results.
Record the assumptions in a small worksheet:
| Input | Example value | Why it matters |
|---|---|---|
| Records | 50,000 | Sets the base workload. |
| Average input tokens | 700 | Drives input usage and context fit. |
| Average output tokens | 40 | Drives output usage and parsing effort. |
| Retry overhead | 8% | Captures temporary failures and validation retries. |
| Effective rate | Quota-limited estimate | Determines elapsed time and queue pressure. |
Keep these values separate from provider-specific pricing so the worksheet remains useful after a model migration. For migration work, pair the estimate with the LLM model migration checklist.
Safe restart runbook
- Pause new submissions if the failure source is unknown.
- Capture queue depth, provider job status, error classes, and the last successful checkpoint.
- Confirm whether submitted work may still complete. Avoid resubmitting an active provider job without checking its status.
- Mark only confirmed failures as retryable.
- Reconcile results by stable record ID and input hash.
- Resume with a low concurrency limit and monitor error rates before restoring normal throughput.
- Close the run only when every input is succeeded, intentionally skipped, cancelled, or assigned a documented permanent failure.
When to recalculate
Recalculate before every substantial run if the dataset size, average prompt length, output limit, model, provider, or retry policy has changed. Recalculate after a quota increase or reduction, a pricing update, a change to batch or asynchronous API behavior, or a postmortem involving duplicate, missing, or unusually expensive results.
During a quarterly infrastructure review, verify provider documentation for current limits, supported features, maximum request sizes, completion guarantees, status transitions, SDK behavior, and pricing inputs. Also compare estimates with observed runs. Track records per minute, tokens per record, retry percentage, permanent-failure percentage, validation-pass rate, and total cost per successful record.
Before the next launch, use this checklist:
- Input validation and stable IDs are in place.
- Every request has a durable status and checkpoint.
- Concurrency and token limits are configured below the applicable quota.
- Retries use classification, backoff, jitter, and a maximum attempt count.
- Results are idempotent and reconciled against the original manifest.
- Cost estimates use current provider inputs and measured token averages.
- Operators know how to pause, inspect, and safely restart the job.
For adjacent workflow design, see the AI coding workflow templates and the prompt debugging checklist. A batch LLM process is ready for scale when it can explain what was attempted, what succeeded, what failed, what it cost, and what will happen after a restart.