The race to integrate AI capabilities into products has shifted from mere experimentation to rigorous financial scrutiny. As of 2026, the question isn't just can we build it, but at what sustainable cost? For many, the answer lies in understanding the granular economics of AI inference, specifically the cost per million tokens – the fundamental unit of consumption for large language models (LLMs) and other generative AI.
TL;DR: Calculating cost per million tokens is essential for accurate AI budgeting and optimization. It enables direct comparison between hosted APIs and self-hosting, highlighting the impact of utilization, model choice, and infrastructure decisions. Strategic optimization through batching, caching, and model quantization can dramatically reduce this unit cost, making AI features economically viable at scale.
Key takeaways
- Cost per million tokens is the most reliable metric for comparing AI inference expenses.
- Utilization is king: Low GPU utilization can make self-hosting prohibitively expensive.
- Hosted APIs vs. Self-Hosting: The break-even point depends heavily on your anticipated request volume and engineering overhead.
- Optimization is not optional: Batching, caching, and model selection offer significant leverage over raw hardware costs.
- Don't forget hidden costs: Egress, storage, observability, and operational burden add up quickly.
Why Cost Per Million Tokens Matters in 2026
In 2026, AI is no longer a novelty; it's a core component of many applications. From customer service chatbots to sophisticated content generation platforms, the underlying infrastructure processes millions, if not billions, of tokens daily. Without a clear understanding of your AI inference cost per token, budgeting becomes guesswork, and scaling becomes a financial gamble.
This metric allows you to normalize expenses across different models, providers, and deployment strategies. A smaller, cheaper model might have a higher cost per million tokens if it requires more processing time or less efficient hardware. Conversely, a powerful, expensive model might be more cost-effective if it can handle complex tasks with fewer tokens or greater throughput.
The CFO's Perspective: Predictability and ROI
As engineers, we often focus on performance and reliability. However, when presenting an AI infrastructure budget, the CFO's primary concern is predictability and return on investment. The 'cost per million tokens' provides a tangible, measurable unit that translates directly to business value. If an AI feature generates X revenue per month and consumes Y tokens, you can quickly assess its profitability. This level of granular cost analysis is crucial for securing funding and justifying ongoing investment in AI initiatives.
Hosted APIs vs. Self-Hosting: The Break-Even Arithmetic
The fundamental decision for many teams is whether to leverage hosted LLM APIs (like those from major providers) or to self-host open-weight models on dedicated or rented GPU infrastructure. This choice hinges entirely on your expected usage patterns and the associated total cost of ownership (TCO).
Hosted APIs offer convenience, instant scalability, and zero operational overhead. You pay per token, per request, or sometimes per second of compute. Self-hosting, however, can offer significantly lower unit costs at high utilization, greater control over data privacy, and the flexibility to fine-tune models. The challenge is reaching that high utilization.
Illustrative Cost Example: Hosted vs. Self-Hosted Inference
Let's model a hypothetical AI feature that processes customer queries, averaging 1,000 requests per minute during peak hours, 24/7. Each request involves 100 input tokens and generates 200 output tokens. This means 300 tokens per request.
- Assumptions:
- Request Volume: 1,000 requests/minute = 60,000 requests/hour = 1,440,000 requests/day.
- Tokens per Request: 300 tokens (100 input + 200 output).
- Total Daily Tokens: 1,440,000 requests * 300 tokens/request = 432,000,000 tokens/day (0.432 billion).
- Monthly Tokens: 0.432 billion * 30 days = 12.96 billion tokens/month.
- Illustrative Hosted API Rate: $0.50 per million tokens (input + output combined). (Note: Actual rates vary wildly by model and provider, verify current pricing.)
- Illustrative Self-Hosting GPU Rental: One NVIDIA H100 GPU at $3.00/hour. (Note: H100 rental costs fluctuate significantly; this is an illustrative figure for calculation.)
- Self-Hosting Model: A 70B parameter open-weight model requiring one H100 GPU for inference at ~200 tokens/second throughput.
- Self-Hosting Operational Overhead: 20% of hardware cost (for DevOps, monitoring, scaling).
Scenario 1: Hosted API Costs
Monthly tokens: 12.96 billion tokens.
Cost per million tokens: $0.50.
Total Monthly Hosted API Cost: (12.96 billion / 1,000,000) * $0.50 = 12,960 * $0.50 = $6,480.00
Scenario 2: Self-Hosting Costs
One H100 GPU provides ~200 tokens/second. To handle 1,000 requests/minute * 300 tokens/request = 300,000 tokens/minute = 5,000 tokens/second. This requires 5,000 / 200 = 25 H100 GPUs.
GPU Rental Cost: 25 GPUs * $3.00/hour * 24 hours/day * 30 days/month = 25 * $3.00 * 720 = $54,000/month.
Operational Overhead: 20% of $54,000 = $10,800/month.
Total Monthly Self-Hosting Cost: $54,000 + $10,800 = $64,800.00
In this specific, high-volume scenario, the hosted API is significantly cheaper. Why? Because our assumed self-hosting throughput per H100 is low relative to the aggregate demand, forcing us to scale up GPUs. This highlights that raw GPU cost is only part of the equation; efficient utilization is paramount.
When NOT to use this approach: While calculating cost per million tokens is powerful for predictable, high-volume inference, it's less relevant for infrequent, highly variable, or extremely low-volume AI tasks where the fixed cost of infrastructure (even if shared) would dominate. For early-stage prototyping or experimental features with unknown usage, starting with hosted APIs is often more practical, even if the theoretical unit cost is higher.
Optimizing AI Unit Economics: Beyond Raw Hardware
Our experience shows that hardware alone rarely dictates the final AI infrastructure TCO. Intelligent software optimizations can dramatically shift the unit economics. We've seen projects where careful tuning reduced inference costs by 5x-10x without changing the underlying GPU. Stripe's engineering blog, for instance, details how they optimized LLM inference for scale, showcasing the impact of software-level decisions.
Batching and Caching
Batching combines multiple individual requests into a single, larger inference request to the GPU. GPUs are highly parallel processors, performing much more efficiently when processing a large batch of data simultaneously rather than many small individual requests. In a recent client engagement, we optimized a real-time analytics pipeline by implementing dynamic batching at the API gateway, pushing request latency from ~500ms to ~150ms for individual users while reducing GPU idle time by nearly 40%. The `vLLM` library, for example, excels at continuous batching, which can significantly boost throughput.
Caching stores the results of common or recent prompts. If a user asks a question that has been asked before, or if a specific prompt prefix is frequently used, serving the response from a cache bypasses the LLM inference entirely, reducing both latency and cost. Our team measured a 30% cache hit rate on a production rollout of an internal knowledge base AI, directly translating to a 30% reduction in token consumption for that feature.
Model Choice and Quantization
Not every task requires the largest, most advanced LLM. Often, a smaller, fine-tuned model can achieve comparable accuracy for specific use cases at a fraction of the cost. For example, a 7B parameter model might be perfectly adequate for text classification, whereas a 70B model would be overkill. Quantization further reduces a model's memory footprint and computational requirements by representing weights with fewer bits (e.g., 8-bit or 4-bit integers instead of 16-bit floats), significantly improving throughput on the same hardware. OpenAI's research often highlights the ongoing efforts in model efficiency and smaller, more specialized models.
Comparing AI Infrastructure Options for Cost Efficiency
Deciding on the right AI infrastructure involves weighing upfront costs, operational burden, flexibility, and scalability. Here's a comparison of common options:
| Option | Main Cost Driver | Breaks Even When | Best For |
|---|---|---|---|
| Hosted LLM APIs | Per-token usage, API calls | Low-to-moderate, unpredictable usage | Rapid prototyping, variable workloads, minimal ops burden, immediate scale. |
| Cloud GPU Rental (On-Demand) | Hourly GPU time, egress, storage | Moderate, bursty usage with high peak-to-average ratio | Development, testing, short-term projects, variable compute needs. |
| Cloud GPU Rental (Reserved Instances) | Fixed commitment fee + usage | High, predictable base usage over 1-3 years | Established AI features, cost optimization for stable workloads, reduced GPU rental cost. |
| Specialized AI Clouds (Neoclouds) | Per-GPU hour, sometimes lower than hyperscalers | Moderate-to-high usage, specific GPU needs | Cost-sensitive projects needing specific hardware, less vendor lock-in, flexible commitment. |
| On-Premise (Self-Hosting) | Hardware CAPEX, power, cooling, ops headcount | Very high, consistent, long-term usage; strict data sovereignty | Extreme scale, maximum control, sensitive data, long-term TCO benefits at peak utilization. |
Do the math yourself
To calculate your own effective cost per million tokens, you need to aggregate all relevant costs over a period and divide by the total tokens processed in that same period. This applies whether you're using a hosted API or self-hosting.
Formula for Cost Per Million Tokens (CPMT):
CPMT = (Total Cost for Period / Total Tokens Processed for Period) * 1,000,000
Example (Self-Hosting):
- Total Cost for Period: Sum of GPU rental, power, cooling, storage, egress, network, and operational headcount costs.
- Total Tokens Processed for Period: Sum of all input and output tokens generated by your LLMs.
Consider the `nvidia-smi` command for monitoring GPU utilization and `Prometheus` for capturing metrics like token counts. You'll want to instrument your application to log token usage per request, allowing you to accurately measure the denominator in your CPMT calculation. For instance, in a Python application using `LangChain` with `OpenAI` models, you might wrap your LLM calls to log `completion_tokens` and `prompt_tokens` from the response metadata. RFC 9110 (HTTP Semantics) provides a good framework for understanding how to structure API responses for consistent data reporting.
Forgotten Line Items: The Hidden Costs of AI Infrastructure
When budgeting for AI, many teams overlook crucial expenses that accumulate quickly, especially with self-hosting or heavy cloud usage. These can significantly inflate your actual AI infrastructure budget:
- Data Egress: Moving data out of a cloud provider is often significantly more expensive than moving it in. If your AI feature frequently sends large responses to external services or users, egress costs can become a major component of your bill.
- Storage: Storing model weights, training data, and vector database embeddings can incur substantial costs, especially for large models or extensive knowledge bases.
- Vector Databases: Managed vector database services (e.g., Pinecone, Weaviate, Milvus) have their own pricing models, often based on vector dimensions, storage, and query volume. If self-hosting, you bear the operational burden of managing Postgres with pgvector or a dedicated vector store.
- Observability & Monitoring: Tools for logging, tracing, and monitoring your AI inference endpoints (e.g., Datadog, Grafana, OpenTelemetry) add costs, but are non-negotiable for production reliability.
- Human Capital: The engineering time spent on MLOps, infrastructure management, model serving, and optimization is a significant cost. This is often the highest forgotten line item in TCO calculations for self-hosting.
FAQ
How do I estimate tokens per request accurately?
Estimate tokens by running sample inputs through a tokenizer for your chosen model. Most LLM providers offer tokenizer APIs or libraries. For instance, OpenAI's `tiktoken` library can give precise token counts for various models, allowing you to simulate typical request payloads.
What is the typical cost per million tokens for major LLMs?
Typical costs vary widely, from sub-$0.10 to several dollars per million tokens, depending on the model size, provider, and whether you're using input or output tokens. Output tokens are often more expensive. Always check the latest pricing directly from the model provider's documentation.
Does GPU choice impact cost per million tokens?
Absolutely. A more powerful GPU (like an H100) might have a higher hourly rental cost but can process significantly more tokens per second, potentially leading to a lower effective cost per million tokens if you can achieve high utilization. Conversely, underutilized powerful GPUs are wasteful.
How does fine-tuning affect inference costs?
Fine-tuning can reduce inference costs by allowing a smaller, more specialized model to perform a task that would otherwise require a larger, more expensive general-purpose model. While fine-tuning has upfront training costs, it can lead to substantial savings in long-term inference expenses.
Is reserved GPU capacity always cheaper?
Reserved GPU capacity (e.g., AWS Reserved Instances, Google Cloud Committed Use Discounts) can be significantly cheaper than on-demand, often by 30-70%, but only if your usage is consistently high enough to fully utilize the reserved capacity. Unused reserved capacity is wasted money, making it a risk for unpredictable workloads.
Want your AI bill modelled before you build? Talk to Krapton
Navigating the complex landscape of AI infrastructure costs requires deep technical expertise and a strategic financial perspective. Our engineers specialize in dissecting AI project requirements, modeling token economics, and designing cost-optimized solutions for web, mobile, and SaaS applications. Whether you're considering cloud GPU pricing models or the total cost of ownership for self-hosting, we can help you make informed decisions and budget with confidence. Book a free consultation with Krapton today to optimize your AI infrastructure budget.
Krapton Engineering
Krapton Engineering brings over a decade of hands-on experience building and scaling complex web and mobile applications, SaaS products, and AI integrations for startups and enterprises worldwide. Our team deeply understands the nuances of AI infrastructure, from optimizing LLM inference costs to architecting high-performance GPU deployments.



