Where AI spend actually comes from
For API-based systems, cost is a function of input tokens, output tokens and the price per token of each model, multiplied by the number of calls. For self-hosted models, cost is GPU time, which depends on utilization, batching and model size. In practice most waste falls into a few patterns: the largest model used for every task, long prompts repeated on every call, retrieved context that is mostly irrelevant, agents that call models many times per task, and GPUs that sit idle between peaks. The first job is to see which of these apply to you, measured per feature and per successful task rather than per month.
The main methods
Model routing and cascades
Not every request needs the most capable model. A router sends each request to the smallest model likely to handle it, based on task type, a lightweight classifier or rules. A cascade tries a small model first and escalates to a larger one when confidence is low or a validation check fails. Routing works best when tasks are clearly separable, such as classification versus open-ended reasoning.
Prompt caching
Major API providers offer prompt caching, which reuses the processed form of a repeated prompt prefix at a reduced rate and with lower latency. To benefit, the stable parts of a prompt (system instructions, tool definitions, reference documents) must come first and stay byte-identical across calls, with variable content at the end. Many teams already pay for large static prefixes and get little cache benefit because timestamps or user data sit at the top of the prompt.
Response caching
Exact-match caching returns a stored answer for an identical request. Semantic caching returns a stored answer for a sufficiently similar request, using embeddings. Semantic caching needs care: similar questions can need different answers, and cached answers can leak data across users if the cache is not scoped correctly. It suits FAQ-style traffic, not personalized or time-sensitive answers.
Smaller, fine-tuned and distilled models
For narrow, high-volume tasks, a smaller model fine-tuned on examples, often including outputs from a larger model (distillation), can meet the quality bar at a fraction of the compute. This requires a solid evaluation set and a plan for retraining when the task changes. See Model Training & Fine-Tuning for that work.
Context and prompt reduction
Better retrieval (smaller chunks, reranking, fewer passages), summarizing long conversation history, removing unused tool definitions and trimming few-shot examples all reduce input tokens. Asking for structured, concise outputs reduces output tokens, which are usually priced higher than input tokens.
Batching and serving efficiency
Work that does not need an instant answer, such as nightly document processing, evaluations or bulk enrichment, can use providers' batch APIs, which trade latency for lower cost. For self-hosted models, serving engines such as vLLM and SGLang use continuous batching and memory-efficient caching to serve more requests per GPU, and quantization reduces memory needs. Autoscaling to traffic avoids paying for idle capacity.
Budgets and guards
Token budgets per request, user, tenant and agent run, step limits for agents, and alerts on unusual spend stop runaway costs. They also protect against abuse, which OWASP lists as unbounded consumption.
Why evaluation comes first
Every method above can reduce quality if applied blindly. A smaller model may miss edge cases, aggressive context trimming may drop the passage that held the answer, and a semantic cache may return a subtly wrong response. That is why we build an evaluation set and baseline before touching anything, and require each change to pass it. The same evaluation gates then protect you when providers release new models or change prices. If you do not yet have evaluation in place, our AI Evaluation & Observability Setup service builds it.
Scope
This service focuses on model and inference costs for AI workloads. General cloud cost management, reserved capacity and FinOps practices are covered in Cloud Cost Optimization & FinOps, and ROI cases for new AI projects in ROI Modeling.