Latency and cost in production
The feature works. People like it. Usage grows ten times in two months, and two graphs start to worry everyone: the model bill is now the largest line in the infrastructure budget, and the slowest 5% of requests take nine seconds. Nothing is broken. The prototype was simply never built for its own success.
This chapter is the toolkit for that moment. The good news is that most of these fixes make the feature faster and cheaper at the same time.
Name three changes that would make an LLM feature both faster and cheaper, without making answers worse.
Measure per feature, per request#
You cannot cut what you cannot see. For every LLM feature, log on every request: input tokens, output tokens, cached tokens, time to first token, total time, model, and cost. Then look at the totals by feature. It is very common to find one forgotten background job, or one prompt with a 6,000 token example block, behind half the bill.