Why preview costs?
Cost transparency builds trust and empowers customers to make informed decisions. Common scenarios include:- Resource-intensive operation cost previews: Show users how much a compute job or data processing task will cost before confirming execution
- Budget planning: Help customers forecast costs for planned usage patterns with interactive cost calculators
- What-if analysis: Let customers explore different usage scenarios to optimize their spending
How cost preview works
The preview events endpoint evaluates events against a customer’s actual contract configuration, including all pricing complexity:- Tiered pricing: Correctly applies volume discounts and tier transitions
- Commits and credits: Shows what usage is covered by commit and credit balances and what spills into overage
- Free allotments: Accounts for included usage in the contract
- Multiple products: Calculates costs across all products in the contract
Preview modes
There are two different ways you can choose to evaluate preview events:Merge mode
Combines preview events with the customer’s existing usage for the billing period. Use this to show incremental cost impact. Example: A customer has used 99 API calls this month (with 100 free). Previewing 5 calls in merge mode shows 1 free and 4 billable.Replace mode
Evaluates only the preview events, ignoring existing usage. Use this for hypothetical “clean slate” scenarios. Example: Show the total monthly cost if a customer only performed the specific actions in the preview.Set up a cost preview
Basic example
Preview how 100 compute hours would affect a customer’s invoice:Response structure
The endpoint returns draft invoices showing the calculated costs:Event deduplication
The preview endpoint follows the same deduplication logic as the ingest endpoint:- Events with identical
transaction_idvalues passed in the same request payload are deduplicated against each other - Events with identical
transaction_idvalues to those passed to/ingestin the prior 34 days are deduplicated as well
Best practices & limitations
Performance considerations
The endpoint has an 8 RPS rate limit per client and is not suitable for real-time validation of every event. Consider these strategies:- Cache preview results: When showing repeated calculations for similar usage patterns, cache the results
- Batch multiple events: Preview multiple events in a single request rather than making separate calls
Accuracy tips
- Include all relevant event properties that affect pricing
- Test both
mergeandreplacemodes during development
Limitations
- Customers using SQL-based billable metrics cannot use this endpoint. If SQL BMs are present on the customer invoice being evaluated when passing in events to preview, the endpoint will return a 400 error.