{"success":true,"name":"budget-llm-calls-like-money-token-caps-caching-and-model-tie","description":"Building a feature or tool that calls a paid LLM API","category":"ai-brimind","path":"ai-brimind/budget-llm-calls-like-money-token-caps-caching-and-model-tie/SKILL.md","file":"SKILL.md","content":"---\nname: budget-llm-calls-like-money-token-caps-caching-and-model-tie\ndescription: \"Building a feature or tool that calls a paid LLM API\"\n---\n\n# Budget LLM Calls Like Money: Token Caps, Caching, and Model Tiering\n\n## When to use\nThe project makes LLM API calls (chat, generation, agents), and nobody has set cost controls, caps, or thought about which model each call really needs.\n\n## Example request\nAgent loop re-sends the entire growing history every iteration → cost grows quadratically with turns; context trimming or summarizing is the standard containment. — Every tiny classification uses the flagship model → the strongest model does work a cheap model handles fine; model tiering matches model size to task difficulty. — A retry bug loops all night → hundreds of dollars burned silently; a spend alert and hard cap is the smoke detector. — Same expensive prompt computed for every user → identical inputs mean identical outputs; caching responses (and using the provider's prompt caching) is free money.\n\n## Instructions\nAct as a finance controller who treats every token as a coin leaving the account, because it is. When designing anything that calls LLM APIs: 1) Price the design before building it: tokens in and out per call, times calls per user action, times expected volume — a ten-minute estimate reveals whether the architecture is affordable at all; discovering cost in the invoice is discovering it too late. 2) Tier the models: map each call type to the cheapest model that does the job reliably — classification, extraction, and reformatting rarely need the flagship; reserve the expensive model for the genuinely hard steps. 3) Attack the biggest lever, context size: cap max output tokens per call, trim or summarize conversation history instead of resending everything, and send only the context the task needs — in loops and agents, unbounded context is the classic quadratic cost bug. 4) Cache aggressively: identical or near-identical requests should hit a cache, and use the provider's prompt-caching for large stable prefixes like system prompts — reuse the platform mechanism before building your own. 5) Install the safety rails: provider spending limits, alerts at thresholds, per-user/per-session call budgets, and hard iteration caps on any loop — a runaway loop with no cap is an open wallet. If real usage is unknown, log token counts per call from day one; you cannot budget what you don't measure. Only scale the feature once measured cost per user action is confirmed acceptable, and explain which lever (tiering, context, caching, caps) controls each cost component rather than hoping the bill stays small.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #976\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}