Logo

Get Started

OpenMeter provides real-time event-based metering to aggregate usage over time. In this guide you will learn how to create a meter and send an event to OpenMeter.

Getting Started

To get started with OpenMeter you need to create a meter and send an event.

For the complete guide check out the quickstart.

Create a Meter

For example, to count AI token usage by model, provider, and type you can create a meter like this:

await openmeter.meters.create({
  // Unique name for the meter
  slug: 'tokens_total',
  description: 'Total number of tokens',
  // Event type to match
  eventType: 'prompt',
  // Aggregation method
  aggregation: 'SUM',
  // Property to use for the aggregation
  valueProperty: '$.tokens',
  // Properties to group the aggregation by
  groupBy: {
    model: '$.model',
    provider: '$.provider',
    type: '$.type',
  },
});

Checkout the Create a Meter guide for more information.

Meter Examples

Check out the Meter Examples guide for more common metering examples.

Send a Usage Event

To send an event matching the meter above you can use the following code:

await openmeter.events.ingest({
  type: 'prompt',
  subject: 'my-user-id',
  data: {
    tokens: 123456,
    model: 'gpt4',
    provider: 'openai',
  },
});

Checkout the OpenMeter SDKs and Collectors to send events from your application.

Best Practices

Check out the Best Practices for more information on how to design your meters and usage events.