**Understanding AI Inference Costs: Integrating OpenCost with llm-d on Kubernetes**
As AI adoption accelerates, platform teams face mounting pressure to understand and control GPU-driven infrastructure costs. With models serving billions of tokens monthly, many organizations struggle with a critical blind spot: *what each token actually costs*.
—
### The Hidden Challenge of AI Costs
Platform teams today operate in an opaque financial environment. While infrastructure spend is visible and token throughput is trackable, the crucial link between these metrics remains missing. Without accurate per-model and per-token cost data derived from actual resource consumption, decision-making becomes speculative rather than data-driven.
This creates several pressing challenges:
– **Unclear ROI**: Executives ask difficult questions about AI return on investment that cannot be answered with concrete numbers
– **Budget mysteries**: Teams cannot identify which workloads are consuming disproportionate AI budgets
– **Guesswork economics**: Organizations cannot determine whether self-hosting models is more cost-effective than using SaaS APIs
**Key Distinction**: It’s important to remember that *cost ≠ price*. SaaS providers may price below cost to gain market share or well above cost for premium models. For self-hosted infrastructure, the cost is what you spend to operate it, while the SaaS price is simply what you pay.
—
### A New Approach: OpenCost + llm-d Integration
To address these challenges, the CNCF ecosystem is delivering a solution through the integration of **OpenCost** (a CNCF incubating project) with **llm-d** (a CNCF sandbox project for distributed LLM inference on Kubernetes).
This integration bridges the visibility gap by connecting infrastructure costs to the actual token streams flowing through vLLM, producing meaningful metrics for AI platform decisions.
> Note: Even vLLM users who don’t use llm-d can benefit, as the core metrics come from vLLM itself.
—
### GPUs: The Complex Cost Challenge
GPUs represent a unique cost management challenge compared to traditional CPU resources:
– They are significantly more expensive when misconfigured
– Idle GPUs with loaded models still incur substantial costs (VRAM occupancy)
– KV cache efficiency directly impacts processing costs
– Traditional Kubernetes resource allocation struggles with inference workloads
The integration addresses what OpenCost calls the “invisible GPU” problem—resources that appear allocated but aren’t producing value.
—
### Two Types of AI Costs Explained
The integration provides two fundamentally different cost metrics that answer distinct business questions:
#### 1. Allocation-Based Cost Per Model
This includes all costs attributed to running a model:
– GPU memory reserved for model weights
– Compute consumed during active inference
– Shared infrastructure components (gateway, KV cache storage)
**Answers**: “What is this model costing us to keep available?”
#### 2. Usage-Based Cost Per Model
This includes only costs during active inference:
– GPU and infrastructure consumption while processing
– Savings from KV cache optimizations
**Answers**: “What did this model’s actual computational work cost?”
**Utilization Insight**: The relationship between these metrics reveals GPU utilization efficiency:
“`
Utilization = usage-based cost per million tokens / allocation-based cost per million tokens
“`
For example, if usage-based costs are $1.00 per million tokens while allocation-based costs are $4.00, utilization is 25%.
—
### Build vs. Buy: The Critical Comparison
One common mistake is using usage-based costs alone to justify self-hosting over SaaS APIs. This creates misleading comparisons.
**Correct Approach**: Compare allocation-based costs (real costs) against API pricing:
“`
Self-hosted at 25% utilization:
Usage-based: $1.00/million tokens (misleading)
Allocation-based: $4.00/million tokens (real cost)
SaaS API: $2.00/million tokens
Conclusion: SaaS is cheaper at current utilization
Self-hosting becomes competitive above ~50% utilization
“`
This framework provides clear optimization targets—increasing utilization through smarter routing, model sharing, or traffic consolidation.
—
### What the Integration Actually Measures
The solution leverages existing metrics from llm-d deployments:
– Token throughput from vLLM
– GPU costs from OpenCost’s allocation engine
– Processing time metrics for input/output separation
**Key Metrics Published**:
| Metric | Purpose |
|——–|———|
| `llm_total_hourly_cost` | Hourly cost per model |
| `llm_cost_per_million_tokens` | Blended cost per million tokens (input/output separated) |
All metrics include labels for model name, version, namespace, cost basis (usage vs. allocation), and workload type.
—
### Complete Cost Picture: Beyond the GPU
A running model requires accounting for supporting infrastructure:
– **Inference Scheduler (EPP)**: CPU gateway routing component
– **llm-d gateway proxy**: Setup and maintenance costs
– **KV cache storage**: Can reach 18TB in tiered-cache deployments
– **Workload Variant Autoscaler**: Cluster-wide component distributing costs via OpenCost’s SharedLabels
The SharedLabels approach keeps systems decoupled—components are labeled at deployment, and OpenCost handles attribution without understanding internal architecture.
—
### Reading the Cost Matrix: What Different Scenarios Indicate
| Allocation Cost | Usage Cost | Diagnosis & Action |
|—————–|————|——————-|
| High | Low | Costly availability, efficient inference. Focus on utilization |
| High | High | Expensive overall. Re-evaluate model choice |
| Low | Low | Well-sized deployment |
| Low | High | Cheap hosting but inefficient inference. Check model size and hardware |
—
### Practical Applications
– **Finance Teams**: Generate chargeback reports by namespace and team
– **FinOps Teams**: Identify underutilized models and quantify right-sizing savings
– **Platform Teams**: Enable smart routers to factor per-token cost into routing decisions alongside latency and throughput
—
### Current Status and Future Work
**Available Now**: OpenCost 1.121.0+ with proof-of-concept validated on clusters with 109 GPUs and 30 AI models.
**Ongoing Development**:
– Measuring wasted GPU capacity
– Improving idle-GPU detection for LLM patterns
– OpenCost UI integration
– Workload and tenant metric capture
– Deployment guides and optimization frameworks
Both projects are open source and actively seeking contributions.
—
## FAQ
**Q: What problem does this integration solve?**
A: It connects infrastructure costs to AI token throughput, providing per-model and per-token cost visibility that was previously unavailable.
**Q: Can I use this without llm-d?**
A: Yes—vLLM users can still benefit from the core cost metrics derived from token throughput and GPU consumption.
**Q: How is utilization calculated?**
A: Utilization = usage-based cost per million tokens ÷ allocation-based cost per million tokens. This reveals how efficiently GPUs are being used.
**Q: What costs are included in allocation-based pricing?**
A: GPU memory for model weights, active compute, gateway infrastructure, KV cache storage, and shared platform components.
**Q: What costs are included in usage-based pricing?**
A: Only active inference costs—compute consumed during token processing, with KV cache efficiency factored in.
**Q: How does this help with build-vs-buy decisions?**
A: By comparing allocation-based costs (real hosting costs) against SaaS API pricing, organizations can make informed decisions about self-hosting versus cloud APIs.
—
## Conclusion
The integration of OpenCost with llm-d represents a significant advancement in AI infrastructure cost management. By providing granular, per-model and per-token cost visibility, platform teams can move from guessing to data-driven decision-making.
The solution addresses the unique economics of AI workloads—particularly GPU utilization, KV cache efficiency, and the distinction between allocation-based versus usage-based costs. With metrics already available in OpenCost 1.121.0, organizations can now accurately measure, analyze, and optimize their AI infrastructure spending.
As both projects continue evolving toward production readiness, this integration lays the foundation for smarter AI cost management across the Kubernetes ecosystem. The open source nature of both projects encourages community collaboration to further refine these critical cost visibility tools.


