Logo

Get Started

Prerequisites

You need to have an instance of OpenMeter running and configured. If you haven't yet, watch our Getting Started guide. We'll be using the Node.js OpenMeter SDK, but the concepts are the same whether using an SDK, the API, or the Cloud UI.

This guide also builds on the Entitlements Get Started guide by assuming that the environment has features and entitlements set up.

1. Set up a URL to receive the events

We will use Svix Playground for that URL.

Let's say that our URL is the following: https://play.svix.com/in/e_4Iv1ft38HaoM36eVa3X1Q7w1vN5/

2. Create a notification channel

OpenMeter needs to know where to deliver the notifications to. In this step, we are creating a webhook typed notification channel that will be used to deliver events:

import { OpenMeter } from '@openmeter/sdk';
 
const openmeter = new OpenMeter({
  baseUrl: 'https://openmeter.cloud',
  token: '<API_TOKEN>', // Cloud only
});
 
const channel = await openmeter.notification.channels.create({
  type: 'WEBHOOK',
  name: 'Webhook Channel',
  url: 'https://play.svix.com/in/e_4Iv1ft38HaoM36eVa3X1Q7w1vN5/',
});

3. Create a notification rule

In this example, we are to create a Balance Change Notification Rule that would emit an event to the channel if the gpt_4_tokens feature's usage reaches 80% and 100% (the feature is defined in the Entitlements Getting Started guide).

await openmeter.notification.rules.create({
  type: 'entitlements.balance.threshold',
  name: 'Limit Notifications',
  channels: [channel.id],
  thresholds: [
    {
      type: 'PERCENT',
      value: 80,
    },
    {
      type: 'PERCENT',
      value: 100,
    },
  ],
});

4. Ingest events

Start ingesting events for a subject; a notification should arrive at the URL obtained in the first step when the usage reaches 80%.