Cost, latency & caching for LLM apps
Make AI features fast and affordable with routing, caching and smaller prompts.
Cost scales with tokens in and out, and latency scales mostly with output length. The cheapest token is the one you do not send, so trim prompts, retrieve fewer and better chunks, and cap output length.
Use the right model for each step. A small, fast model can classify, route and extract. Reserve the large model for the steps that need it. Stream responses so users see progress while the rest generates.
Cache aggressively where it is safe. Providers can cache a stable prompt prefix, which rewards putting fixed instructions first. You can also cache whole answers for repeated, non-personalised questions. Key the cache on the exact inputs and the model version.
Key points
- Output length drives latency. Input size drives cost.
- Route easy steps to small models.
- Put stable content first to benefit from prefix caching.
- Stream tokens to improve perceived speed.
Answer these out loud
- 1Your assistant costs too much and 70% of tokens are repeated instructions. What changes first?
- 2When is caching a full LLM answer unsafe?
Use this from an agent
Any MCP client, including Grok, can read this lesson. See how to connect.
curl https://engineeros-delta.vercel.app/api/v1/topics/cost-latency-and-caching