Table of Contents
- What are Usage Events?
- Publishing a Usage Event
- Event Fields
- Event Types
- Examples
- Relationship to Meters
What are Usage Events?
A Usage Event represents a unit of consumption in your application — an API call made, a document generated, storage consumed, a message sent. Publishing usage events lets SolvaPay track what your customers are consuming, enforce plan limits, and provide usage analytics. Usage events are distinct from meter events. Meters are for precise billing counters. Usage events are broader — they capture consumption context (which customer, which product, how many units) and feed into the event system for analytics, alerting, and operational visibility.Publishing a Usage Event
UsecreateEvent() to publish a usage event:
Response
eventId is a unique identifier for the published event.
Event Fields
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Dot-notation event type (e.g. usage.api_call) |
customerRef | string | Yes | The customer reference this event belongs to |
productRef | string | No | The product reference, if the event is scoped to a specific product |
units | number | Yes | Quantity consumed (must be non-negative) |
type
A dot-notation string that categorises the event. Convention is usage.<action>, for example:
usage.api_callusage.document_generatedusage.message_sentusage.storageusage.tokenusage.search
usage..
customerRef
The customer reference (cus_...) identifying who consumed the resource. This must be a valid customer reference in your SolvaPay account.
productRef
Optional. The product reference (prd_...) to scope the event to a specific product. Useful when a customer has purchases across multiple products and you want usage attributed to the correct one.
units
The quantity consumed. Must be a non-negative number. The meaning depends on your type:
- For
usage.api_call: typically1per call - For
usage.token: the number of tokens consumed - For
usage.storage: bytes or megabytes used
Event Types
You define your own event types using dot-notation. Here are common patterns:| Type | Use Case |
|---|---|
usage.api_call | REST or GraphQL API requests |
usage.token | LLM token consumption |
usage.message_sent | Chat or notification messages |
usage.document_generated | PDF, report, or file generation |
usage.search | Search queries executed |
usage.storage | File or data storage consumption |
usage.compute | Compute time or processing units |
Examples
Track API calls in Express
Track token consumption in an AI app
Track document generation
Track storage usage
Relationship to Meters
Usage events and meter events serve different purposes:| Usage Events | Meter Events | |
|---|---|---|
| Purpose | Operational visibility and analytics | Billing and limit enforcement |
| Method | solvaPay.createEvent() | solvaPay.trackUsage() |
| Enforces limits | No | Yes |
| Triggers paywalls | No | Yes |
| Visible in ops dashboard | Yes | No |
Next Steps
- Core Concepts - Understand products, plans, and the paywall flow
- Meters - Set up meters for billing and limit enforcement
- Webhook Handling - React to purchase and payment events