Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Cheat sheet

LLM cost levers cheat sheet

The main ways to cut model spend, ordered by effort, with what each saves, what it risks and how to check quality held. Checked against provider docs.

By Checked Intermediate
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

The cheapest ways to cut LLM costs are to measure spend per feature, trim prompts, cap output length and cache repeated prompt prefixes. Next come batch APIs for work that can wait and routing easy requests to smaller models. Self-hosting only pays at high, steady volume. Check quality with the same eval set after every change.

First, measure

Log tokens and cost per request, tagged with the feature and prompt version. Without that you cannot tell which lever matters. A gateway or an observability tool can do this without code changes: the LLM gateway comparison covers LiteLLM, Portkey, OpenRouter and Helicone, and Langfuse records cost per trace.

LLM cost levers, roughly cheapest first

Lever What it saves Risk How to check
Trim the prompt Input tokens on every call Dropping an instruction the model needed Run your eval set before and after
Retrieve fewer, better chunks Input tokens; often improves answers too Missing context Context recall on a golden set
Cap output length (parameter names in the LLM API parameters cheat sheet) Output tokens, which cost more than input Truncated answers Count truncated responses in traces
Prompt caching Repeated input prefixes Little; cache writes cost extra Cached-token counts in API usage fields
Lower reasoning effort (see reasoning effort parameters) Thinking tokens Worse answers on hard cases Eval at two or three effort levels
Batch API Half the price for work that can wait Results arrive later Compare batch and live outputs on a sample
Pick the smallest model that passes your eval for the whole feature Often most of the bill Harder cases fail Run the same eval set on two or three model sizes
Route easy requests to a smaller model Most of the cost of those requests Quality drop on misrouted cases Eval per route; watch escalation rate
Semantic caching Whole calls for repeated questions Wrong answer for a similar but different question Review a sample of cache hits
Cap agent steps and tokens Runaway loops Agent stops before finishing Completion rate per task
Summarise or drop old turns in long chats and agent runs Input tokens that grow with every turn Losing a detail the model needs later Replay long sessions and check the later answers
Self-host an open model Per-token fees at high, steady volume GPU and operations cost, quality gap Total cost of ownership and evals

Provider numbers worth knowing

Item Anthropic OpenAI
Batch discount 50% 50%
Batch turnaround Most batches under an hour Within 24 hours
Batch and rate limits Separate batch limits Batch jobs do not count toward standard per-model limits; they use a separate queued-token limit
Prompt cache Opt in with cache_control, per block or once at the top level; default lifetime 5 minutes, or 1 hour with "ttl": "1h" Automatic for long enough prompts
Cache pricing Reads 0.1x base input on most models (0.05x on Opus 5.5 and Sonnet 5.5); writes 1.25x for 5 minutes, 2x for 1 hour Discounted cached input; rate varies by model
  • A 1-hour cache pays off when the gap between reuses of a prefix is longer than 5 minutes but shorter than an hour.
  • OpenAI’s flex processing tier is being wound down, so do not build new work on it.
  • Prices and limits change often. Check the provider’s pricing page before you rely on a number.

The glossary explains prompt caching and the batch API if either is new to you.

Make caching work

  • Put stable content first: system prompt, tool definitions, long documents, examples.
  • Put the parts that change per request (the user’s question, today’s date) last.
  • Keep tool order and formatting identical between calls; a single changed byte early in the prompt breaks the cache.
  • Check the usage fields in responses to confirm cached tokens are being counted.

Budgets that hold

# LiteLLM proxy: create a team with a budget that resets every 30 days
curl -X POST 'http://localhost:4000/team/new' \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"team_alias": "support-bot", "max_budget": 200, "budget_duration": "30d"}'

Set budgets per team or key in the gateway, alert at a share of the budget before the hard stop, and review the top ten most expensive traces every week.

For the full method behind these levers, see the LLM cost optimisation skill page, with its tutorials and tools, and the prompt caching and token costs tutorial.

Check your understanding

LLM cost levers quiz

Measuring spend first, the levers from prompt trimming to self-hosting, batch and cache numbers, ordering prompts for caching, and budgets in a gateway.

7 questions · pass mark 70%

Question 1 of 70 answered
  1. Your LLM bill doubled. What does the cheat sheet say to do before pulling any lever?

Checked against

  • LLM cost optimisation

    Cutting LLM costs with caching, model routing, batching and budgets.

    SkillIntermediate

  • LLM gateways compared: LiteLLM, Portkey, OpenRouter and Helicone

    Four LLM gateways that put one API in front of many models, compared on hosting, budgets, routing and logging.

    Comparison

  • Prompt caching

    Reusing the processed form of a repeated prompt prefix, such as a long system prompt, across requests to reduce latency and cost.

    Glossary

  • Batch API

    A provider endpoint that takes many requests at once and returns results later, typically within 24 hours, at a lower price than live requests.

    Glossary

  • Model routing

    Choosing which model handles each request, often sending easy requests to a small, cheap model and hard ones to a larger model.

    Glossary

Back to top