Record Structure
Each usage record contains:
Usage records are immutable. Once recorded, they cannot be modified or deleted. MongoDB’s timeseries engine automatically compresses and indexes records by metadata and time for efficient aggregation.
Recording Usage
Usage is recorded viaUsageService.recordUsage(), which writes to the Usage timeseries collection.
Via SDK Endpoint
Record usage directly from your backend using the SDK API:Via Usage Endpoint
The usage endpoint records generic usage events (not direct meter-name events):/v1/sdk/meter-events when you need explicit meterName + value semantics.
Via NATS Event Bus
For internal services, usage can be published over NATS:Automatic MCP Tool Tracking
Every MCP tool call through the SolvaPay proxy automatically records a usage record against the provider’srequests meter. No SDK integration needed — the proxy records usage with the outcome as a property:
Querying Usage
Aggregated Usage
Query total usage for a specific meter and customer within a time range:Time-Bucketed Aggregation
Get usage broken down by time intervals for charting:hour, day, week, month.
When no customerRef is specified, the aggregation runs across all customers.
Analytics Queries
The Usage timeseries powers several analytics views:How Usage Powers Billing and Limits
Limit Checking
When a customer makes a request to a protected endpoint, the system:- Finds the customer’s active purchase for the product
- Looks up the plan to get the
limit - Resolves the plan’s auto-assigned requests meter
- Queries
UsageService.sumForMeter()for usage fromperiodStartto now - Compares the total against the plan’s hard cap
End-of-Period Billing
For post-paid and hybrid plans, a daily cron job:- Finds purchases with expired billing periods
- Queries the Usage timeseries for total usage in the period
- Subtracts free units from the total
- Applies the plan’s pricing (flat rate or tiered)
- Creates a payment intent for the calculated amount
Record Properties
The optionalproperties field supports arbitrary key-value pairs for filtering and analysis:
Environment Isolation
Usage records are stored in environment-specific collections:Usage_sandbox— sandbox environment recordsUsage_live— live environment records