Skip to main content

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. See Usage for cross-session aggregate reporting.

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 every praisonai run with an active session, a compact footer prints to stdout:
Totals persist in session metadata and survive resume. Multi-model runs are priced per-model — each call is priced against its own model via get_pricing(model), then summed. The footer is silenced under --output json. To aggregate these persisted totals across many sessions — by day, model, or project — see Usage.

Quick Start

Cost Tracking Monitors API Expenses

Supported Models

Cost tracking supports 18+ models with accurate pricing:

OpenAI Models

Anthropic Models

Google Models

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_usage merges the new per-call usage from praisonaiagents.telemetry.token_collector into the session file.
  • The token_collector is 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 --continue or praisonai run --session <id> rehydrates RehydratedSession.usage so the cumulative totals continue accumulating.
Sessions stored in the global store (created via the gateway or TUI) are handled transparently — _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:
Cross-link: see Session for the full 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:
Models that are not in 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

  1. Use appropriate models - gpt-4o-mini for simple tasks
  2. Monitor token usage - Check /tokens regularly
  3. Enable caching - Reduces input token costs
  4. Batch operations - Fewer requests = lower overhead

Tracking Tips

  1. Name sessions - Use descriptive session IDs
  2. Export regularly - Save session data for analysis
  3. Set budgets - Implement budget alerts
  4. Review by model - Identify expensive operations

Environment Variables

Aggregate reporting: praisonai usage

The per-session totals persisted here feed the praisonai usage report, which aggregates spend across sessions by day, model, or project.
See Usage for the full command reference, grouping options, and JSON output shape.
  • Usage - Aggregate spend/token reporting across sessions
  • Slash Commands - Use /cost command
  • 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
  • Usage - Cross-session aggregate token and cost reporting