Skip to main content
Cost insights puts what you spend next to what you earn. Attach a cost to the events you already send, and Polar reports costs, gross margin and cashflow, overall and per customer. Revenue comes from your orders. Costs come from your events. Typical costs: LLM calls, GPU minutes, storage, email and SMS sends. The examples on this page use the sandbox and API version 2026-10. See Usage for how events work.

Cost events

Add a _cost object to an event’s metadata. For LLM calls, add _llm too, so costs can be broken down by model and vendor.
In production, send events in batches. See Send events.

_cost

The amount is in cents, not dollars: 150 is $1.50, and `0.0014` is $0.000014. Fractions of a cent are kept, so you can record the cost of a single API call.

_llm

These two are the only nested objects metadata accepts. A meter can read inside them with a dot path, like _cost.amount or _llm.total_tokens. The LLM strategy adds _llm for you, and _cost when you give it a .cost() function. Other ingestion strategies accept .cost() too.

Traces

One user action often costs several things: an agent run makes three LLM calls and a web search. Send each as an event, and link them with parent_id so their costs add up under one trace.
  1. Send the root event with your own external_id, such as a request ID.
  2. Send each child with parent_id set to that external_id, or to the root event’s Polar ID.
Children can arrive before their parent. Polar holds them until the parent arrives. If it never does, they aren’t processed, so always send the root. In Analytics → Costs, the event type page for agent_run adds up the costs of its children, so you see what a whole run costs. If you trace with OpenTelemetry, the PolarTraceExporter sends spans as events with the parent links already set. See OpenTelemetry.

Where costs show up

Dashboard only, except the metrics below, which the API, CLI and MCP server can read.
Analytics → Costs has two tabs:
  • Overview: the cost metrics as charts, then:
    • Breakdown: event types ranked by total spend in the period.
    • Changes: the biggest cost movers compared to the previous period.
    • By Customer: customers ranked by total cost.
    • Anomalies: individual traces whose total cost is at or above the 99th percentile for their event type.
  • LLM: costs from events with _llm, ranked By Model, By Vendor and By Customer.
Select an event type to see its Occurrences, Total Cost, Average Cost and Cost per Customer over time. Analytics → Events has a Cost filter to show only events that carry a cost. Customers → Cost Drivers ranks customers by their share of your costs. See Customer analytics.

Cost metrics

These metrics come from your _cost data and your revenue. Find them as charts on Analytics → Costs and in the Costs and Usage groups on Analytics → Metrics. Amounts are in cents. Lifetime Value (ltv) also subtracts cost per user from revenue per user. See Metrics for every metric.
Pass customer_id to get one customer’s costs and margin.

From the CLI or your agent

Costs are sent with events, from your application. Reading them works everywhere:
Prompt

Learn more