Legacy GPT-4 at $30/M output tokens vs Claude Haiku 4.5 at $5/M output — and $1/M in versus $30/M in — is a 6-30x swing on the exact same request. The architecture decisions you make in week 1 lock in 10x of your bill. Here's how to design AI products for the bill — model routing, prompt caching, batch APIs, and the math that decides which GPU to rent.
Learning Objectives
After this lesson, you will be able to:
Compare GPU options (A100, H100, L4, T4) and pick the right hardware for training versus serving
Design a routing system that sends easy questions to cheap models and hard questions to expensive ones
Apply token-saving strategies that cut LLM API costs by 40-70% without making the output worse
This lesson might save you (or your company) more money than any other topic in this track. Cost surprises kill more AI startups than bad models. The good news: most cost problems are solvable once you know the patterns.
Prices are approximate as of early 2026 and vary by cloud provider and region.
Key insight: H100 is ~3x faster than A100 for training, but only ~1.5-2x more expensive. For large training runs, H100 is almost always more cost-effective despite the higher hourly rate because you need fewer hours.
Prices are approximate as of early 2026 and vary by cloud provider and region.
The L4 sweet spot: For many inference workloads, NVIDIA L4 offers the best cost-performance ratio. It has enough VRAM for quantized 7B-13B models and costs 75% less per hour than A100. Four L4s can serve the same throughput as one A100 for many model sizes, at half the cost.
What Do You Think?
You need to serve a Llama 70B model. An A100-80GB costs $2/hr and an L4-24GB costs $0.60/hr. The 70B model in INT4 needs ~37GB. Which is more cost-effective?
This is a trick question -- two L4s only have 48 GB total, and tensor parallelism overhead means you likely need the A100. But the real answer is D: cost-effectiveness depends on throughput. If the A100 serves 30 requests/second and two L4s serve 15 req/s, the per-request cost is identical. You need to benchmark your specific model and traffic pattern.
Building a cost-efficient AI system is not about being cheap -- it is about being systematic. Here is the step-by-step process for designing an architecture that balances performance and cost:
Start with your traffic projections. How many requests per day? What is the peak-to-average ratio? A chatbot serving 10K requests/day has fundamentally different economics than one serving 1M. Volume determines whether API providers or self-hosting is more economical.
Price out the API option. At 50K requests/day with 2,000 input tokens and 500 output tokens each, GPT-4-turbo costs ~$30K/month. GPT-5 mid-tier costs ~$7-8K/month. Claude Haiku 4.5 / GPT-5-mini costs ~$1-3K/month. Model choice is the single biggest cost lever.
Price out the self-hosting option. Two A100-80GB GPUs at $2/hr each cost $2,880/month fixed. Add engineering time for setup, monitoring, and maintenance. Self-hosting has a high fixed cost but near-zero marginal cost per request.
The break-even point is where API costs equal self-hosted costs. Below this volume, APIs win (simpler, no ops burden). Above it, self-hosting wins (lower marginal cost). For most teams, the break-even is around $15-20K/month in API spend, factoring in engineering time.
#Token Optimization: Spending Less on Every Request
For LLM API users (OpenAI, Anthropic, Google), tokens are the primary cost driver:
You are a helpful customer service agent for Acme Corp. You were founded
in 1985 and are known for your excellent products and customer service.
When responding to customers, always be polite, professional, and helpful.
Make sure to address their concern directly and provide actionable steps.
If you don't know the answer, say so honestly rather than making
something up. Always end with asking if there's anything else you can help with.
Customer: What is your return policy?
Token count: ~100 input tokens for system prompt
After optimization
[Acme Corp CS agent. Be concise, helpful, honest. If unsure, say so.]
Customer: What is your return policy?
Token count: ~20 input tokens for system prompt (80% reduction)
Impact at scale: 100K requests/day x 80 tokens saved x $0.01/1K tokens = $80/day = $2,400/month saved from one prompt optimization.
If confidence is low or output quality is poor (detected by a cheap quality check), escalate to the large model
Only 20-30% of queries typically need escalation
Cost analysis: If 70% of queries are resolved by the small model at $0.001 each and 30% escalate to the large model at $0.05 each, the blended cost is $0.0157/request vs. $0.05/request for all-large-model. That is a 68% savings.
The 2024-2026 production pattern is to put every model call through an LLM gateway — a proxy that handles routing, caching, retries, fallback, observability, and budget enforcement in one place. Without it, cost controls scatter across application code; with it, you have a single chokepoint to enforce policy.
Gateway
Open source?
Strongest feature
Notes
LiteLLM
Yes
Unified OpenAI-compatible API across 100+ providers
The de-facto standard for self-hosted gateways; built-in budgets and routing rules.
Portkey
Hybrid
Smart routing, fallback chains, prompt versioning
Strong fallback graphs (try GPT-5, on fail try Claude Sonnet 5, on fail try DeepSeek-V3.1).
Helicone
Yes
Drop-in OpenAI proxy with cost analytics
Minimal code change; pairs well with Langfuse for tracing.
Cloudflare AI Gateway
Managed
Edge caching + rate limiting + observability
Lowest latency overhead; pay only for traffic.
What you should enforce at the gateway:
Per-customer / per-feature budgets — hard cutoff plus soft alerts at 80%.
Prefix caching — hash system prompts and reuse server-side KV; many gateways ship this.
Semantic cache — embed and match the user message; serve cached completions for high-similarity hits.
Fallback chains — primary fails or rate-limits, secondary handles, tertiary handles, and graceful degradation if all fail.
Provider rotation — when a provider has elevated p99, shift weight automatically.
Audit logging — every prompt, completion, model, latency, token count, and cost tagged by user/feature.
What Do You Think?
Your team is deciding whether to call OpenAI directly from each microservice or to route everything through a self-hosted LiteLLM gateway. Annual LLM spend is projected at $1.2M. What is the single strongest argument for the gateway?
#FinOps Math: Per-Million-Tokens, GPU Hours, and Spot Economics
Pricing models for AI workloads are a mess of dimensions. Work them out in the same units before deciding.
GPU selection depends on workload type. H100s for large-scale training, A100s for medium training and inference, L4/T4 for cost-effective inference; matching hardware to workload avoids 2-5x overspending
Multi-model routing cuts costs dramatically. Route simple queries to cheap small models and hard queries to expensive large models; 70-80% of queries are often simple enough for the small model
Token optimization reduces LLM API costs by 40-70%. Prompt compression, caching frequent responses, batching requests, and truncating unnecessary context all reduce token consumption without degrading quality
Cost must be a first-class architectural concern. Designing for cost-efficiency from the start (choosing the right model size, implementing caching, using spot instances) is far easier than optimizing after launch
With cost architecture mastered, you can build AI products that are both powerful and economically sustainable. Next up: Security & Compliance -- protecting your AI systems from attacks and meeting regulatory requirements.
Select your architecture based on the analysis. Options include: all-API (simple, scales automatically), all-self-hosted (cheapest at scale), or hybrid (self-host a small model for easy queries, API for hard ones). Multi-model routing is almost always the right answer at scale.
Track cost per request, cost per user, and cost per feature daily. Alert on anomalies (prompt drift making prompts longer, traffic spikes, retry storms). Review cost metrics weekly in sprint reviews. The best cost architecture evolves continuously as traffic patterns and model pricing change.