Cut LLM API cost and latency with caching and batching

8 steps · about 2 h · Intermediate

  1. Know what you pay for: input, output and cached tokens (reference, Claude Docs, 10 min)

    Lists per-token prices and the discounts for cache reads and batch jobs.

  2. Count tokens before you send a request (reference, Claude Docs, 10 min)

    Estimate cost and stay under limits without making the call.

  3. See how much prompt caching saves (article, Anthropic, 10 min)

    Gives measured cost and latency cuts for long, repeated prompts.

  4. Mark reusable prompt prefixes for caching (reference, Claude Docs, 25 min)

    Where to put cache breakpoints, cache lifetime and how to read cache hits.

  5. Compare explicit and implicit context caching (reference, Google AI for Developers, 15 min)

    A second provider's take on reusing long context across calls.

  6. Send non-urgent work as a discounted batch (reference, Claude Docs, 20 min)

    Submit many requests at once and collect results later at lower cost.

  7. Stream tokens so users see answers sooner (reference, Claude Docs, 15 min)

    Cuts perceived latency by showing output as it is generated.

  8. Reuse shared prefixes on a self-hosted server (reference, vLLM, 15 min)

    The same caching idea applied to your own vLLM deployment.