AI and LLM cost optimization

Model routing, caching, smaller models and token budgets without losing quality. For teams already running AI in production: reduce model and GPU spend with routing, prompt and semantic caching, smaller or distilled models, batching and token budgets, with evaluation checks so answer quality does not drop.

A free first call with an engineer. You leave with a scoped next step.

Discovery Sprint to a roadmap
1–2 wks
Scope quote before anything is built
Fixed
30-minute first call
Free

What we deliver. Written by engineers who build these systems.

AI costs grow quietly. A feature that cost little in a pilot becomes a large line item once real traffic, long prompts, retries and agent loops add up. AI cost optimization finds where tokens and GPU time go, then applies proven methods such as routing, caching, smaller models, batching and budgets. Gepton does this for teams already running AI in production, and every change is checked against an evaluation set first so savings never come at the cost of answer quality.

Technologies

  • LiteLLM
  • Portkey
  • OpenRouter
  • Langfuse
  • Helicone
  • OpenTelemetry
  • vLLM
  • SGLang
  • Redis
  • GPTCache
  • Batch APIs
  • Prompt caching
  • Hugging Face
  • Kubernetes
  • Grafana
  • Cost and usage breakdown per feature, workflow, customer segment and model, built from your logs or traces
  • Cost-per-successful-task metric, so spend is linked to outcomes rather than raw token counts
  • Evaluation set and quality baseline for each workload before any change is made
  • Model routing design and implementation that sends each request to the smallest model that passes the bar
  • Prompt caching setup and prompt restructuring so static content is reused across requests
  • Semantic or exact-match response caching where answers can safely be reused
  • Prompt and context reduction: shorter system prompts, better retrieval, history summarization
  • Batch processing for non-urgent jobs and right-sized serving for self-hosted models
  • Token budgets, rate limits and loop guards per user, tenant and agent run, with alerts
  • Optimization report with each change, its quality result and a rollback path

What gets in the way. The problems teams bring to us.

Use cases. Where clients put AI cost optimization to work.

  • Support assistant using a frontier model for every message

    Simple intents such as order status are routed to a small model, while complex complaints still reach the larger model.

  • RAG system sending too much context

    Better chunking, reranking and fewer retrieved passages shorten prompts while answer accuracy is checked on a fixed test set.

  • Long, repeated system prompts

    Prompts are restructured so the stable part comes first and provider prompt caching can reuse it across requests.

  • Nightly document processing

    Non-urgent extraction and classification jobs move to batch APIs or scheduled self-hosted runs.

  • Agent with runaway loops

    Step limits, token budgets per run and better tool error handling stop costly loops and retries.

  • Self-hosted model with idle GPUs

    Quantization, continuous batching and autoscaling improve GPU utilization and remove over-provisioned capacity.

  • High-volume classification task

    A small model fine-tuned or distilled on outputs from a larger model handles the task, with the large model as fallback.

How a project runs. A fixed-scope plan before anything is built.

How we work
  1. 1

    Measure

    We instrument or read your existing logs to break down cost by feature, model, customer and step, and find the few workloads that account for most of the spend.

  2. 2

    Set a quality baseline

    For each priority workload we build an evaluation set from real traffic and record current quality, so every later change is compared against a fixed bar.

  3. 3

    Apply optimizations

    We apply the relevant methods one at a time: routing, caching, prompt reduction, smaller or fine-tuned models, batching and serving changes.

  4. 4

    Verify and roll out

    Each change must pass the evaluation before release, then goes out gradually with monitoring of quality, latency and cost.

  5. 5

    Keep it in place

    We add budgets, alerts and a cost dashboard, and document the evaluation gates so future changes do not reverse the gains.

Who it is for. And how we work with you.

A good fit if you are

  • Companies whose AI or GPU bill has grown faster than usage or revenue
  • SaaS products with AI features where cost per customer affects margins
  • Teams running AI agents whose cost per task is unknown or unpredictable
  • Organizations self-hosting models on GPUs with low or uneven utilization
  • Finance and engineering leaders who need to forecast AI spend before scaling

How we work

Quality is the constraint
No change ships unless it passes the evaluation baseline for that workload. Saving money by making the product worse is not optimization.
Methods, not promises
We do not quote savings figures in advance. We measure your baseline, apply methods that fit, and report the actual effect of each one.
Provider-neutral advice
We do not resell models, APIs or GPUs, so recommendations are based only on your workloads and data.
Changes you can reverse
Every optimization has a feature flag or rollback path, and gradual rollout with monitoring.

A closer look at AI cost optimization

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.

Engagement models. Each one scoped and quoted after a first call.

How engagements work

1–2 weeks

Discovery Sprint

We map one process with your team, check the data and systems, and hand you a roadmap with a fixed-scope quote for the first build. You also get our technology recommendations and the success measures we agree with you up front.

4–8 weeks

Pilot Project

Our engineers build one focused system in weekly releases, connect it to your tools and put it in front of real users. Testing, deployment, monitoring, training and documentation are part of the pilot, with 30 days of support after launch.

Monthly retainer

Ongoing Partnership

A dedicated team that keeps building, runs what is live, and reports on quality and cost every month. It covers new features, performance and infrastructure work, model updates, and priority support under an agreed SLA.

No prices are published: you approve a written scope and quote before we build.

AI cost optimization in depth

Attributing cost before cutting it

Provider invoices show totals by model, not by feature or customer, so the first technical step is attribution. Every model call is tagged with the feature, workflow step, tenant or customer, user type and environment, usually at a gateway or in the tracing layer. Token counts and computed cost are attached to each trace, so a single support conversation or agent run shows exactly what it cost and where. For SaaS companies this also produces unit economics per customer and per plan, which often matters more to product and pricing decisions than the total itself. Development and evaluation traffic is separated from production, because test runs can be a surprising share of spend.

Attribution usually reveals a concentration: a few features, workflows or customers account for most of the spend. We rank optimization candidates by expected saving, confidence in that estimate and the effort and quality risk involved, then agree the order with your team. Working on the largest, safest opportunities first produces visible results early and funds the attention that riskier changes need.

Choosing methods by fit and risk

The page above describes each method. The table below is how we decide which to try first for a given workload.

MethodBest fitQuality riskEffort
Prompt cachingLong, stable system prompts, tool lists or reference documentsNone if prompts are unchangedLow: reorder prompt content
Context reductionRAG and agents carrying large retrieved text or historyMedium: may drop needed contextMedium
Model routingMixed traffic of simple and complex requestsMedium: misrouted hard casesMedium
Batch processingNon-urgent jobs such as nightly extraction or evaluationsNone, latency onlyLow to medium
Response cachingRepeated, non-personal questionsMedium: stale or wrong reuseMedium
Fine-tuned or distilled small modelHigh-volume narrow tasksManaged through evaluationHigh

Low-risk, low-effort changes usually go first, because they produce savings while the evaluation baseline for riskier changes is being built.

Agent-specific waste

Agents introduce cost patterns that simple chat features do not have. Context grows with every step as tool results and earlier reasoning accumulate, so later steps cost far more than early ones. Tools often return far more data than the agent needs, such as a full record when one field would do. Reflection or self-check loops can repeat without improving the result, and retries on tool errors can multiply calls. We address these by trimming and summarizing tool outputs before they enter context, pruning history between steps, setting step and token limits per run, and fixing the tool errors that cause retries. Trace data shows which of these patterns affects your agents, and by how much. Changes to agent behavior are checked with trajectory evaluation, so a cheaper run that skips a necessary step is caught.

Capacity, contracts and providers

Beyond technical changes, how you buy capacity affects cost. Pay-per-token suits variable or growing traffic. Provisioned or reserved throughput, offered by several providers and clouds, can suit steady high volumes but is paid whether used or not, so it needs utilization data before commitment. Using more than one provider through a gateway allows routing by price and availability, at the cost of evaluating each model. For self-hosted models, the choice between on-demand, reserved and owned GPUs follows the same logic. We present these as options with the drivers and the utilization needed for each to make sense, and leave commercial decisions to you. Region choice can matter as well, since the same model may be offered at different terms or not at all in some regions, so data residency needs and cost are reviewed together. General cloud commitments are covered by Cloud Cost & FinOps.

Reasoning models and long contexts

Reasoning models generate internal reasoning tokens before answering, and providers generally bill these as output tokens, which are usually priced higher than input. A task that looks short can therefore be expensive. Many offer a setting for reasoning effort; lowering it for simpler tasks, or routing those tasks to a non-reasoning model, often keeps quality while cutting cost and latency. Large context windows invite sending whole documents on every call, which raises cost even with caching. Both are checked against the evaluation set, because the right setting differs by task.

Making savings last

Costs creep back when nobody owns them. We assign a cost owner per AI feature, set budgets with alerts at the tenant, feature and agent-run level, and include cost per successful task in the same dashboard as quality and latency, so teams see trade-offs together. Changes to prompts, models or retrieval run through evaluation gates that also report cost impact, so a quality improvement that doubles cost is a visible decision rather than a surprise on the next invoice. A short regular review of the top cost drivers keeps attention on the workloads that matter. For forecasting cost of new projects, see ROI Modeling and the agent running cost estimator.

Questions about AI cost optimization

Something else? Send us your question and an engineer replies with next steps.

How much can we save?

We do not promise a figure in advance, because it depends on your workloads, models, traffic and current setup. The first phase measures where your spend goes and which methods apply, and we share realistic options at that point. After each change we report the measured effect on cost, latency and quality.

Will quality drop?

Not if the process is followed. We build an evaluation set from your real traffic and record a quality baseline before making changes. A change only ships if it passes that baseline, and rollout is gradual with monitoring. If quality slips in production, the change is rolled back.

What data do you need to start?

Usage data from your model providers or gateway, application logs or traces showing which feature made each call, and sample requests and responses (anonymized if needed) to build evaluation sets. If you have no per-feature tracking, adding it is the first step.

How long does it take?

The measurement and baseline phase typically takes 2 to 3 weeks. Optimizations are then applied in stages over 3 to 8 weeks depending on how many workloads are in scope and how quickly changes can be released.

Do we have to change model provider?

No. Many gains come from routing within one provider's model family, prompt caching, context reduction, batching and budgets. Switching providers or moving some workloads to self-hosted models is an option we evaluate, not a requirement.

Is semantic caching safe?

It can be, with limits. We use it only for workloads where similar questions truly deserve the same answer, scope caches per tenant or user where needed, set similarity thresholds conservatively, expire entries, and test it against the evaluation set. For personalized or time-sensitive answers we do not use it.

Should we move to self-hosted models to save money?

Sometimes. Self-hosting can be economical at steady, high volume with good GPU utilization, but it adds operational work and needs engineering time. For spiky or low traffic, APIs are often simpler. We compare both using your measured traffic and quality results.

How does this differ from Cloud Cost & FinOps?

Cloud Cost & FinOps covers general cloud spend: compute, storage, networking, commitments and cost allocation across your whole estate. AI Cost Optimization focuses on how AI workloads use models and GPUs: which model handles which request, token usage, caching, batching and serving efficiency, all guarded by quality evaluations.

What access do you need?

Read access to usage dashboards and logs or traces, access to a staging environment to test changes, and a small set of engineers to review and merge pull requests. Production changes go through your normal release process.

What stays with us afterward?

The cost dashboard, evaluation sets, routing and caching configuration, budget rules and all code, in your repositories. Your team can keep optimizing with the same gates, and Gepton can review costs periodically if you want.

Can we see AI cost per customer for our SaaS product?

Yes. We tag every model call with the tenant or customer and attach token counts and computed cost to each trace. That produces cost per customer, per plan and per feature, which shows whether your heaviest users are profitable and helps product and pricing teams set usage limits or tiers. Development and test traffic is kept separate so it does not distort the numbers.

Do reasoning models change the cost picture?

Yes. Reasoning models produce internal reasoning tokens that providers generally bill as output, so a short answer can carry a large hidden token count. Lowering reasoning effort for simpler tasks, or routing them to a non-reasoning model, often cuts cost and latency without a quality loss. We test each option against your evaluation set before changing anything in production.

Is provisioned or reserved throughput worth it?

It can be for steady, high-volume traffic, because capacity is paid for whether used or not. The decision depends on how consistent your traffic is across the day and week and how much of the reserved capacity you would actually use. We measure your traffic profile from traces and show the utilization needed for each option to make sense, then you decide commercially.

How do we stop one tenant or user from driving up costs?

Set token budgets and rate limits per tenant, user and agent run, enforced at the gateway, with alerts when usage approaches limits. Agents get step limits and loop guards. Unusual spikes are flagged automatically, which also helps detect abuse. Limits are tied to your plans or contracts, so heavy users can be offered a higher tier instead of being silently subsidized.

Will optimization make responses slower?

Most methods make responses faster, not slower. Prompt caching, shorter contexts, smaller models and response caching all reduce latency. Batch processing is the exception: it trades speed for lower cost, so we use it only for work that does not need an immediate answer. Every change is measured for latency as well as quality and cost before rollout.

Related services. More from AI Consulting & Strategy.

See AI consulting & strategy

Jump to

↑↓ to move↵ to open