Skip to main content
Every completion carries a cost estimate — PraisonAI derives it from the token counts your provider reports. Cost is computed from the input_tokens and output_tokens your provider returns, multiplied by a per-model rate. When litellm is installed it covers 1000+ models; otherwise a built-in fallback table prices the most common models.

Quick Start

1

Run an agent and read its token counts

A bare Agent(llm="gpt-4o-mini") records usage automatically. Read the counts back with the global collector:
2

Estimate the cost from those counts

Pass the counts and the model name to calculate_llm_cost():

How It Works

Cost is input_tokens × input_rate + output_tokens × output_rate. The only question is which rate applies to a given model name.

How Pricing Is Resolved

The fallback matcher resolves a model name to a rate in three steps:
  1. Strip the provider prefix. openai/gpt-4o-mini becomes gpt-4o-mini, so provider-qualified names resolve the same as bare names.
  2. Match longest-key-first, on exact match or prefix boundary. The table is searched from the longest key down, and a key only matches when the model name is exactly that key or starts with <key>-…. So gpt-4o-mini is billed at $0.15/1M, not gpt-4o’s $2.50/1M, and o1-mini no longer matches o1.
  3. Fall back to default. If no key matches, the default rate applies. default is never matched by name — it is only the last resort.
Corrected in PraisonAI PR #4200. Prior to this release the fallback matcher used a substring search where the first hit won, which billed gpt-4o-mini at gpt-4o rates — a 16.7× overcharge in the estimate — and let o1-mini match o1. Existing dashboards will show a step-change downward; the new numbers are the accurate ones.

Fallback Pricing Table

These are the built-in rates the SDK ships in _FALLBACK_PRICING (USD per 1M tokens). They apply when litellm is not installed.
Install litellm for accurate pricing across 1000+ models. Pass use_litellm=True to calculate_llm_cost() to prefer it; without it, the fallback table above is used for speed.

Common Patterns

Read the session totals, then price them once:
openai/gpt-4o-mini is stripped to gpt-4o-mini before matching, so it prices at the mini rate:

Best Practices

Pass the exact model string you run with (e.g. gpt-4o-mini, claude-3-5-sonnet). The longest-key-first matcher relies on the full name to avoid billing a -mini model at its larger sibling’s rate.
The fallback table covers common models only. For anything outside it, install litellm and call calculate_llm_cost(..., use_litellm=True) for accurate, up-to-date pricing.
These numbers estimate spend from token counts and published rates. Use your provider’s dashboard for authoritative billing.

Token Tracking

Read real token spend from any agent.

Telemetry

Anonymous usage metrics for agent runs.