Lesson 2 of 2 AI Workload Cost Optimization

Optimizing AI Inference and Training Costs

Engineers have many levers to reduce AI cost without reducing quality. This lesson covers model selection and routing, prompt and context optimization, caching, batch processing, accelerator utilization and governance of AI spend.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain model selection and routing as cost levers.
  • Identify techniques that reduce token usage.
  • Describe prompt caching and response caching.
  • Describe how to improve accelerator utilization.
  • Describe governance practices for AI spend.

Choose the right model

The largest single lever is model selection. A smaller or older model may handle classification, extraction, summarization or simple question answering as well as a larger model, at a small fraction of the price per token and with lower latency. The right choice is the smallest model that meets the quality requirement, established through evaluation on representative examples rather than by assumption.

Model routing extends this idea: a router sends simple requests to a cheap model and only complex requests to an expensive one. Fine-tuning or distilling a smaller model for a specific task can also replace a large general model for high-volume use cases, although training has its own cost.

The following diagram shows requests routed between a small and a large model.

Routing simple requests to a small model. A cheap classifier sends the requests that a small model handles equally well to it, at a fraction of the price per request, and only the rest to the large model. When most requests are simple, total cost falls sharply, while quality is monitored.
The classifier's small cost is not shown.

Reduce tokens

Because cost is proportional to tokens, reducing tokens reduces cost directly. The following list describes common techniques.

  • Concise instructions: remove redundant text from system prompts that are sent with every request.
  • Targeted retrieval: send only the most relevant document chunks rather than whole documents.
  • Conversation management: summarize or trim long conversation histories instead of resending everything.
  • Output limits: request concise answers and set maximum output tokens appropriate to the task.
  • Fewer calls: design agents and workflows to avoid unnecessary model calls and retries.
Match the pairs

AI cost levers

Exam skills 7.4.3

Match each AI cost problem with the lever that addresses it.

Log in to try this activity Interactive activities are free with an account.

Caching

Prompt caching, offered by many model services, stores repeated prompt prefixes, such as a long system prompt or a reference document, so that later requests reuse them at a reduced input price and with lower latency. Structuring prompts so that the stable part comes first makes caching effective. Response caching at the application level returns a stored answer for identical or near-identical questions without calling the model at all.

Batch and asynchronous processing

Work that does not need an immediate answer, such as classifying a day's documents, generating product descriptions or evaluating a model, can use batch inference at a significant discount. Designing pipelines to collect such work and submit it in batches turns a latency-tolerant workload into a cheaper one.

Scenario questions

When work can wait

Exam skills 7.4.3

Choose how to run AI work that does not need an immediate answer.

Log in to try this activity Interactive activities are free with an account.

Accelerator utilization

For self-hosted inference and training, cost follows accelerator hours, so utilization is critical. The following comparison sets out common problems and remedies.

Inference endpoints
Common wasteEndpoints running with little traffic, oversized instances
RemediesAutoscaling, scale to zero where supported, smaller or shared instances, efficient serving
Choose when Serving traffic in production
Training jobs
Common wasteIdle GPUs waiting for data, failed runs restarted from scratch
RemediesEfficient data loading, checkpointing, spot capacity for checkpointed jobs
Choose when Training or fine-tuning models
Notebooks and experiments
Common wasteGPUs left running when nobody is working
RemediesAutomatic idle shutdown, scheduled stops, smaller instances for development
Choose when Interactive development

Purpose-built accelerators, such as AWS Inferentia and Trainium, Google Cloud TPUs and other provider chips, can offer better price-performance than general-purpose GPUs for supported models.

Governing AI spend

AI spend needs the same FinOps practices as other technology, adapted to its pace. Requests should be allocated to teams and features, for example through separate projects, API keys or request metadata. Budgets and anomaly detection catch runaway usage, such as an agent stuck in a loop. Quotas and rate limits cap exposure. Unit cost per feature is tracked alongside quality metrics, so that optimizations that degrade answers are caught.

Worked example

Routing to a smaller model

A document-processing service sends 2 million requests a month to a large model at an average of USD 0.012 per request. Evaluation shows that a small model handles 75% of requests with equal quality at USD 0.001 per request, and a classifier can identify those requests cheaply. What is the saving?

Today: 2,000,000 x 0.012 = USD 24,000 a month. With routing: 1,500,000 x 0.001 = USD 1,500 for the simple requests and 500,000 x 0.012 = USD 6,000 for the rest, USD 7,500 in total, plus the small cost of the classifier. The saving is about USD 16,500 a month, around 69%, provided quality is monitored to confirm that the small model continues to perform.

Worked example

The weekend GPU

A data science team's cost report shows four GPU instances at USD 12 per hour each running every weekend with no activity. What is the cost, and what control would prevent it?

Over a 48-hour weekend: 4 x 12 x 48 = USD 2,304, roughly USD 10,000 a month for no work. An automatic idle shutdown for notebooks and development instances, for example after an hour without activity, combined with a scheduled stop on Friday evening and an anomaly alert for GPU usage outside working hours, would prevent it.

Check yourself

How should a team decide whether a smaller model is good enough for a task?

Show answer

By evaluating it on representative examples against the quality requirement, then monitoring quality after rollout, rather than assuming that the larger model is needed or that the smaller one is sufficient.

Exam Tips

Remember for the exam

  • Use the smallest model that meets quality, and route simple requests to cheaper models.
  • Reduce tokens with concise prompts, targeted retrieval and output limits.
  • Use prompt caching and batch inference for repeated context and work that can wait.
  • Keep accelerators busy and shut down idle endpoints and notebooks.