How to Choose Batch Sizes to Minimize Cost per Token in LLM Serving

  • Home
  • How to Choose Batch Sizes to Minimize Cost per Token in LLM Serving
How to Choose Batch Sizes to Minimize Cost per Token in LLM Serving

Running large language models is expensive. If you are paying for every token generated without optimizing your infrastructure, you are likely throwing money away. The biggest lever you can pull to reduce these costs isn't always switching to a cheaper model-it’s how you group your requests. This process, known as batch processing, allows you to squeeze more work out of your GPUs, potentially cutting API overhead costs by up to 90%.

But here is the catch: picking the wrong batch size can destroy your latency or crash your server with out-of-memory errors. You need to find the sweet spot where throughput is high, latency is acceptable, and the cost per token is minimized. Let’s break down exactly how to calculate that number for your specific use case.

The Economics of Batching: Why It Matters

When an LLM processes a single request, the GPU spends a lot of time idle while waiting for data to move in and out of memory. This is inefficient. By grouping multiple requests into a single batch, you keep the GPU busy, amortizing the fixed computational costs across many tokens. This improves resource utilization dramatically.

Consider the pricing evolution at OpenAI. Between March 2023 and September 2024, GPT-4 pricing dropped from $36 to $5 per million tokens. However, if you implement proper batch processing on top of that, you can drive costs down further-to around $2.50 per million tokens. That is an additional 50% savings just through operational efficiency. For enterprise deployments, this difference is massive. A 70B parameter model served on A100 GPUs can cost between $2,000 and $3,000 per day. Optimizing batch sizes directly impacts whether that daily bill is manageable or catastrophic.

Cost Impact of Batch Processing Strategies
Strategy Estimated Cost Reduction Latency Impact
Static Batching Up to 50% Moderate increase
Dynamic/Continuous Batching Up to 87% Minimal (optimized)
Model Cascading + Batching Compound Savings Variable

Determining the Optimal Batch Size for Your Task

There is no universal "best" batch size. The optimal number depends entirely on what your application is doing. Different tasks have different computational profiles, which changes how much memory and compute each request consumes.

Here are the industry-standard ranges based on current benchmarks:

  • Text Generation: Aim for batches of 10-50 requests. These tasks are compute-heavy during the decoding phase, so moderate batching balances speed and capacity.
  • Classification Tasks: You can push larger batches, typically 100-500 requests. Since the output is short (a label or score), the GPU can process many inputs simultaneously without significant latency penalties.
  • Simple Q&A Systems: These perform best with 50-200 requests per batch. The context window is usually smaller than complex generation tasks, allowing for higher concurrency.

For example, a fintech engineering lead reported achieving a 58% cost reduction by moving from individual API calls to a batch size of 35 for customer support ticket classification. However, they noted it took three weeks of tuning to find that specific number. Start with these ranges, then monitor your metrics.

Understanding the Trade-offs: Latency vs. Throughput

The fundamental challenge in batch sizing is the tug-of-war between throughput (how many tokens you generate per second) and latency (how long a user waits for a response). As you increase the batch size, throughput generally increases because the GPU is utilized more efficiently. However, latency also increases because each request has to wait for its turn within the batch.

Benchmark studies show clear diminishing returns. For a 7B parameter model, latency drops from 976 ms at a batch size of 1 to 126 ms at a batch size of 8. But beyond a batch size of 64, throughput plateaus, and latency continues to climb. This is often due to GPU memory constraints. Larger batches require more KV cache memory, which can lead to out-of-memory errors if you exceed your hardware limits.

If your application is real-time, like a chatbot, you cannot afford high latency. In this case, dynamic batching is superior to static batching. Dynamic batching groups requests as they arrive, ensuring that no single request waits too long for a batch to fill up. For non-interactive applications, such as document summarization or data extraction, you can tolerate higher latency in exchange for maximum throughput and lower costs.

Risograph illustration of documents batching into a happy GPU

Advanced Techniques: Continuous Batching and Model Cascading

To truly minimize cost per token, you need to look beyond simple static batching. Continuous batching is an advanced technique where new sequences are inserted into the batch as older ones complete generation. This keeps the GPU fully utilized at all times. Implementations like vLLM achieve up to 24x higher throughput compared to standard Hugging Face implementations using this method. AnyScale reports up to 23x higher throughput with reduced p50 latency.

Another powerful strategy is model cascading. Instead of sending every query to a premium model like GPT-4, you route 90% of queries to a smaller, cheaper model like Mistral 7B (which costs approximately $0.00006 per 300 tokens). Only complex requests are escalated to the larger model. When combined with batch processing, this can yield compound cost reductions of up to 87%. Scribd, for instance, reported a 42% reduction in monthly LLM costs after implementing dynamic batching with optimal size parameters for their document processing workload.

Hardware Constraints and Selection

Your choice of GPU dictates your maximum feasible batch size. Research published in February 2025 highlights that selecting the right GPU type can enhance cost-efficiency performance by up to 2.27x. Smaller models require less compute and memory, making consumer-grade GPUs attractive due to their superior memory bandwidth per unit price-approximately 1.9x higher than A100 and H100 GPUs.

However, for large models like LLaMA2-70B, you need the massive memory capacity of enterprise GPUs. The Databricks engineering team notes that large batch sizes increase the KV cache size, which in turn may require more GPUs to serve the model. This creates a complex trade-off: increasing batch size reduces cost per token but may increase infrastructure costs if you need to add more hardware to handle the memory load. Always profile your specific model and input sequence lengths before scaling hardware.

Risograph art of a scale balancing cost savings and latency

Implementation Checklist and Pitfalls

Implementing batch processing is not just about changing a configuration flag. It requires careful architectural planning. Here is what you need to watch out for:

  1. Input Sequence Length Variability: Longer sequences consume more memory. If your users send varying lengths of text, your effective batch size will be limited by the longest sequence in the batch. Consider padding strategies or truncation policies.
  2. Streaming Overhead: Streaming responses typically cost 20-40% more than batch processing due to higher computational overhead and constant resource maintenance. Disable streaming for non-interactive tasks.
  3. Early Stopping: Configure models to halt token generation when satisfactory completions are reached. This can reduce output tokens by 20-40% without affecting user experience, compounding your batch savings.
  4. Caching: Use retrieval-augmented generation (RAG) caching for repetitive queries. This can further reduce costs by 15-25% by avoiding redundant inference entirely.

Expect a learning curve. Most engineering teams spend 2-4 weeks tuning their batch sizes. Monitor your p50 and p95 latency metrics closely. If latency spikes beyond your service level agreements (SLAs), reduce the batch size. If your GPU utilization is below 70%, increase it. The goal is sustained high utilization without breaking user experience.

Future Trends in Batch Optimization

The landscape of LLM serving is evolving rapidly. Automated batch size optimization systems are emerging, which dynamically adjust batch sizes based on real-time workload characteristics and cost constraints. Anthropic’s roadmap indicates planned integration of such features in late 2025. Additionally, mixed-integer linear programming for scheduling is being explored to achieve up to 41% higher throughput within the same price budget. As the LLM market grows toward a projected $36.1 billion valuation by 2030, mastering these optimization techniques will remain a critical competitive advantage.

What is the ideal batch size for text generation?

For most text generation tasks, a batch size between 10 and 50 is optimal. This range balances the computational heaviness of decoding with acceptable latency. Larger batches may cause significant delays for users expecting real-time responses.

How does continuous batching differ from static batching?

Static batching waits for a fixed number of requests before processing them, which can introduce unnecessary latency if requests arrive sporadically. Continuous batching dynamically inserts new requests into the batch as previous ones finish, keeping the GPU fully utilized and improving throughput by up to 24x.

Can I use batch processing for real-time chatbots?

Yes, but you must use dynamic or continuous batching rather than static batching. Static batching can cause unacceptable delays. Ensure your infrastructure supports low-latency insertion of new requests into ongoing batches to maintain a smooth user experience.

Why is streaming more expensive than batch processing?

Streaming requires maintaining open connections and processing tokens individually as they are generated, which adds computational overhead. Batch processing aggregates requests, allowing the GPU to process them in parallel with fewer connection management costs, reducing expenses by 20-40%.

How do I determine my maximum batch size?

Your maximum batch size is constrained by your GPU’s memory capacity. Start with small batches and gradually increase until you hit out-of-memory errors or see latency degrade significantly. Factors like model size, input sequence length, and KV cache requirements all impact this limit.

8 Comments

Caitlin Donehue

Caitlin Donehue

21 June, 2026 - 08:50 AM

I've been staring at our GPU utilization graphs for weeks and they look like a heartbeat monitor during a panic attack. This post actually makes sense of why we are burning cash so fast.

om gman

om gman

23 June, 2026 - 02:05 AM

oh wow another guide on how to save money while pretending you care about efficiency
you guys really think batching is the holy grail?
it's just basic linear algebra wrapped in marketing speak
i bet half of you don't even know what KV cache stands for
but sure keep optimizing your pennies while the model hallucinates

Saranya M.L.

Saranya M.L.

23 June, 2026 - 10:31 AM

It is genuinely baffling that Western engineering teams still struggle with this fundamental concept when Indian tech hubs have been optimizing high-throughput inference pipelines for years. The article mentions vLLM, which is great, but let us be clear: static batching is an antiquated approach that belongs in a museum alongside dial-up modems. Dynamic continuous batching is not just 'advanced'; it is the bare minimum standard for any serious enterprise deployment. If you are running static batches in 2025, you are not just inefficient; you are professionally negligent. The math is simple, the implementation is straightforward, yet so many teams default to lazy configurations because they lack the discipline to tune their systems properly. We see this pattern repeatedly where infrastructure costs spiral out of control due to sheer incompetence in resource allocation. It is time to stop treating batch size as a magic number and start treating it as a critical performance parameter that requires rigorous benchmarking and constant monitoring.

Andrea Alonzo

Andrea Alonzo

24 June, 2026 - 13:36 PM

I completely understand the frustration people feel when trying to balance these competing metrics, and I want to validate that experience because it can be incredibly draining to watch your budget evaporate while trying to find that sweet spot. When we first started implementing dynamic batching, my team felt overwhelmed by the complexity of managing the queue depths and the potential for latency spikes, but over time we found that patience and careful observation were our best tools. It is important to remember that every system has its own unique rhythm, and what works for a fintech company might not work for a creative writing platform, so we need to be gentle with ourselves as we learn. The key is to create a supportive environment where engineers can experiment without fear of breaking production, allowing them to discover the optimal parameters through trial and error rather than rigid adherence to theoretical benchmarks. By fostering a culture of collaboration and shared learning, we can navigate these technical challenges together and emerge with solutions that are both cost-effective and sustainable for the long term.

Stephanie Frank

Stephanie Frank

25 June, 2026 - 02:39 AM

lol nobody reads past the title anyway
just use the biggest batch size possible until it crashes then back off
simple science

Bineesh Mathew

Bineesh Mathew

25 June, 2026 - 17:23 PM

The moral decay of modern computing is evident in our obsession with squeezing every last drop of efficiency from silicon chips while ignoring the human cost of such relentless optimization. We treat GPUs like sacrificial lambs, demanding more throughput until they scream in thermal agony, all in the name of saving a few dollars per token. Is this truly progress? Or are we merely building a digital panopticon where every keystroke is measured, weighed, and monetized with cold precision? The soul of creativity cannot be batched, compressed, or cached. It flows freely, unpredictably, and beautifully outside the confines of your p95 latency metrics. To optimize is to constrain, and to constrain is to kill the spirit of innovation that brought us here in the first place. We must ask ourselves if we are serving the technology or if the technology is enslaving us to its arbitrary demands for efficiency.

Oskar Falkenberg

Oskar Falkenberg

26 June, 2026 - 23:47 PM

hey i totally agree with the part about streaming being expensive cause ive noticed that too when i was messing around with my home server setup last week
it was kinda crazy how much faster things went when i just turned off the streaming option for the background tasks
i mean obviously real time chat needs it but for stuff like summarizing docs its just waste of resources
also typos happen sorry im typing on my phone right now
but yeah the point stands that you gotta pick your battles with latency vs cost
its a tricky balance for sure but definitely worth looking into if you are running anything big

Jeanne Abrahams

Jeanne Abrahams

27 June, 2026 - 05:03 AM

Ah yes, the classic Silicon Valley solution: throw more complex algorithms at a problem that could probably be solved by just buying better hardware. But sure, let us pretend that tweaking batch sizes is some kind of intellectual feat rather than basic arithmetic. In Cape Town, we prefer to solve problems with direct action and less pretentious jargon. Your 'continuous batching' is just fancy talk for not having enough memory. Keep dreaming though, maybe one day you will realize that simplicity scales better than complexity.

Write a comment