- AI-powered products — Track LLM token costs, embedding calls, and agent compute per customer
- Data enrichment platforms — Record the cost of third-party API calls (geocoding, credit checks, identity verification) attributed to each customer
- Document processing — Attribute OCR, translation, or extraction pipeline costs to the customers who triggered them
- Multi-tenant SaaS — Track cloud compute or storage spend that varies by customer workload
How It Works
- Create a cost metric that defines what you measure and how to aggregate it
- After each operation that incurs a cost, send a cost event to
POST /v0/eventswith the dollar amount - Paygentic aggregates cost events by customer and time period
- Query the aggregated costs via API to build margin dashboards or feed your own analytics
Before You Begin
- Cost tracking enabled on your organization (Private Beta)
- An API key with
events:createandcostMetrics:writepermissions - Your customer IDs available at the time operations are performed
Step 1: Create a Cost Metric
A cost metric defines which events contribute to cost tracking, how to extract the amount, and how to slice costs by dimension.Step 2: Send Cost Events
After each operation that incurs a cost, send an event with the dollar amount. Use the samePOST /v0/events endpoint as meter events — the type field links the event to your cost metric.
Send cost events after the operation completes, once you have the actual cost from your provider. The
amount field should be the total cost in the currency configured on the cost metric.Calculating the amount
Theamount you record should reflect what you actually paid — not an estimate. Retrieve this from your provider’s response or invoice data:
Tracking Multiple Cost Dimensions
Create separate cost metrics for each distinct type of spend. Each metric has its owneventType and tracks independently.
Example: separate metrics for different cost categories
type:
Multiple cost metrics can read from the same
eventType. This lets you extract and aggregate different fields from the same event — for example, tracking GPU cost and CPU cost separately from a single compute event.Cost Metric Reference
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name for this cost metric |
eventType | string | Yes | The type value on cost events. Convention: use a cost. prefix (e.g. cost.ai.inference, cost.enrichment) |
valueProperty | string | Yes | JSONPath expression to extract the cost amount from the event data. For example, $.amount. |
aggregation | enum | Yes | How to combine values. Always sum for cost tracking. |
currency | string | Yes | ISO 4217 currency code (e.g. "USD"). Defaults to your organization’s primary currency. |
groupBy | object | No | Map of dimension names to JSONPath expressions. Allows slicing total cost by provider, operation type, region, etc. |
Cost Event data Fields
The data payload is arbitrary JSON. Only amount (or whichever path valueProperty points to) is required — all other fields are optional context that improves filtering and dimension slicing.
| Field | Description |
|---|---|
amount | Cost in the metric’s currency. Required — this is the value extracted by valueProperty. |
provider | The vendor or service that incurred the cost (e.g. "anthropic", "aws", "clearbit"). |
operation | The type of operation performed (e.g. "document-extraction", "geocoding", "ocr"). |
region | The compute or data region, if relevant for cost attribution. |
data can be referenced in groupBy on your cost metric.
Idempotency
UseidempotencyKey to avoid double-counting costs when retrying failed requests:
- If two events share the same
idempotencyKey, only the first is recorded - The deduplication window is 24 hours
- Omitting
idempotencyKeymeans retries will create duplicate cost entries
Best Practices
Send cost events after the operation completes. You need the actual cost from your provider — don’t estimate upfront and correct later. UseidempotencyKey on every event. Derive it from a stable operation identifier (job ID, request ID) to make retries safe.
One cost event per billable operation, not per customer request. A single customer request may trigger multiple downstream calls — track each one individually for accurate attribution.
Separate metrics for different cost categories. Inference, enrichment, and compute have different unit economics. Tracking them independently makes it easier to understand where margin pressure is coming from.
Next Steps
- Meter Events — The underlying event infrastructure that cost tracking builds on
- Billable Metrics — Define what you measure for customer billing
- Metered Entitlements — Gate customer access based on usage quotas