On this page
An AI feature can feel slow even when its model responds quickly. Authentication, retrieval, queueing, buffering and interface rendering all contribute to the wait. Conversely, an operation with a long total duration can feel manageable when users see useful progress early and retain control over what happens next.
Treat latency as a workflow property rather than a model benchmark. First measure the journey users actually experience, then decide which work to remove, parallelise, stream or defer. Faster output is valuable only if it remains correct enough for the task and does not create extra review work.
Measure the full request journey
Start with end-to-end latency, measured from the user's action to the usable result. Add timestamps for request acceptance, retrieval completion, provider dispatch, first received content and final rendering. Distinguish server timing from browser timing so network travel and client work do not disappear from the analysis.
Track time to first useful output, not just the first byte. A heartbeat, empty event or generic introductory phrase may prove that the connection is alive without helping the user. For a structured response, the first useful moment might arrive only after enough fields have been validated to render a meaningful preview.
Inspect the median and slower percentiles under realistic load. A quick local demo says little about queueing during a busy period. Record cancellations and timeouts separately, and document whether those requests are included in each metric. Otherwise the slowest experiences can vanish from a dashboard simply because users abandoned them.
Use the JSON formatter to inspect sanitised timing records and compare event fields across requests. Do not paste customer prompts or credentials into debugging tools. A small event structure makes instrumentation easier to review:
{
"requestId": "synthetic-example",
"retrievalMs": 140,
"providerFirstContentMs": 620,
"usablePreviewMs": 810,
"completedMs": 1840,
"outcome": "completed"
}These are illustrative measurements, not performance targets. Agree on useful targets from your own task and user research.
Choose the smallest workflow that meets quality
Model choice affects latency, but capability requirements come first. Evaluate a faster candidate on representative cases before routing production traffic to it. A model that needs frequent retries or manual correction may make the overall workflow slower despite a shorter generation time.
Reduce unnecessary work before changing providers. Remove duplicate instructions, retrieve fewer irrelevant passages and request only the fields the interface needs. A terse classification response should not carry several paragraphs of explanation unless the product actually displays or audits that explanation.
Use task routing when the distinction is reliable. A constrained label assignment might use a lighter model, while a difficult synthesis task takes a more capable path. Keep the routing decision testable and monitor misroutes. Do not use an unvalidated confidence claim from the generator as the only escalation signal.
The OpenAI latency optimisation guidance offers useful categories of optimisation. Apply them through your own evaluation suite, measuring quality and completion time together. Avoid reducing context so aggressively that the model loses the evidence required to answer accurately.
Remove serial dependencies and unnecessary round trips
Draw the critical path as a sequence of operations. Authentication, permissions and required data dependencies cannot simply be skipped, but independent retrieval operations may run concurrently. Parallelism reduces elapsed time only when available capacity and provider limits support it.
Avoid turning one simple transformation into several model calls by default. A planning step, rewriting step and stylistic polishing step can create a long serial chain. Keep extra stages only when evaluation demonstrates a worthwhile improvement, and consider moving optional analysis out of the interactive path.
Use caching at the appropriate boundary. Cache static reference material or safe, reusable computation where freshness and access rules permit it. Partition private results by tenant and relevant permissions. Include configuration and content versions in cache keys so a prompt update does not silently reuse obsolete output.
Measure cache hits and misses separately. Warm-cache demonstrations can create unrealistic expectations for new users. Provider prompt caching, where supported, has its own eligibility and accounting rules; it should not be assumed to behave like an application response cache. Review the web.dev performance guidance for surrounding browser costs that can obscure an otherwise improved server path.
Stream useful progress without misleading users
Streaming can reduce perceived waiting when the result is naturally incremental, such as prose or an explanation. Verify that each layer forwards chunks promptly: provider, application server, proxy and browser. A streaming implementation that buffers until completion delivers no early value.
Do not render incomplete structured data as if it were validated final output. Use a provisional preview or wait for a coherent section. For irreversible actions, generation progress is not confirmation that the action succeeded. Keep generating, validating, executing and completed states separate.
Use accurate progress language. A status such as searching reference documents describes real work; a fabricated percentage implies knowledge you may not have. If the service cannot estimate remaining duration, acknowledge that honestly and provide a cancel option or a background completion path.
Protect accessibility during progressive rendering. Avoid shifting focus when new text arrives and avoid announcing every token to screen readers. Provide concise status updates and a discoverable final result. The W3C status message guidance is a practical reference. Test slower connections and reduced motion preferences, not only a fast development machine.
Bound slow requests and preserve user control
Set deadline budgets for the whole request and for major stages. A provider timeout longer than the application's request limit creates confusing failures and may leave unnecessary work running. Propagate cancellation where supported, and verify whether upstream generation actually stops.
Retry suitable transient failures within the remaining budget. Use bounded backoff and respect rate-limit guidance. Do not retry indefinitely or restart a tool workflow in a way that repeats side effects. Long tasks may belong in a background job with durable status rather than an open browser connection.
Preserve the user's draft and offer a clear recovery action. If a stream fails after producing content, label the partial result and let the user decide whether to keep or retry it. Silent replacement can destroy useful work and makes timing problems look like data loss.
After each optimisation, compare the same task slices and load conditions. The Vercel AI SDK guide provides a related server and streaming workflow. Track whether users complete the task sooner, not merely whether tokens arrive faster. The best latency improvement may be eliminating a generation step that never needed to exist.
Key takeaways
- Measure the full journey and the first genuinely useful result.
- Choose models and output budgets against quality evaluations.
- Shorten serial paths and cache only within explicit privacy boundaries.
- Stream coherent progress with accessible, truthful status messages.
- Use deadlines, cancellation and recovery paths to contain slow requests.
Reach designers & developers at work
Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.
Become a sponsor