Skip to content
PHP2Shell: The PHP Bug
Akshay Thakare

LLM Inference: Cost and Latency in Production

Where time and money go in an LLM call, and the techniques that cut both: smaller models, caching, streaming, batching and shorter prompts.

LLMsIntermediate2 min readUpdated 11 Oct 2026

Where the time goes

PhaseDriven by
Time to first tokenInput length, model size, queueing
GenerationNumber of output tokens, one at a time
Around the modelRetrieval, tool calls, network

Output tokens usually dominate latency, and they are often priced higher than input tokens.

Techniques

TechniqueSaves
Use the smallest model that passes your evalsCost and latency
Route: small model by default, large model for hard casesCost
Prompt caching for a long, repeated prefix (system prompt, documents)Input cost and time to first token
Limit output length; ask for concise formatsLatency and cost
Stream tokens to the userPerceived latency
Batch offline jobsCost, where batch pricing is offered
Cache whole answers for repeated questionsEverything, for exact repeats

Measure per request

Log input tokens, output tokens, latency, model and outcome for every call. Cost per successful task is the number that matters, not cost per call.

Finished this note?

Share