- 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
GET /v0/costs/{id}/summaryto build margin dashboards or feed your own analytics
Before you begin
- An API key for your organization
- A product created in Paygentic (you need the
productId) - 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. Every cost must be attached to a product viaproductId.
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:
Step 3: Query cost summary
UseGET /v0/costs/{id}/summary to retrieve aggregated cost data for a specific cost metric over a time window.
Group by dimensions
AddgroupBy to break down costs by the dimensions you configured on the cost metric:
groups array:
Time-series breakdown
Addwindow to get a time-series breakdown:
timeSeries array:
Filter by dimension values
UsefilterGroupBy to narrow results to specific dimension values:
filterGroupBy value is a JSON-encoded object. Keys must match those defined in the cost’s groupBy configuration.
Managing costs
List costs
Retrieve all costs for your organization, optionally filtered by product:Get a single cost
Update a cost
All fields are optional — only include the fields you want to change:Delete a cost
Deleting a cost performs a soft delete. The cost is no longer returned in list queries, but historical data is preserved.204 No Content on success.
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.A single event can also be processed by both a billable metric and a cost metric simultaneously. For example, an ai.inference event can drive customer billing via a billable metric while the same event feeds your cost tracking — no need to send separate events.API reference
Create cost request
Cost response object
Cost summary query parameters
Cost summary response
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.
Any other fields you include in
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