Lesson 5 of 7 Cost and Capacity Optimization

Estimating and Reducing Foundation Model Inference Costs

This lesson explains the cost structure of foundation model inference, how to evaluate its cost implications in production and how to manage it with usage optimisation.

Learning outcomes

After completing this lesson, you will be able to:

  • Calculate FM cost per request.
  • Reduce input and output tokens.
  • Choose a deployment model by cost and volume.

How FM costs are calculated

On-demand Bedrock cost per request is input tokens x input price + output tokens x output price, with output tokens usually several times more expensive. Prices differ greatly between models. RAG adds retrieved context to input tokens; conversation history accumulates; agents make several model calls per task; guardrails, embeddings and reranking add their own charges. Provisioned Throughput is charged per model unit per hour regardless of use, and self-hosted models cost instance hours.

Cost per request (on-demand):
  input:  3,000 tokens x price_in  / 1,000
  output:   400 tokens x price_out / 1,000
Monthly cost = cost per request x requests per month
Compare with: Provisioned Throughput hours x price, or self-hosted instance hours
Fill in the value

Estimate the bill

Exam skills 4.2.7

Estimate monthly on-demand foundation model cost from token use.

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

Usage optimisation

Reduce input tokens by shortening system prompts, retrieving fewer but better chunks (reranking helps), summarising conversation history and using prompt caching for repeated prefixes. Reduce output tokens with explicit length instructions, structured formats and maxTokens limits. Reduce the number of calls by caching answers to repeated questions and batching. Reduce the price per token with smaller or distilled models, intelligent prompt routing, batch inference and the Flex tier.

Sort into groups

Cut input or output tokens?

Exam skills 4.2.9

Decide whether each change mainly reduces input tokens or output tokens.

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

Choosing a deployment model by cost

At low or variable volume, on-demand is usually cheapest. At very high, steady volume, Provisioned Throughput, the Reserved tier or self-hosting an open model may cost less per token, but they shift utilisation risk to you. The following table summarises the optimisation levers.

LeverReduces
Prompt cachingCost and latency of repeated input prefixes
Shorter prompts, fewer chunks, history summarisationInput tokens
Length limits and concise formatsOutput tokens
Response cachingNumber of calls
Smaller, distilled or routed modelsPrice per token
Batch inference, Flex tierPrice for non-urgent work

The following diagram compares the input tokens per request of a RAG assistant before and after four cost-saving changes.

Input tokens per request for the RAG assistant before and after. Reranking sends 3 chunks instead of 8, cutting input from about 6,000 to 2,500 tokens, and the 1,000-token system prompt is cached. Intelligent prompt routing sends simple questions to the smaller model, and a response cache answers the 15% of questions that repeat exactly. Estimated monthly cost falls by more than 60% with unchanged quality.
Bar lengths are proportional to tokens.
Worked example

Estimating and cutting cost

A RAG assistant handles 2 million requests per month with 6,000 input tokens (including 8 chunks) and 500 output tokens per request on a large model.

  • Reranking lets the assistant send 3 chunks instead of 8, cutting input to about 2,500 tokens.
  • Prompt caching covers the 1,000-token system prompt and instructions.
  • Intelligent prompt routing sends simpler questions to the smaller model in the family.
  • A cache answers the 15% of questions that repeat exactly.

Evaluation confirms quality is unchanged, and estimated monthly cost falls by more than 60%. Buying Provisioned Throughput first would have locked in capacity for the inefficient prompts.

Check yourself

How is on-demand foundation model cost calculated?

Show answer

Input tokens × input price plus output tokens × output price; output tokens usually cost more.

Exam Tips

Remember for the exam

  • On-demand cost = input tokens x input price + output tokens x output price.
  • Output tokens usually cost more than input tokens.
  • Repeated prefixes: prompt caching; repeated questions: response cache.
  • Fewer, better chunks via reranking cut RAG input tokens.
  • Optimize usage before buying provisioned capacity.