Measuring Inference Latency and Throughput
Online APIs optimize for latency and process requests as they arrive. Batch APIs optimize for cost and can accept longer turnaround. The deciding question is always what the provider is allowed to delay.
Why Two Identical-Looking APIs Behave Differently
Once a model has been trained, applications send it inputs and wait for outputs. Many model providers expose this work through two kinds of inference API: an online API and a batch API. Both accept requests and both return predictions, so from the outside they can look alike. The difference lies in what the provider is trying to optimize, and that choice shapes how requests are scheduled, how the hardware is used, and what the person waiting on the result experiences.
What do you think happens?
A batch API receives a request right now. Does the provider have to return the answer immediately?
Reveal answer
No, a batch request does not need an immediate answer.
A batch API is tuned for cost. Its requests do not need to be answered immediately, and that slack gives the provider room to use cheaper hardware and to group many requests together. Turnaround can stretch from seconds or minutes to hours.
Latency-First Versus Cost-First Design
An online API is tuned for latency, which means the time a single caller waits for an answer. Each request is handled as soon as it arrives. A batch API is tuned for cost. Its requests do not need to be answered immediately, and that slack gives the provider room to use cheaper hardware and to group many requests together so they are processed as one unit of work.
| Question | Online API | Batch API |
|---|---|---|
| What is it tuned for? | Latency, the wait of a single caller | Cost |
| When are requests processed? | As soon as they arrive | When the provider schedules them, with turnaround that can be hours |
| What does the provider give up? | Some efficiency, so it can answer quickly | Immediacy, so it can spend time on efficiency |
| What hardware and grouping are possible? | Limited by the need to answer quickly | Cheaper hardware and grouping many requests as one unit of work |
The two API styles differ in what the provider is allowed to delay.
A helpful way to hold this distinction is to ask what the provider is allowed to delay. An online API is not allowed to delay much, so it gives up some efficiency to answer quickly. A batch API is allowed to delay, so it can spend that time on efficiency. The provider's documentation describes the batch trade-off in concrete terms: when turnaround time stretches from seconds or minutes to hours, the provider can apply a wider range of optimization techniques. At the time that material was written, Google Gemini and OpenAI both offered batch APIs at a 50% cost reduction in exchange for that longer turnaround.
Online APIs optimize for latency and process requests as they arrive. Batch APIs optimize for cost and can accept longer turnaround. The deciding question is always what the provider is allowed to delay.
Tracing Three Requests Through Each API
The clearest way to see the difference is to follow a small set of requests through each style. Suppose three requests arrive close together: a chatbot message, a code-generation request, and a request to summarize a day's support tickets. Each request is a separate job for the provider. The scenario below is an illustration written to make the two behaviors concrete.
Following Three Requests Through Both API Styles
Three requests arrive close together: a chatbot message, a code-generation request, and a request to summarize a day's support tickets. How is each one handled under an online API and under a batch API?
- 1Step 1: Online API, first arrival
The chatbot message arrives and is handled as soon as it arrives. The caller waits only for that one job.
- 2Step 2: Online API, remaining arrivals
The code-generation request and the ticket summary request are each handled as soon as they arrive. Each is treated as its own job, so each caller's wait stays short.
- 3Step 3: Batch API, submission
All three requests are accepted and queued. None is answered on arrival, because a batch request does not need an immediate answer.
- 4Step 4: Batch API, processing
The provider groups the submitted requests and processes them together as one unit of work, possibly on cheaper hardware. Each caller receives an answer when the batch completes, which may take hours.
Under the online API, each request finishes soon after it arrives. Under the batch API, all three wait and finish together, trading immediacy for efficiency.
Why Batching Does Not Define Either Style
It would be a mistake to conclude that online APIs never batch anything. Online APIs may still group requests together, provided the grouping does not significantly hurt latency. The deciding factor is therefore not whether grouping happens at all, but how much waiting it adds. The real difference is one of emphasis: an online API focuses on keeping latency low, whereas a batch API focuses on maximizing throughput.
Two Meanings of Batch
The word batch means something slightly different in traditional machine learning. There, online inference means predictions are computed after a request has arrived, while batch inference means predictions are precomputed before any request arrives. This meaning is not the same as the batch API described above, because the two are not interchangeable for foundation models.
Precomputation works when inputs are finite and predictable. A recommendation system, for example, can generate recommendations for every user in advance, store them, and retrieve them when a user visits the site. Foundation model inputs are open-ended, and it is hard to anticipate every prompt a user might write. Precomputing answers for all of them is therefore impractical, which is why the batch API for foundation models works by processing submitted requests rather than by precomputing predictions.
- Generating synthetic data
- Producing periodic reports such as summaries of Slack messages or analyses of customer support tickets
- Processing every document uploaded during onboarding of a new customer
- Reprocessing all data when migrating to a new model
- Generating personalized recommendations or newsletters for a large customer base
- Reindexing an organization's data to update a knowledge base
These workloads share one property: no individual caller needs an answer right away. That property is what makes a batch API a good fit.
Streaming Mode: Faster First Token, Harder Safety Checks
Language models often produce output one token at a time through autoregressive decoding, and generating a full response can take a long time. Users are impatient. By default, APIs usually return a complete response, but many online APIs offer streaming mode, which returns each token as soon as it is generated.
The main benefit is that the time a user waits until the first token shrinks. The client can start displaying text as soon as the first token arrives. The complete answer still takes just as long to finish, so streaming improves responsiveness rather than total generation time.
The main drawback is a loss of safety checking. If the whole response is generated before anything is shown, the application can score that response and decide whether it is acceptable. When tokens are streamed, that step is skipped, because text reaches the user before it is complete. In short, a response cannot be scored before it is shown to users, which raises the risk that a bad response is seen.
Measuring Latency, Throughput, and Utilization
Before optimizing an inference service, it helps to know which measurements matter. Three are central: latency, throughput, and utilization. From the user's point of view, latency is the central concern. Latency is the time a single request takes, the wait that one caller experiences. Throughput is the number of requests the service completes per second. Utilization is the share of the hardware that is in use.
| Metric | What it measures | Whose view it reflects |
|---|---|---|
| Latency | Time per request, the wait for one caller | A single caller's experience |
| Throughput | Requests per second the service handles | The service in aggregate |
| Utilization | Share of hardware in use | How efficiently resources are used |
Latency describes a single caller; throughput and utilization describe the whole service.
Response quality is a property of the model itself, not of the inference service that delivers it. An inference API therefore cannot be judged on quality alone. Application developers must look at throughput and utilization as well, because these shape how much work the service can do and how efficiently it uses its resources, and those in turn determine what the application costs to run.
Latency tells you how a single caller experiences the service. Throughput and utilization tell you what the service is doing in aggregate. Both views are needed to decide whether an online or batch design makes sense.
Mistakes When Reading Inference Metrics
Common mistake Assuming online APIs never group requests
What it looks likeConcluding that a provider's real-time endpoint must handle every request in isolation
Why it failsOnline APIs may batch requests when the grouping does not significantly hurt latency.
Do this insteadAsk how much waiting grouping adds, not whether grouping happens at all.
Common mistake Treating batch inference and batch APIs as the same thing
What it looks likeAssuming a foundation model batch API precomputes answers for every possible prompt
Why it failsIn traditional ML, batch inference precomputes predictions. For open-ended foundation model inputs, the batch API processes submitted requests instead.
Do this insteadCheck whether a batch mention refers to precomputation or to a cost-oriented API that accepts delay.
Common mistake Reading streaming as a faster complete answer
What it looks likeExpecting a streamed response to finish sooner than a non-streamed one
Why it failsStreaming shrinks the wait until the first token. The complete answer still takes just as long to finish.
Do this insteadMeasure time to first token separately from total completion time.
Common mistake Judging an inference API by response quality alone
Why it failsQuality belongs to the model. Latency, throughput, and utilization describe the service that delivers it.
Do this insteadEvaluate the API with latency, throughput, and utilization alongside quality.
Common mistake Using latency and throughput as interchangeable names for speed
Practice: Choosing an API Style
A product team must summarize 40,000 customer support tickets overnight. Nobody needs the results before morning. Which API style fits this workload, and what does the team gain and give up by choosing it?
Hints
- Ask what the provider is allowed to delay in this workload.
- Consider which optimization goal matches a job where no individual caller needs an answer right away.
- Think about what the team trades in turnaround time to gain cost efficiency.
Key Takeaways
- Online APIs are tuned for latency and handle each request as it arrives. Batch APIs are tuned for cost and accept longer turnaround so the provider can use cheaper hardware and group requests.
- Batching does not define either style. Online APIs may group requests when that does not significantly hurt latency; the real difference is whether the provider optimizes for latency or throughput.
- Streaming mode returns tokens as they are generated, cutting the wait for the first token. Its main drawback is that a response cannot be scored before it is shown to users.
- Latency, throughput, and utilization are the metrics for inference APIs. Latency describes a single caller, while throughput and utilization describe the service in aggregate.