Managing the Cost of Generative AI Solutions
This lesson explains the cost drivers of a Foundry solution, which grow with tokens, capacity reservations and supporting services, and the design choices and governance that control them.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the billed components of a Foundry solution.
- Apply design levers that reduce cost, such as smaller models and shorter prompts.
- Describe governance controls such as budgets, tags and an AI gateway.
What is billed
The cost of a Foundry solution comes mostly from model usage, but supporting services add a significant share. Standard deployments are billed per token, with separate prices for input tokens, cached input tokens and output tokens. Token prices differ by model, output tokens usually cost several times more than input tokens, and reasoning models bill their internal reasoning tokens as output even though the user never sees them. A long answer from a reasoning model can therefore cost far more than its visible length suggests. Provisioned deployments are billed per PTU per hour, or at a discount through a reservation, whether or not they are used. Batch tokens are billed at a discount.
Beyond the models, Foundry Tools are billed per transaction, per page or per hour of audio, so reprocessing the same documents doubles their cost. Azure AI Search is billed by tier and by the number of replicas and partitions, with additional charges for the semantic ranker and for the tokens that agentic retrieval uses to plan queries. Some agent tools carry their own charges, such as web grounding per call and code interpreter per session, and media generation is billed per image or per second of video. The following table lists these components with the main lever for each.
| Component | Billing unit | Main lever |
|---|---|---|
| Standard model deployments | Input, cached input and output tokens | Model size, prompt length, output length |
| Provisioned deployments | PTUs per hour or reservation | Right-size PTUs; reserve for steady use |
| Batch deployments | Discounted tokens | Move offline work to batch |
| Foundry Tools | Transactions, pages, audio hours | Use only where needed; avoid reprocessing |
| Azure AI Search | Tier, replicas, partitions, semantic ranker, agentic retrieval tokens | Right-size; reduce fan-out |
| Agent tools | Per call (for example web grounding), code interpreter sessions | Limit unnecessary tool calls |
| Media generation | Per image (by quality and size) or per second of video | Lower quality for drafts |
What costs money
Design levers
The biggest savings come from design. Use the smallest model that meets the quality bar, and route only complex requests to larger models. Shorten prompts by retrieving fewer, better chunks and trimming conversation history. Put stable content, such as long instructions, at the start of the prompt so that prompt caching can bill repeated prefixes at the cached input rate. Bound output length, move offline work to batch, cache answers to frequent questions, and avoid reflection loops where evaluation shows that they do not improve results.
Prompt caching explains why prompt structure affects cost. When a request begins with the same sequence of tokens as a recent request, and that shared prefix is long enough (at least 1,024 tokens for Azure OpenAI models), the service reuses the earlier computation and bills the matching tokens at the lower cached input rate. The cache matches from the first token onward, so a timestamp or user name placed at the top of the system prompt changes the prefix on every request and prevents any cache hit. Placing fixed instructions, tool definitions and examples first, and variable content such as retrieved chunks and the user's question last, maximizes the cached portion.
Agent and RAG designs multiply these effects. Retrieving ten chunks of 500 tokens adds 5,000 input tokens to every request; if evaluation shows that the best five chunks give the same groundedness, halving retrieval halves that cost. Each extra agent step, such as a planning call or a self-check, adds a full model call, so steps are kept only where evaluation shows they improve the result enough to justify their cost.
Governance
Azure Cost Management budgets and alerts warn when spending approaches limits, and tags on resources attribute cost to teams and environments. An AI gateway in Azure API Management can enforce token limits per consumer with the token limit policy and emit token metrics per application, so that each team's usage is visible and capped. Usage reports from Application Insights traces show which features and prompts consume the most tokens.
Foundry also offers cost controls (preview) on its Cost page. The following screenshot shows a cost control being created for a Foundry resource: a monthly budget in US dollars or tokens, shared or set per agent, with threshold actions that either send an alert through Azure Event Grid or block new eligible requests when the budget is reached.

Keep cost under control
Reducing cost without lowering quality
A support assistant sends a 6,000-token system prompt and the full 40-turn conversation history with every request to a large model. Most questions are simple. Monthly cost is three times the budget.
Three changes address this: keep the long system prompt unchanged at the start of every request so that prompt caching applies; summarize older turns instead of sending the full history; and route simple questions to a smaller model with a classifier or model router, escalating only complex ones. Each change should be validated with the evaluation dataset to confirm that quality is unchanged.
Where should long, static instructions go in a prompt to lower cost?
Show answer
At the start, so repeated requests share the same prefix and benefit from prompt caching.
Exam Tips
Remember for the exam
- Output tokens usually cost more than input tokens; bound output length.
- Keep long static instructions at the start of prompts to benefit from prompt caching.
- Per-team token caps and metrics: API Management AI gateway policies.