Cost Tracking
PraisonAI CLI provides comprehensive cost tracking to help you monitor token usage and expenses across your AI coding sessions. Know exactly what you’re spending in real-time.Overview
The cost tracking system monitors:- Token usage - Input, output, and cached tokens
- Cost calculation - Real-time cost based on model pricing
- Session statistics - Aggregated stats across requests
- Model breakdown - Usage per model
Per-session totals
After everypraisonai run with an active session, a compact footer prints to stdout:
get_pricing(model), then summed. The footer is silenced under --output json.
Quick Start

Supported Models
Cost tracking supports 18+ models with accurate pricing:OpenAI Models
| Model | Input (per 1M) | Output (per 1M) |
|---|---|---|
| gpt-4o | $2.50 | $10.00 |
| gpt-4o-mini | $0.15 | $0.60 |
| gpt-4-turbo | $10.00 | $30.00 |
| o1 | $15.00 | $60.00 |
| o1-mini | $3.00 | $12.00 |
| o3-mini | $1.10 | $4.40 |
Anthropic Models
| Model | Input (per 1M) | Output (per 1M) |
|---|---|---|
| claude-3-5-sonnet | $3.00 | $15.00 |
| claude-3-opus | $15.00 | $75.00 |
| claude-3-haiku | $0.25 | $1.25 |
Google Models
| Model | Input (per 1M) | Output (per 1M) |
|---|---|---|
| gemini-2.0-flash | $0.10 | $0.40 |
| gemini-1.5-pro | $1.25 | $5.00 |
| gemini-1.5-flash | $0.075 | $0.30 |
Python API
Basic Tracking
Session Statistics
Tracking from LLM Responses
Export Session Data
CLI Integration
Interactive Mode
Token Breakdown
Cost Calculation
How Costs Are Calculated
Custom Pricing
Add pricing for custom or new models:Per-session persistence
Usage is now accumulated into the session metadata at~/.praisonai/sessions/<id>.json under a usage blob, so costs persist across terminal sessions and are visible in praisonai session list.
How it works:
- After each run,
accumulate_session_usagemerges the new per-call usage frompraisonaiagents.telemetry.token_collectorinto the session file. - The
token_collectoris then reset to avoid double-counting on the next run. - Pricing comes from
cli/features/cost_tracker.get_pricing(model)— the same model price table used by/cost. - Resuming with
praisonai run --continueorpraisonai run --session <id>rehydratesRehydratedSession.usageso the cumulative totals continue accumulating.
_resolve_usage_store prefers whichever record already carries usage, so resuming a globally-stored session keeps accumulating into the original record.
Persisted usage blob keys:
| Key | Type | Notes |
|---|---|---|
input_tokens | int | Cumulative prompt tokens |
output_tokens | int | Cumulative completion tokens |
cached_tokens | int | Cumulative cached / prefix-hit tokens (when the provider reports them) |
total_tokens | int | input + output (cached not double-counted); mirrored to flat total_tokens on session metadata |
cost | float | USD; mirrored to flat cost on session metadata |
requests | int | Count of agent.start() runs that produced usage |
session list column reference and Run for the per-run usage footer.
Scheduler Integration
AgentScheduler and AsyncAgentScheduler price every run through ModelPricing (since PR #2171). Any model you register here becomes spendable from the scheduler’s max_cost brake:
DEFAULT_PRICING are priced at $0 — they still run, but total_cost_usd will under-report and the max_cost brake won’t trip. See Async Agent Scheduler for the full budget pattern.
Real-Time Monitoring
Display During Operations
Budget Alerts
Session Management
Multiple Sessions
End Session
Best Practices
Cost Optimization
- Use appropriate models - gpt-4o-mini for simple tasks
- Monitor token usage - Check
/tokensregularly - Enable caching - Reduces input token costs
- Batch operations - Fewer requests = lower overhead
Tracking Tips
- Name sessions - Use descriptive session IDs
- Export regularly - Save session data for analysis
- Set budgets - Implement budget alerts
- Review by model - Identify expensive operations
Environment Variables
Related Features
- Slash Commands - Use
/costcommand - Metrics - Detailed performance metrics
- Telemetry - Usage analytics
- Session - Per-session token and cost columns in
session list - Run - Per-run usage footer after each prompt

