Batch vs Realtime LLM Calls: A Cost and Latency Decision Table
A practical guide to choosing batch or realtime LLM APIs by workload, with idempotency, partial failure handling, and a migration checklist.
What batch actually optimizes
Batch APIs are built for throughput and cost efficiency, not for latency. When you submit a batch, the provider queues your requests and processes them when capacity allows, often within a stated completion window. You typically get a lower price per token in exchange for giving up immediate responses. The exact discount and turnaround time vary by provider and model, so check the live pricing and documentation for your chosen model family.
Batch also helps with rate limits. Instead of hammering a realtime endpoint with thousands of concurrent requests and hitting 429 errors, you can submit a large job and let the provider manage scheduling. This is especially useful for offline workloads like tagging, classification, summarization, and embedding generation where you care about total cost and completion within hours, not milliseconds.
Workloads that should never use batch
Any workload where a human or an automated agent is waiting for the result should use realtime APIs. That includes chat interfaces, interactive coding assistants, agent steps that must decide the next action, and any pipeline where the next stage depends on the current output within seconds. Batch adds unpredictable delay that breaks the user experience and can cause timeouts in upstream systems.
Also avoid batch for workloads that require immediate validation or feedback, such as form autocomplete, content moderation on user-generated posts that must be published instantly, or real-time translation. If the output feeds into a user-visible action, batch is the wrong tool.
Idempotency and partial failures
Batch jobs are not atomic. A single batch submission can contain thousands of requests, and some may succeed while others fail due to content filtering, token limits, or transient errors. You must design your system to handle partial success. Track each request with a unique custom ID and record its status. When the batch completes, iterate over the results, separate successes from failures, and retry only the failed items with appropriate backoff.
Idempotency is critical to avoid duplicate side effects. If you retry a batch submission because you did not receive a response, you could end up processing the same requests twice. Use an idempotency key per logical job or per request, and store it alongside your data. Many batch APIs support a custom idempotency key; if not, implement your own deduplication layer. Also consider that retrying a failed request may produce a different output if the model is non-deterministic, so design downstream systems to tolerate that.
A migration checklist
Migrating a workload from realtime to batch does not have to mean rewriting your prompt layer. Follow these steps to move safely:
- Abstract your LLM calls behind an interface that accepts a list of requests and returns a list of responses, regardless of whether the backend is realtime or batch.
- Add a job queue and a worker that can submit batches and poll for completion, decoupling submission from result processing.
- Assign a stable custom ID to each request and store it with your data so you can map results back and retry failures.
- Implement idempotency at the job level: if a submission is retried, ensure the provider or your own layer deduplicates.
- Write a result handler that processes partial successes and failures, with retry logic for transient errors and dead-letter handling for permanent failures.
- Test with a small batch first, measure end-to-end latency and cost, and compare against your realtime baseline before rolling out to production.
Decision table by workload
- Offline tagging and classification: use batch. No user is waiting, and you can tolerate hours of latency for lower cost.
- Nightly summaries and reports: use batch. Schedule the job after hours and process results before the next business day.
- Chat and interactive assistants: use realtime. Users expect responses within seconds.
- Agent steps that decide next actions: use realtime. The agent loop cannot proceed without the result.
- Embedding generation for a static corpus: use batch. You can process the entire corpus in one job and store the vectors.
- Content moderation for instant publishing: use realtime. You cannot delay publishing while waiting for a batch.
How to apply this with Admesh
Admesh provides a unified API for multiple model families, so you can implement the batch vs realtime decision without managing separate credentials. Use the OpenAI-compatible base URL https://api.admesh.ai/v1 for realtime calls, and the Anthropic-compatible endpoint https://api.admesh.ai/v1/messages if you need that interface. For batch workloads, check the Admesh documentation at https://docs.admesh.ai for the supported batch submission flow and any model-specific constraints.
Start by listing your workloads and classifying each as batch or realtime using the decision table above. Then, for each batch workload, implement the idempotency and partial failure handling described earlier. Use the Admesh console at https://console.admesh.ai to monitor usage and balance, and consult the model catalog at https://admesh.ai/models to pick models that support batch processing. Pricing for batch versus realtime may differ, so verify current rates at https://admesh.ai/pricing before committing.
Because Admesh uses one API key and one balance across model families, you can prototype with a small batch on one model and switch to another without changing your integration. This makes it easy to test cost and latency tradeoffs before migrating a production workload.
FAQ
Can I use batch for agent steps if I add a timeout?
How do I handle a batch job that partially fails?
Do I need to rewrite my prompts when moving to batch?
Where can I find the batch discount and turnaround time for a specific model?
References
Call these models through one gateway
Admesh provides a unified OpenAI-compatible API: one Base URL and one key for Claude, GPT, DeepSeek and more. New accounts get trial credit that never expires.
