Cost Analysis
Cost Analysis provides deep visibility into your AI spending across providers, models, flows, and time periods.
Dashboard Overview
The Cost Analysis dashboard shows:
┌────────────────────────────────────────────────────────────────────┐│ COST OVERVIEW Last 30 Days ▼ │├────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────┐ ┌─────────────────────────┐ ││ │ TOTAL SPEND │ │ TOTAL REQUESTS │ ││ │ $2,450 │ │ 156,234 │ ││ │ ▲ 12% from last month │ │ ▲ 8% from last month │ ││ └─────────────────────────┘ └─────────────────────────┘ ││ ││ ┌─────────────────────────┐ ┌─────────────────────────┐ ││ │ AVG COST/REQUEST │ │ TOP OPTIMIZATION │ ││ │ $0.0157 │ │ Switch classifier │ ││ │ ▼ 3% from last month │ │ Save $340/mo │ ││ └─────────────────────────┘ └─────────────────────────┘ ││ │└────────────────────────────────────────────────────────────────────┘Cost Breakdown Views
By Provider
┌────────────────────────────────────────┐│ COST BY PROVIDER │├────────────────────────────────────────┤│ ││ OpenAI ████████████████░░ 68% ││ $1,666 ││ ││ Anthropic ██████░░░░░░░░░░░░ 24% ││ $588 ││ ││ Google ██░░░░░░░░░░░░░░░░ 8% ││ $196 ││ │└────────────────────────────────────────┘By Model
| Model | Requests | Tokens | Cost | % Total |
|---|---|---|---|---|
| gpt-4o | 45,230 | 12.3M | $1,245 | 51% |
| gpt-4o-mini | 89,450 | 8.7M | $89 | 4% |
| claude-3-sonnet | 21,554 | 5.2M | $520 | 21% |
| gpt-3.5-turbo | 34,120 | 3.1M | $52 | 2% |
By Flow
| Flow | Requests | Avg Cost | Total Cost |
|---|---|---|---|
| customer-support | 52,340 | $0.024 | $1,256 |
| content-generator | 38,210 | $0.019 | $726 |
| qa-pipeline | 65,684 | $0.007 | $460 |
Time-Series Analysis
Daily Trends
Cost Trend (Last 30 Days)$120 ┤ │ ╭───╮$100 ┤ ╭─────╯ ╰──────╮ │ ╭──╯ ╰────╮ $80 ┤─╯ ╰───── │ $60 ┤ └──────────────────────────────────── Nov 1 Nov 8 Nov 15 Nov 22Weekly Comparison
| Week | Cost | Change | Requests |
|---|---|---|---|
| This week | $612 | +5% | 39,210 |
| Last week | $583 | -2% | 37,845 |
| 2 weeks ago | $595 | +8% | 36,120 |
Anomaly Detection
Ladger automatically detects cost anomalies:
Alert Configuration
Set up cost alerts in Project Settings → Alerts:
| Alert Type | Threshold | Action |
|---|---|---|
| Daily spend | > $100 | |
| Weekly spend | > $500 | Slack |
| Cost spike | > 50% increase | PagerDuty |
| Per-request cost | > $0.10 |
Token Analysis
Input vs Output
Token Distribution┌─────────────────────────────────────┐│ ││ Input Tokens ████████████ 72% ││ 8.9M tokens ││ ││ Output Tokens █████░░░░░░░ 28% ││ 3.4M tokens ││ │└─────────────────────────────────────┘Token Efficiency
| Flow | Avg Input | Avg Output | Ratio | Status |
|---|---|---|---|---|
| qa-pipeline | 1,200 | 150 | 8:1 | ✓ Efficient |
| content-gen | 500 | 2,000 | 1:4 | ✓ Expected |
| support-agent | 2,500 | 300 | 8:1 | ⚠ Review |
Cost Attribution
By User/Customer
Track costs per user for billing or analysis:
span.setAttributes({ 'user.id': 'customer-123', 'user.tier': 'enterprise',});Dashboard shows:
| Customer | Requests | Cost | Avg Cost |
|---|---|---|---|
| customer-123 | 12,340 | $245 | $0.020 |
| customer-456 | 8,920 | $178 | $0.020 |
| customer-789 | 5,670 | $113 | $0.020 |
By Feature
Tag spans with feature names:
span.setAttributes({ 'feature': 'smart-search', 'feature.version': '2.0',});Cost Projections
Ladger projects future costs based on trends:
| Timeframe | Projected | Confidence |
|---|---|---|
| Next 7 days | $580 | High (±5%) |
| Next 30 days | $2,650 | Medium (±15%) |
| Next 90 days | $8,200 | Low (±25%) |
Filtering and Drill-Down
Filter cost data by:
- Time range: Last hour, 24h, 7d, 30d, custom
- Provider: OpenAI, Anthropic, Google, etc.
- Model: GPT-4o, Claude-3, etc.
- Flow: Any configured flow name
- Environment: Production, staging, development
- Custom attributes: Any span attribute
Exporting Reports
Generate cost reports:
- Go to Cost Analysis → Reports
- Select date range and filters
- Choose format: PDF, CSV, or JSON
- Schedule recurring reports (Pro/Enterprise)
Report Contents
- Executive summary
- Cost breakdown by dimension
- Trend analysis
- Anomaly highlights
- Optimization recommendations
API Access
Query cost data programmatically:
curl -X GET "https://ladger.pages.dev/api/v1/metrics/costs" \ -H "Authorization: Bearer ladger_sk_live_..." \ -H "Content-Type: application/json" \ -d '{ "flowName": "customer-support", "startDate": "2024-01-01", "endDate": "2024-01-31", "groupBy": "model" }'Next Steps
- Explore Task Classification to understand cost drivers
- Learn about Optimization recommendations
- Set up Simulations to test changes safely