Cost Engineering for Production AI: How We Reduced LLM Costs Without Making the Platform Less Intelligent
The architectural decisions that kept PHHM fast, scalable, and cost-efficient without sacrificing workflow quality. First of a two-part cost series: this article covers measurement; Part 2 covers optimization.
Focus
Cost • Measure
Read time
13 min
Series
PHHM Journal
Theme
Production AI
One of the first questions people ask about AI platforms is:
"How much does it cost?"
It's a reasonable question. It's also the wrong one. The better question is:
"Why does it cost that much?"
When we started building PHHM, cost felt like someone else's problem. The models worked. The workflows were reliable. Users were happy. Then we looked at production telemetry. One workflow consumed nearly four times as many tokens as another. Two seemingly identical requests had completely different execution costs. Retries quietly multiplied token usage.
Long conversation histories were being sent to every agent. Nothing was technically broken. The platform was simply doing more work than it needed to. That realization completely changed how we thought about AI engineering. Instead of asking:
"Which model is cheapest?"
We started asking:
"Which architectural decision is making this workflow expensive?"
That's the difference between optimizing prompts... ...and engineering production AI.
The Biggest Cost Isn't the Model
Most discussions about AI costs begin with model pricing. In production, we discovered something surprising. The model was rarely the biggest factor. Architecture was. Two workflows could use exactly the same model. One costs three times more. Why? Because one:
executed six agents instead of three
retried twice
included unnecessary conversation history
generated redundant summaries
repeated context across agents
The model didn't create the cost. The workflow did.
Cost Is the Sum of Many Small Decisions
No single architectural decision doubled our AI bill. Lots of tiny ones did. For example:
User Request
↓
Overseer
↓
Analyst
↓
Care
↓
Communications
↓
Validation
↓
Retry
↓
Response
Every step consumes:
tokens
latency
compute
API calls
Multiply that across thousands of workflows. Small inefficiencies become significant operational costs.
Part 1
Stop Thinking About Cost Per Request
Traditional APIs often measure: Cost per request. Multi-agent systems need something different. We measure:
Cost per workflow.
One request might execute:
two agents
six agents
multiple retries
fallback models
validation passes
Treating those requests equally hides where the money actually goes.
Every Workflow Has an Operational Cost
By the end of the project, every execution produced a cost profile. For example:
Workflow
Agents
Tokens
Estimated Cost
Welcome Journey
2
1,120
Low
Member Report
4
3,480
Medium
Care Plan
5
4,210
High
Newsletter
3
2,870
Medium
Now optimization becomes targeted. We're no longer guessing. We're measuring.
The Architecture We Wanted
Eventually every workflow answered three questions. Was it correct?
↓
Was it fast?
↓
Was it economical?
Production AI isn't only about quality. It's about sustainable quality.
The Cost Triangle
Every engineering decision balanced three competing goals.
Quality
▲
/ \
/ \
/ \
/ \
Speed ------- Cost
You can usually improve two. Improving all three requires architectural changes. That's exactly what this article explores.
The Principle That Changed Everything
Looking back, one sentence summarizes our entire cost strategy.
Don't optimize model prices. Optimize the amount of work your platform performs.
Everything else followed from that idea.
Measuring AI Costs: Stop Optimizing Requests, Start Optimizing Workflows
One of the biggest mistakes we made early was measuring AI costs the same way we measured traditional APIs. We looked at cost per request. That turned out to be almost meaningless. Two requests arriving at the same endpoint could have dramatically different execution paths. One might trigger two specialist agents. Another might invoke six agents, perform multiple validation steps, retry twice, and generate a long-form report.
Example
From the API's perspective, both were simply:
POST /workflow
From the platform's perspective, they were completely different workloads. That's why PHHM stopped measuring requests. We started measuring workflows.
Every Workflow Has Its Own Cost Profile
By the end of the project, every execution produced a detailed cost breakdown. Instead of seeing one total number, we could see where every token was spent.
Member Report Workflow
│
▼
Overseer ............ 320 tokens
Without this information, optimization becomes guesswork. With it, cost engineering becomes measurable.
Not Every Agent Costs the Same
Another assumption disappeared quickly. We expected every specialist to consume roughly the same resources. Production data showed otherwise.
Agent
Typical Token Usage
Relative Cost
Overseer
Very Low
Minimal
Welcome
Low
Low
Analyst
High
High
Care
Medium
Medium
Communications
Medium
Medium
Gospel
Variable
Depends on content length
The Analyst consistently consumed the most context because it processed the richest inputs. That made it the first target for optimization. Not because it was inefficient. Because improving the largest contributor produces the greatest return.
Context Is Usually the Biggest Expense
When people think about AI costs, they usually think about generated text. In reality, input context often dominates. Imagine this request.
Conversation History
↓
Workflow State
↓
Member Profile
↓
Prompt
↓
User Request
Every one of those sections consumes tokens before the model generates a single word. Large contexts quietly become expensive.
More Context Isn't Always Better
One misconception slowed us down early. We assumed giving agents more information would always improve quality. It didn't. Often, it simply increased cost. Specialist agents rarely need the complete workflow history. The Communications Agent doesn't require every analytical detail. The Welcome Agent doesn't need the entire care record. Instead of maximizing context...
We started minimizing it.
Context Should Be Purpose-Built
Every specialist receives only the information required for its task.
Workflow State
│
▼
Context Builder
│
├──────────────┐
▼ ▼
Analyst Communications Each agent receives a different context package. That reduces:
token usage
latency
cognitive load for the model
And, surprisingly, often improves output quality. Less irrelevant information means fewer distractions.
Shared Context Is Hidden Cost
One expensive pattern appears in many AI systems. The same information is sent repeatedly. For example:
Member Profile
↓
Analyst
↓
Member Profile
↓
Care
↓
Member Profile
↓
Communications
The platform keeps paying to transmit identical information. Whenever possible, PHHM summarizes or transforms context before passing it downstream. The downstream agent receives what it needs—not everything that came before.
Summaries Are Cheaper Than Histories
One optimization delivered immediate savings. Instead of forwarding an entire conversation history between agents, we forward structured summaries. For example:
Full Conversation
│
▼
Workflow Summary
│
▼
Next Agent
A concise, validated summary often costs a fraction of the original context while preserving the information that actually matters. The result is lower token usage without reducing workflow quality.
Cost Engineering Begins with Measurement
Looking back, our first instinct was to optimize prompts. That was premature. The real breakthrough came when we understood where the money was going. Once token usage became observable, optimization opportunities became obvious. The biggest savings didn't come from writing clever prompts. They came from removing unnecessary work.
The Bigger Lesson
One engineering principle emerged again and again.
You can't optimize costs you don't measure.
Token accounting isn't just billing information. It's architectural feedback. It tells you:
which workflows are expensive
which agents consume the most context
where retries multiply costs
which optimizations produce meaningful savings
Without those measurements, cost reduction becomes speculation. With them, it becomes engineering.
Architectural Cost Optimization: Doing Less Work Instead of Buying Cheaper Models
After measuring workflow costs, one pattern became impossible to ignore. The expensive workflows weren't expensive because they used better models. They were expensive because the platform performed unnecessary work. Extra agents executed. Context was repeated. Retries multiplied token usage. Identical requests were processed again. The platform wasn't paying for intelligence.
It was paying for redundancy. That realization completely changed our optimization strategy. Instead of asking:
"Which model should we downgrade?"
We started asking:
"Why is this workflow doing this work at all?"
The Cheapest AI Call Is the One You Never Make
One engineering principle quickly became our north star.
Every unnecessary model invocation is permanent technical debt.
A language model should only execute when it genuinely adds value. Everything else should be handled by software. For example: Don't ask an LLM:
if a required field exists
whether JSON is valid
whether a user is authenticated
whether a workflow exists
whether an email address is correctly formatted
Those are deterministic problems. Software solves them faster, cheaper, and more reliably. Reserve AI for reasoning. Not validation.
Part 2
Intelligent Model Routing
Not every task deserves your most capable model. One mistake we made early was treating every workflow equally.
Simple Welcome Message
↓
Largest Model
Technically correct. Economically inefficient. Eventually, routing became another orchestration responsibility.
Fast Model Advanced Model The orchestrator—not the user—decides which model is appropriate. That keeps quality high while reducing unnecessary cost.
Match Capability to Complexity
One useful framework emerged during development.
Task
Model Strategy
Classification
Lightweight model
Routing
Lightweight model
Summarization
Standard model
Complex analysis
Advanced model
Multi-step reasoning
Advanced model
Final formatting
Lightweight model
Notice the pattern. High-cost models are reserved for high-value reasoning. Everything else uses simpler alternatives where appropriate.
Parallel Execution Has a Cost
Earlier in the series we celebrated parallel execution because it reduced latency. There's another side to that decision. Concurrency also increases resource consumption. Imagine this workflow.
Overseer
│
├──────────────┬──────────────┐
▼ ▼ ▼
Analyst Care Communications Latency improves. But three model calls now happen simultaneously. Sometimes that's exactly what you want. Sometimes sequential execution is more economical. Choosing between them becomes an architectural trade-off.
Optimize for the Right Constraint
One lesson became increasingly important. Sometimes the goal is speed. Sometimes it's cost. Sometimes it's both. Those goals don't always align.
One logical operation became three AI calls. Three sets of tokens. Three opportunities to consume additional context. That's why reducing retries often produces larger savings than switching models.
Fix the Cause, Not the Bill
Whenever retries increased, we resisted the temptation to focus on cost. Instead, we investigated the underlying reason. Common causes included:
unclear prompts
oversized context
weak output contracts
insufficient validation feedback
poor routing decisions
Reducing retries naturally reduced spending. Cost optimization became a by-product of better engineering.
Cache What Doesn't Change
One of the simplest optimizations required almost no AI expertise. Stop recomputing identical work. For example:
Member Summary
↓
Cache
↓
Reuse
If a profile hasn't changed, regenerating the same summary adds cost without adding value. Caching works especially well for:
profile summaries
document analysis
workflow templates
reference material
static knowledge
The orchestrator checks whether existing results remain valid before invoking another model.
Avoid Cascading AI Calls
Another expensive pattern appeared during profiling. One agent generated information solely so another agent could summarize it.
Agent A
↓
Long Report
↓
Agent B
↓
Summary
↓
Agent C
The platform paid twice for essentially the same information. Instead, we redesigned several workflows so the first agent produced a structured summary directly. Less text. Fewer tokens. Simpler orchestration. Lower cost.
Cost Is a Workflow Metric
One mindset shift tied everything together. Instead of treating cost as an accounting problem, we treated it as another operational metric. Every workflow now answers four questions. Was it correct?
↓
Was it reliable?
↓
Was it fast?
↓
Was it economical?
A workflow that costs twice as much without improving outcomes isn't better. It's simply more expensive.
Once cost became visible, design discussions changed. Instead of asking:
"Can we build this?"
We asked:
How many model calls does this introduce?
Can this context be reduced?
Should this result be cached?
Is this retry avoidable?
Does this task require our most capable model?
Architecture reviews naturally included economics. That proved far more effective than trying to optimize costs after deployment.
The Bigger Lesson
Looking back, one principle guided almost every optimization we made.
Optimize the architecture before you optimize the model.
Changing providers might save a percentage. Removing unnecessary work often saves an order of magnitude more. That's the difference between tactical optimization and engineering design.
Cost Engineering Is a Design Discipline, Not a Finance Exercise
When people hear "cost optimization," they often imagine finance teams asking engineers to reduce cloud bills. That's not what happened in PHHM. The engineering team cared about cost because cost directly influenced architecture. Every unnecessary retry increased latency. Every oversized prompt increased token usage. Every redundant AI call consumed compute that could have been used elsewhere. Cost wasn't simply money leaving the business. It was evidence that the platform was performing unnecessary work.
Once we understood that, optimization became much easier. We stopped trying to make AI cheaper. We started making the platform more efficient.
Sustainable AI Requires Economic Feedback
One realization changed how we evaluated architectural decisions. Every new feature should answer one additional question.
"What is the operational cost of this capability?"
That doesn't mean rejecting expensive features. It means understanding their trade-offs before deploying them. For example:
Does this workflow require another specialist agent?
Can existing context be reused?
Should the result be cached?
Is a more capable model actually necessary?
Will this increase retries?
Does this improve user outcomes enough to justify the additional cost?
Cost became another engineering constraint. Just like latency. Just like reliability.
Every Architecture Decision Has an Economic Consequence
Looking back, nearly every architectural decision influenced operational cost.
Notice something important. The model appears surprisingly late. Most cost is determined long before the first token reaches an LLM. That's why architectural thinking matters so much.
Budgeting at the Workflow Level
Traditional budgeting often focuses on monthly infrastructure costs. Multi-agent platforms benefit from a different perspective. We started defining expected cost envelopes for each workflow. For example:
Workflow
Target Profile
Operational Goal
Welcome Journey
Low cost
Fast onboarding
Member Report
Moderate cost
High analytical quality
Care Plan
Higher cost
Prioritize recommendation quality
Newsletter
Moderate cost
Batch generation efficiently
Instead of asking whether the platform was expensive, we asked whether each workflow stayed within its intended design goals. That made cost discussions much more productive.
Cost Trends Matter More Than Daily Spend
One unusually expensive day rarely indicates a systemic problem. Gradual increases do. That's why we monitored trends instead of isolated numbers. Average Workflow Cost Week 1 1.00x
↓
Week 2 1.03x
↓
Week 3 1.11x
↓
Week 4 1.28x Nothing catastrophic happened. But the trend clearly suggested that something in the platform had changed. Trend analysis often revealed regressions long before monthly billing reports did.
Cost Dashboards Should Explain Spending
One lesson carried over directly from the observability article. Dashboards shouldn't just display numbers. They should answer questions. A useful cost dashboard helps engineers understand:
Which workflow is most expensive?
Which agent consumes the most tokens?
Which prompt version increased costs?
Which workflows retry most frequently?
Which model is responsible for the highest spend?
How has cost changed since the last deployment?
Those answers make optimization actionable.
Scaling Without Losing Control
As usage grows, small inefficiencies become significant. A workflow that wastes only a few hundred tokens doesn't seem important during development. Multiply that across thousands of daily executions and the impact becomes obvious. That's why cost engineering becomes more valuable over time. Good architectural decisions compound just as quickly as poor ones.
Cost Completes the Engineering Picture
Looking back across the PHHM series, another pattern became clear. Every workflow ultimately balances four competing goals.
Optimizing only one dimension rarely produces the best platform. Production engineering is the art of balancing all four.
The Architecture We Ended Up With
By the end of the project, cost engineering wasn't a separate activity. It was woven into the platform itself.
User Request
│
▼
Orchestration Layer
│
├──────────┼──────────┐
▼ ▼ ▼
Model Routing Context Builder Cache
│ │ │
└──────────┼──────────┘
▼
Specialized AI Agents
│
▼
Validation & Retry Management
│
▼
Cost Telemetry & Observability
│
▼
Final Response
Notice what's missing. There isn't a separate "cost optimization service." Cost awareness exists throughout the architecture. Every layer contributes.
The Five Principles of Cost Engineering
If I were designing another production AI platform tomorrow, these are the principles I'd adopt from the beginning.
1. Measure workflows—not requests
Users experience complete workflows. That's where costs should be measured.
2. Minimize unnecessary work
Reducing redundant context, retries, and repeated model calls usually produces greater savings than switching providers.
3. Match capability to complexity
Reserve your most capable models for problems that genuinely require advanced reasoning.
4. Treat token usage as engineering telemetry
Tokens reveal architectural inefficiencies, not just billing information. Use them to guide design decisions.
5. Optimize architecture before pricing
Changing providers might reduce costs. Reducing unnecessary computation changes the economics of the entire platform.
Final Thoughts
When I started building PHHM, I assumed cost optimization would mostly involve comparing model prices. Production taught me something very different. The largest savings rarely came from choosing a different model. They came from improving the architecture around the model. That meant:
reducing unnecessary context
avoiding redundant AI calls
minimizing retries
introducing intelligent routing
caching repeatable work
measuring workflow economics
making cost visible to engineers
None of those changes made the platform less intelligent. They simply removed work that never needed to happen. That's why I no longer think about AI costs as a billing problem. I think about them as architectural feedback. Every unexpected increase in cost is the platform telling us it's doing more work than necessary. Listening to that feedback made PHHM faster, simpler, and more sustainable. And that's the biggest lesson I'd carry into every future AI platform.
Key Takeaways
Example
If you're building production AI systems, I'd recommend adopting these practices from day one:
Measure cost per workflow rather than per API request.
Record token usage for every agent execution.
Give each specialist only the context it actually needs.
Route tasks to models based on complexity instead of using one model for everything.
Cache repeatable results whenever possible.
Investigate retries as engineering issues, not just cost issues.
Monitor cost trends alongside latency and reliability.
Include cost discussions in architecture reviews—not only finance meetings.
Treat token usage as operational telemetry.
Design platforms that perform less work rather than simply using cheaper models.