liveBook · Manning

Cost

As explained in Building Reliable AI Systems

The monetary expense of using an API service, typically based on usage.

Hosted LLM APIs remove the need to manage GPUs and model updates, but they charge for usage. Cost can rise sharply when production requests are longer or more frequent than prototype requests. Estimate spending from real input and output lengths, not just short test prompts. section 10.2.1

A request that changes the estimate

A customer writes a detailed support request rather than a short question. One illustrated exchange uses 356 input tokens and 891 output tokens—1,247 tokens in all—and costs $0.32. Thousands of similarly verbose exchanges would make a short-prompt estimate misleading; the illustrated price is not a universal rate. section 10.2.1

Measure cost alongside the work that produced it. Request logs can record input and output tokens, model and prompt versions, latency, and spending. In one request-life-cycle comparison, inference accounts for $0.004193 of cost versus $0.00001 for other operations combined. That makes output length, prompt efficiency, and model routing more promising cost targets than infrastructure changes in that case. section 10.3.2

Figure 10.3 LLM request life-cycle timeline showing where time and cost are spent during a typical customer-support query. The figure reveals that LLM inference dominates both execution time (89.3%) and cost (97%), making model optimization the highest-value area for performance improvements.
figure

The request timeline compares component latency and expense, making the concentration of cost in inference visible. section 10.3.2

Treat spending changes as production signals, not just billing surprises:

  • Compare current hourly cost with a historical baseline and alert on a large jump. section 10.3.4
  • Watch trends and investigate changes in prompt length, traffic, model routing, or the complexity of user questions. section 10.3.4
  • Trace token counts and cost through the pipeline when a request needs closer investigation; Langfuse provides this visibility alongside prompt, model, latency, and quality traces. section 10.6

A cost alert points to a change, not necessarily its cause. A prompt change once tripled a team's monthly bill by making responses longer; another issue routed every query to a more expensive model. Use request-level evidence to distinguish these failures before changing infrastructure. section 10.3.4 section 10.3.2

How Building Reliable AI Systems covers it

How deep it goes
Works through token-based examples, logging priorities, and anomaly checks; does not establish a universal price per token.
Examples
Uses a 1,247-token support exchange, an inference-heavy request timeline, and prompt-change and model-routing cost incidents.
What you can do after
Diagnose/debug with request logs and cost alerts to prioritize investigations into rising LLM API spending.
How it connects
Connects cost to token counts, prompt engineering, model routing, request logging, and observability.

Also explained in

Compare how 10 books explain cost →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.