dexcost

Core Concepts

Tasks, events, cost confidence, and retry tracking.

Tasks

A task is a business operation your AI agent performs -- "resolve support ticket", "generate report", "classify document". Every task has:

  • A type (what kind of work)
  • A customer (who it serves)
  • A status (pending, success, or failed)
  • Aggregated costs rolled up from all events inside it

Tasks can be nested. A parent task can contain child tasks, and costs roll up through the hierarchy.

Events

An event is a single cost-generating action within a task. There are four types:

Event TypeDescriptionExample
llm_callAn LLM API call with token usage and costgpt-4o completion, $0.032
external_costA non-LLM paid API callStripe charge, Pinecone query
compute_costInfrastructure or compute costLambda execution, GPU time
retry_markerA retry event (retry cost tracking)Rate-limited call repeated

Cost confidence

Every cost event carries a confidence level indicating how the cost was determined:

LevelMeaning
exactCost came directly from the provider response or was manually set
computedCost was computed from token counts and dexcost's pricing data
estimatedCost is an approximation (e.g., compute time estimation)
unknownCost could not be determined

Retry tracking

dexcost treats retry cost as a first-class metric. When an LLM call fails due to a transient error (rate limit, timeout, 5xx) and is retried, the retry cost is tracked separately.

Two detection modes:

  • Manual -- call task.mark_retry(reason) explicitly in your error handling
  • Heuristic -- enable automatic detection with enable_retry_heuristics=True. dexcost uses a sliding-window algorithm to detect likely retries based on timing and error patterns.

Attribution

Every task carries optional customer_id and project_id fields. When set, all costs within that task are attributed to that customer and project, enabling per-customer profitability analysis in the dashboard.

On this page