Lesson 1 of 2 AI Workload Cost Optimization

AI Cost Fundamentals

AI workloads introduce new pricing units and grow quickly. This lesson explains how generative AI services and self-hosted models are priced, what drives their cost, and how to measure AI cost against the value it delivers.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish managed model services from self-hosted models.
  • Explain input, output and cached token pricing.
  • Compare on-demand, provisioned throughput and batch inference.
  • Identify the cost components of an AI application.
  • Calculate cost per conversation or per task.

Two ways to consume AI

Organizations use AI in two main ways. They call managed model services, such as Amazon Bedrock, Azure OpenAI in Microsoft Foundry or Vertex AI on Google Cloud, or model providers' own APIs, and pay per use. Or they self-host models on GPU or accelerator instances, in their own clusters or managed machine learning platforms, and pay for the infrastructure. Training and fine-tuning models also consume large amounts of accelerator time. Each approach has a different cost structure and different optimization levers.

Token pricing

Generative AI services usually charge per token, a unit of text roughly equal to a few characters or part of a word. The following terms describe the main token categories.

Input tokens
Tokens sent to the model: the user's request, instructions, conversation history and any retrieved documents.
Output tokens
Tokens generated by the model. They are usually priced several times higher than input tokens.
Cached input tokens
Repeated input, such as a long system prompt, that the service can cache and charge at a reduced rate.

Prices differ greatly between models: larger, more capable models can cost many times more per token than smaller ones. Cost per request therefore depends on the model, the length of the prompt and context, and the length of the answer.

The following diagram builds the cost of an interaction from token prices.

How model charges build up for a multi-call interaction. Each call is charged for input tokens at the input price and output tokens at the higher output price; an interaction makes several calls, and the monthly cost multiplies by volume. When a long context is resent on every call, input is often the larger share.
Output tokens usually cost several times as much as input tokens.
Fill in the value

Cost per conversation

Exam skills 7.4.3

Calculate token costs for an AI assistant.

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

Throughput and batch options

Managed services offer several ways to buy capacity. On-demand pricing charges per token with no commitment. Provisioned throughput reserves model capacity at a fixed hourly or monthly price, which gives predictable performance and can be cheaper at high, steady volume but is wasted when idle. Batch inference processes requests asynchronously at a discount, often around half the on-demand price, for work that does not need an immediate answer. Some services also offer priority or flexible tiers that trade price for latency.

Sort into groups

On-demand, provisioned or batch?

Exam skills 7.4.3

Choose how to buy AI inference for each workload.

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

Self-hosted and training costs

Self-hosted inference and training are priced by accelerator hours: GPU instances and other accelerators are among the most expensive resources in the cloud. Their cost is driven by how many accelerators run, for how long and how busy they are. An inference endpoint left running overnight with no traffic, or a notebook with a GPU left on over a weekend, charges full price for no work. Capacity can also be scarce, which pushes teams to reserve capacity they may not fully use.

Other AI cost components

An AI application involves more than the model. The following list describes other common costs.

  • Retrieval: vector databases or search services that store and query embeddings for retrieval-augmented generation (RAG).
  • Embeddings: tokens processed to create embeddings for documents and queries.
  • Agents and tools: multi-step agents that call models several times per task, multiplying token use.
  • Guardrails and evaluation: safety filters and evaluation runs, which consume additional model calls.
  • Data storage and transfer for training data, model artifacts and logs.

Measuring AI cost against value

AI spend can grow rapidly as adoption spreads, so total cost alone says little. Unit economics for AI measures cost per unit of value, such as cost per conversation, per document processed, per support ticket resolved or per successful agent task. Comparing that unit cost with the value of the outcome, for example the cost of a human handling the same ticket, shows whether the AI feature is worth its cost and whether optimization is improving it.

Worked example

Cost per conversation

A support assistant averages 6 model calls per conversation, each with 3,000 input tokens and 400 output tokens. The model costs USD 3 per million input tokens and USD 15 per million output tokens. What does a conversation cost in model charges?

Per call: 3,000 x 3 / 1,000,000 = USD 0.009 for input and 400 x 15 / 1,000,000 = USD 0.006 for output, USD 0.015 in total. Per conversation: 6 x 0.015 = USD 0.09. At 500,000 conversations a month, that is USD 45,000. Note that input is 60% of the cost because the long context is resent on every call, which makes prompt caching and shorter context promising levers.

Worked example

Provisioned or on-demand?

A team's model usage is steady at about USD 30,000 a month on demand. Provisioned throughput that covers its peak would cost USD 26,000 a month. Usage drops to near zero at night. Should it switch?

The saving is about USD 4,000 a month only if provisioned capacity is sized correctly and usage stays at the current level. Because usage is near zero at night, much of the provisioned capacity would sit idle, and if usage falls, the fixed cost remains. The team should compare at expected future volume, consider whether part of its work can move to batch inference, and choose provisioned throughput only if the saving survives realistic scenarios or if it needs the guaranteed performance.

Check yourself

Why can a long system prompt make input tokens the largest part of an assistant's cost?

Show answer

The prompt is resent with every call, so its tokens are charged many times per conversation even though output tokens are more expensive per token.

Exam Tips

Remember for the exam

  • Managed AI services charge per token; output tokens usually cost more than input tokens.
  • Provisioned throughput is fixed cost; batch inference is discounted for work that can wait.
  • Self-hosted AI and training are priced by accelerator hours; idle GPUs are costly waste.
  • Measure AI cost per unit of value, such as cost per conversation or per task.