# Skill: Estimate AI API cost and route tasks across model tiers to minimize spend > Lets an AI coding/design agent calculate approximate token-based costs, assign tasks to the correct price/speed tier, and design a cascade architecture; applies whenever building or auditing an AI-powered workflow that calls a model API. Source: sodigi·learn — models/cena-i-skorost · https://sodigi.io/learn/models/cena-i-skorost ## When to use - Designing a new feature that calls a model API more than a handful of times per day. - Auditing an existing integration where the monthly API bill is unexpectedly high. - Advising on which tier to use for a specific sub-task inside a larger pipeline. - Explaining to a non-technical stakeholder why some AI calls cost more than others. ## Core rules - You pay per token, not per request -- both input and output tokens are billed. - Output tokens are priced higher than input tokens (often several times higher); long generated answers cost more than long questions. - Every model family has three tiers: cheap/fast (little), mid-tier (workhorse), expensive/smart (heavyweight). Match tier to task complexity. - The chat history is input on every turn -- a long conversation is re-billed in full with each new message. - Specific prices go stale monthly; always check the provider's current pricing page before any calculation. - Caching repeated input (e.g., a fixed system prompt or knowledge base) can sharply reduce repeat costs. - Batch processing (non-real-time requests) is often discounted by providers. ## Procedure 1. Identify each distinct task in the workflow (e.g., classify email, write reply, extract phone number). 2. For each task, assign a tier: classification/extraction/simple routing -> cheap/fast; writing/explaining/basic code -> mid-tier; complex code/multi-step reasoning/long analysis -> heavyweight. 3. To estimate cost for a task: a. Count input words (question + attached text + history). Multiply by ~1.3 for English token estimate; budget more for other languages. b. Estimate output words. Multiply by ~1.3. c. Look up current input price and output price (per 1000 tokens) on the provider's pricing page. d. Cost = (input_tokens * input_price) + (output_tokens * output_price). e. Multiply by daily request volume and by 30 for a monthly estimate. 4. Apply the cascade pattern for ambiguous tasks: run cheap model first; if it passes a simple quality check, done; otherwise escalate to heavyweight. Most requests never reach the expensive tier. 5. Trim context: remove history, files, and instructions the model does not need for the current turn. ## Ready-to-use prompt ``` You are an AI cost optimization advisor. I will describe an automation pipeline. For each task in the pipeline, recommend the cheapest model tier that can reliably handle it (cheap/fast, mid-tier, or heavyweight), and briefly explain why. Pipeline: [list each step of the pipeline, one per line] For each step return: step name | recommended tier | one-line reason. ``` ## Pitfalls - Using the flagship/heavyweight model "just in case" for every task -- this is a freight truck for a single envelope; the bill inflates without quality gain on simple tasks. - Thinking you pay per "request" -- you pay per token; a short question about a long pasted document costs the same as a long question. - Forgetting that the full chat history is re-sent as input on every turn in a long conversation. - Memorizing specific price numbers -- they change frequently; always verify live on the provider page before committing to a cost estimate. - Chasing cheapness to the point of degraded quality -- if the cheap model fails and you redo the task three times, the savings evaporate. - Ignoring output length -- asking for "a detailed 20-paragraph explanation" when a 3-bullet summary would do costs significantly more.