{"head":{"title":"How to Reduce LLM API Costs: 8 Practical Levers | OceanLab","description":"Ways to cut LLM API costs without hurting quality: prompt caching, batch jobs, model routing, shorter context and output, and measuring the token mix.","canonical":"https://oceanlab.in/questions/how-to-reduce-llm-api-costs"},"crumbs":[{"name":"Home","path":"/"},{"name":"Questions","path":"/questions"},{"name":"How do I reduce LLM API costs?","path":"/questions/how-to-reduce-llm-api-costs"}],"question":"How do I reduce LLM API costs?","answer":["Measure first, then cut where the tokens are. Most savings come from caching the repeated start of your prompts, sending less context, capping output, moving non-urgent work to batch jobs and routing easy requests to a smaller model. Check each change with evals so quality does not drop."],"sections":[{"heading":"Start by measuring the token mix","body":[["Log ",{"href":"/glossary/token","text":"token"}," counts per feature, split into fresh input, cached input and output. Cost depends on that split, not just the total: an output-heavy feature and an input-heavy one with the same total can cost very different amounts, and the cheapest model for one may be the dearest for the other."],["Once you can see which feature and which part of the prompt uses the most tokens, you know which lever to pull first."]],"bullets":[]},{"heading":"The levers, roughly in the order to try them","body":[["Each one is independent, so you can combine them."]],"bullets":[[{"href":"/glossary/prompt-caching","text":"Prompt caching"},": put fixed instructions, tool definitions and shared documents at the start of the prompt and changing content after it, so repeated input is billed at the cached rate."],["Send less context: retrieve the few relevant passages with ",{"href":"/glossary/rag","text":"RAG"}," instead of whole documents, and trim old chat history."],["Cap output: ask for short answers, set a maximum output length and use ",{"href":"/glossary/structured-output","text":"structured output"}," instead of long prose where code reads the result."],[{"href":"/glossary/batch-api","text":"Batch API"},": move work nobody is waiting on, such as tagging, summaries and nightly reports, to batch jobs, which providers usually price lower."],[{"href":"/glossary/model-routing","text":"Model routing"},": send easy requests to a smaller model and escalate only the hard ones."],["Cache whole responses for repeated questions, so identical requests do not hit the model at all."],["Cut wasted calls: retries on errors, agents looping without a step limit, and duplicate calls from the front end."],["Compare providers on your own token mix and check for off-peak or discounted pricing that suits your workload."]]},{"heading":"Protect quality while you cut","body":[["Every saving that changes the model, the prompt or the context can change answers. Keep a set of ",{"href":"/glossary/llm-evals","text":"evals"}," built from real cases and run it before and after each change. A cheaper setup that fails your evals is not cheaper once support tickets and rework are counted."]],"bullets":[]}],"faqs":[{"question":"Is a smaller model always cheaper?","answer":"Per token, usually. Per task, not always: if it needs longer prompts, more retries or more human fixes to reach the same quality, the total can be higher. Compare cost per finished task."},{"question":"Does prompt caching change the answers?","answer":"No. Caching reuses the processed prompt prefix; the model sees the same input. It changes cost and often speed, not the output."},{"question":"Should we self-host an open model to save money?","answer":"Sometimes, at steady high volume. Self-hosting swaps per-token fees for the cost of machines, setup and engineers to run them, so compare the full cost, not only the per-token price."}],"terms":[{"href":"/glossary/token","label":"token"},{"href":"/glossary/prompt-caching","label":"prompt caching"},{"href":"/glossary/batch-api","label":"batch API"},{"href":"/glossary/model-routing","label":"model routing"},{"href":"/glossary/context-window","label":"context window"},{"href":"/glossary/inference","label":"inference"}],"tools":[{"href":"/tools/llm-api-cost-calculator","label":"LLM API cost calculator","detail":"Free tool"},{"href":"/tools/prompt-caching-savings","label":"Prompt caching savings","detail":"Free tool"},{"href":"/tools/token-counter","label":"Token counter","detail":"Free tool"},{"href":"/tools/llm-model-picker","label":"LLM model picker","detail":"Free tool"}],"links":[{"href":"/pricing/categories/llm-api","label":"LLM API pricing","detail":"Model prices side by side, with sources."},{"href":"/pricing","label":"Pricing library","detail":"Software and API prices, each with its source and date."},{"href":"/ai-automation","label":"AI automation","detail":"How OceanLab automates company workflows with AI."}],"related":[{"href":"/questions/who-owns-the-code","label":"Who owns the code when you hire a software agency?","detail":"Question"},{"href":"/questions/is-my-ai-system-high-risk","label":"Is my AI system high-risk under the EU AI Act?","detail":"Question"},{"href":"/questions/does-my-app-need-hipaa","label":"Does my app need to be HIPAA compliant?","detail":"Question"},{"href":"/compare/ai-agent-vs-workflow-automation","label":"AI agent vs workflow automation","detail":"Comparison"},{"href":"/compare/rag-vs-fine-tuning","label":"RAG vs fine-tuning","detail":"Comparison"},{"href":"/glossary","label":"Glossary","detail":"Every term, in plain words."}],"sources":[],"legal":false,"updatedAt":"2026-10-25"}