Skip to main content

What are usage events?

A usage event represents customer consumption in your app, such as an API call, token spend, or document generation. Usage events are distinct from meter events:
  • Usage events: analytics and operational visibility
  • Meter events: billing and limit enforcement

Publish a usage event

import { createSolvaPay } from '@solvapay/server'

const solvaPay = createSolvaPay({
  apiKey: process.env.SOLVAPAY_SECRET_KEY,
})

await solvaPay.createEvent({
  type: 'usage.api_call',
  customerRef: 'cus_3C4D5E6F',
  units: 1,
})

Event fields

FieldTypeRequiredDescription
typestringYesDot-notation event type (for example usage.api_call)
customerRefstringYesCustomer reference this event belongs to
productRefstringNoProduct scope for the event
unitsnumberYesQuantity consumed (non-negative)

Common types

  • usage.api_call
  • usage.token
  • usage.message_sent
  • usage.document_generated
  • usage.search
  • usage.storage

Relationship to meters

Use both when needed:
  • createEvent() for product analytics and operations
  • trackUsage() for limits and billing logic

Next steps