Lesson 4 of 6 Data Transfer and Cost-Optimized Design

Optimising the Cost of AI and ML Workloads

This lesson explains the cost levers for generative AI and ML inference: model choice, service tiers, batching, caching and scale-to-zero hosting.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why model choice is the largest generative AI cost lever.
  • Choose between service tiers, batch inference, prompt caching and semantic caching.
  • Identify cost levers for self-hosted inference on SageMaker AI.

Model choice and service tiers

The largest lever is the model: smaller models cost a fraction of the largest ones per token and respond faster, so evaluations should find the smallest model that meets quality targets for each task. Intelligent prompt routing can send simpler requests to a smaller model in the same family, and model distillation trains a smaller model from a larger one's outputs. Bedrock service tiers then price the same model differently: Priority at a premium for latency-critical traffic, Standard by default, Flex at a discount for work that tolerates longer processing, and Reserved capacity for guaranteed tokens per minute.

Scenario questions

The biggest AI cost lever

Exam skills 3.1.4 · 3.2.5

Choose the most effective way to reduce generative AI cost.

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

Batching and caching

Batch inference processes large sets of prompts from S3 asynchronously at about half the on-demand price, which suits nightly classification, summarisation or enrichment. Prompt caching stores repeated prompt prefixes, such as long system prompts, instructions or documents, so later requests pay much less for those tokens and respond faster. Application-level semantic caching, for example in ElastiCache for Valkey with vector search, answers repeated or very similar questions without calling the model.

Workload patternCost lever
Same long prompt prefix on every requestPrompt caching
Millions of offline promptsBatch inference
Latency-tolerant background generationFlex tier
Repeated user questionsSemantic cache in front of the model
Simple tasks on an expensive modelSmaller model or prompt routing
Match the pairs

AI cost levers

Exam skills 3.1.4

Match each workload pattern with the cost lever that suits it.

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

Self-hosted inference on SageMaker AI

For models on SageMaker AI, idle instances are the main waste. Serverless inference and asynchronous inference scale to zero; multi-model endpoints and inference components share instances among models; batch transform avoids persistent endpoints; and Machine Learning Savings Plans discount steady usage. Data transfer adds cost too: keep knowledge bases, vector stores and endpoints in the application's Region, use VPC endpoints instead of NAT gateways, and rely on cross-Region inference, which adds no routing charge, rather than building custom multi-Region inference.

Worked example

Halving an assistant's bill

A support assistant's Bedrock bill doubled in three months. Analysis shows a 9,000-token system prompt on every request, many repeated questions, and a nightly job that summarises every ticket with the largest model.

The team enables prompt caching for the system prompt, adds a semantic cache that answers the most frequent questions, and evaluates a smaller model, which matches quality for summaries.

The nightly job moves to batch inference with the smaller model. Together these changes cut the bill by more than half with no loss of quality in the evaluation set.

Check yourself

Which feature reduces the cost of a 9,000-token system prompt sent with every request?

Show answer

Prompt caching, which stores the repeated prefix so later requests pay much less for those tokens and respond faster.

Exam Tips

Remember for the exam

  • Repeated long prompts: prompt caching; large offline jobs: batch inference.
  • Latency-tolerant work: Flex tier; guaranteed throughput for critical traffic: Reserved tier.
  • Choose the smallest model that meets evaluated quality.
  • Idle self-hosted endpoints: serverless or asynchronous inference that scales to zero.