Skip to content

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

ModelRequestsTokensCost% Total
gpt-4o45,23012.3M$1,24551%
gpt-4o-mini89,4508.7M$894%
claude-3-sonnet21,5545.2M$52021%
gpt-3.5-turbo34,1203.1M$522%

By Flow

FlowRequestsAvg CostTotal Cost
customer-support52,340$0.024$1,256
content-generator38,210$0.019$726
qa-pipeline65,684$0.007$460

Time-Series Analysis

Cost Trend (Last 30 Days)
$120 ┤
│ ╭───╮
$100 ┤ ╭─────╯ ╰──────╮
│ ╭──╯ ╰────╮
$80 ┤─╯ ╰─────
$60 ┤
└────────────────────────────────────
Nov 1 Nov 8 Nov 15 Nov 22

Weekly Comparison

WeekCostChangeRequests
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 SettingsAlerts:

Alert TypeThresholdAction
Daily spend> $100Email
Weekly spend> $500Slack
Cost spike> 50% increasePagerDuty
Per-request cost> $0.10Email

Token Analysis

Input vs Output

Token Distribution
┌─────────────────────────────────────┐
│ │
│ Input Tokens ████████████ 72% │
│ 8.9M tokens │
│ │
│ Output Tokens █████░░░░░░░ 28% │
│ 3.4M tokens │
│ │
└─────────────────────────────────────┘

Token Efficiency

FlowAvg InputAvg OutputRatioStatus
qa-pipeline1,2001508:1✓ Efficient
content-gen5002,0001:4✓ Expected
support-agent2,5003008: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:

CustomerRequestsCostAvg Cost
customer-12312,340$245$0.020
customer-4568,920$178$0.020
customer-7895,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:

TimeframeProjectedConfidence
Next 7 days$580High (±5%)
Next 30 days$2,650Medium (±15%)
Next 90 days$8,200Low (±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:

  1. Go to Cost AnalysisReports
  2. Select date range and filters
  3. Choose format: PDF, CSV, or JSON
  4. 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:

Terminal window
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