openmeter

module
v1.0.0-beta.233 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: Apache-2.0

README

OpenMeter logo

OpenMeter

Meter usage. Enforce access. Bill customers. Keep the stack yours.

OpenMeter is open-source monetization infrastructure built for AI, API, and usage-based products. It turns high-volume events into real-time usage, powers access enforcement, and handles usage-based billing from pricing and subscriptions through credits and invoices.

API-first and composable, it can own the path from raw usage to invoice—or only the parts your stack is missing—and work with the payment and tax providers you already use.

Quickstart · Documentation · API reference · Community

GitHub Release CI Status License

How it fits together

Usage events flow through OpenMeter's meters into queries, access decisions, and billing

Is OpenMeter a fit?

Question Answer
What is it best for? Products with usage-based or hybrid pricing, prepaid credits, or usage limits that need one source of truth for consumption.
What is it not? A bundled operator UI, payment processor, tax engine, or general-purpose accounting system. If you only need fixed recurring subscriptions, a direct payment-provider integration is usually simpler.
How mature is it? Releases are beta and can include breaking changes. The OpenMeter metering engine has run in production for years and processed billions of usage events. Review releases and migration guides when upgrading.

What OpenMeter provides

Capability What it covers
Meter usage Ingest CloudEvents, attribute usage to customers, aggregate it in real time, and query it by time window or dimension.
Model products and pricing Define versioned plans, features, add-ons, and flat, recurring, per-unit, tiered, package, or dynamic prices; then assign customer subscriptions.
Control access Calculate feature access and usage-limit balances for your application to enforce, with one-time or recurring entitlement grants.
Bill usage Rate flat and usage-based charges, manage customer credit balances and subscription changes, and run the invoice lifecycle.
Integrate Use the OSS REST API and JavaScript, Python, or Go SDKs, send webhooks, and connect external invoicing providers.

Quickstart

The local evaluation stack requires Git and Docker with Compose. Use curl, Node.js 22+, or Python 3.9+ for the examples below.

git clone https://github.com/openmeterio/openmeter.git
cd openmeter/quickstart
docker compose up -d --wait

The stack includes an api_requests_total meter. Choose a client below; each example sends one request event and queries its metered value.

Bash (curl)
curl -sS -o /dev/null -w '%{http_code}\n' \
  -X POST http://localhost:48888/api/v1/events \
  -H 'Content-Type: application/cloudevents+json' \
  --data-raw '{
    "specversion": "1.0",
    "type": "request",
    "id": "readme-curl-1",
    "source": "readme",
    "subject": "readme-curl",
    "data": { "method": "GET", "route": "/hello" }
  }'

response=
for attempt in 1 2 3 4 5 6 7 8 9 10; do
  response=$(curl -fsS 'http://localhost:48888/api/v1/meters/api_requests_total/query?subject=readme-curl')
  printf '%s' "$response" | grep -q '"value":1' && break
  sleep 1
done
printf '%s\n' "$response"
TypeScript SDK

Install the OpenMeter TypeScript SDK:

npm install @openmeter/sdk tsx

Save as quickstart.ts, then run npx tsx quickstart.ts:

import { OpenMeter } from '@openmeter/sdk'

const openmeter = new OpenMeter({ baseUrl: 'http://localhost:48888' })

const queryUsage = () =>
  openmeter.meters.query('api_requests_total', {
    subject: ['readme-typescript'],
  })

async function main() {
  await openmeter.events.ingest({
    type: 'request',
    id: 'readme-typescript-1',
    source: 'readme',
    subject: 'readme-typescript',
    data: { method: 'GET', route: '/hello' },
  })

  let usage = await queryUsage()
  for (let attempt = 1; usage.data[0]?.value !== 1 && attempt < 10; attempt++) {
    await new Promise((resolve) => setTimeout(resolve, 1000))
    usage = await queryUsage()
  }

  if (usage.data[0]?.value !== 1) {
    throw new Error('usage was not processed in time')
  }
  console.log(usage.data[0].value)
}

main().catch((error) => {
  console.error(error)
  process.exitCode = 1
})
Python SDK

The Python SDK is in preview, so install it with pre-releases enabled:

python -m pip install --pre openmeter

Save as quickstart.py, then run python quickstart.py:

import time

from openmeter import Client
from openmeter.models import Event

with Client(endpoint="http://localhost:48888") as openmeter:
    openmeter.events.ingest_event(
        Event(
            id="readme-python-1",
            source="readme",
            specversion="1.0",
            type="request",
            subject="readme-python",
            data={"method": "GET", "route": "/hello"},
        )
    )

    for _ in range(10):
        usage = openmeter.meters.query_json(
            "api_requests_total",
            subject=["readme-python"],
        )
        if usage.data and usage.data[0].value == 1:
            break
        time.sleep(1)
    else:
        raise RuntimeError("usage was not processed in time")

    print(usage.data[0].value)

Event processing is asynchronous. A successful example ends with a metered value of 1.

[!NOTE] This Compose setup is a local evaluation stack. It runs the OpenMeter API and workers together with Kafka, ClickHouse, PostgreSQL, Redis, and Svix using latest OpenMeter images; it is not a production topology.

Continue with the full OSS quickstart, try a metering example, add entitlements and usage limits, or model plans and subscriptions.

When you are done, remove the containers and their local data volumes:

docker compose down -v

Running OpenMeter

The core runtime is OpenMeter's API and worker processes plus Kafka, ClickHouse, and PostgreSQL. Redis is optional for distributed deduplication and query progress; Svix is used when webhook delivery is enabled. The architecture guide explains the complete runtime and data flow.

The official Helm chart for Kubernetes is intended for development deployments, not production.

Project and community

Need Go to
Ask a question or discuss an approach GitHub Discussions
Report a reproducible bug or request a feature GitHub Issues
Track changes Releases and migration guides
Report a vulnerability Security policy
Build or contribute Contributing guide and Code of Conduct

License

OpenMeter is licensed under the Apache License 2.0.

Directories

Path Synopsis
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
client/go
Package openmeter provides primitives to interact with the openapi HTTP API.
Package openmeter provides primitives to interact with the openapi HTTP API.
types
Some parts of the OpenAPI spec are not supported by oapi-codegen, such as the "oneOf" and "anyOf" keywords.
Some parts of the OpenAPI spec are not supported by oapi-codegen, such as the "oneOf" and "anyOf" keywords.
v3
Package v3 provides primitives to interact with the openapi HTTP API.
Package v3 provides primitives to interact with the openapi HTTP API.
v3/handlers/billingcommon
Package billingcommon holds converter helpers shared by the billing-related v3 handler packages (customer charges, invoices), so that neither handler package needs to import the other.
Package billingcommon holds converter helpers shared by the billing-related v3 handler packages (customer charges, invoices), so that neither handler package needs to import the other.
v3/client module
app
config
Package config loads application configuration.
Package config loads application configuration.
ci module
cmd
balance-worker command
billing-worker command
jobs command
server command
sink-worker command
collector module
e2e module
openmeter
app
customer/testutils/uabench
Package uabench holds shared fixtures for the customer usage-attribution benchmarks.
Package uabench holds shared fixtures for the customer usage-attribution benchmarks.
dedupe
Package dedupe implements in-process event deduplication.
Package dedupe implements in-process event deduplication.
dedupe/memorydedupe
Package memorydedupe implements in-memory event deduplication.
Package memorydedupe implements in-memory event deduplication.
dedupe/redisdedupe
Package redisdedupe implements event deduplication using Redis.
Package redisdedupe implements event deduplication using Redis.
ent
ingest
Package ingest implements event ingestion.
Package ingest implements event ingestion.
namespace
Package namespace adds a concept of tenancy to OpenMeter allowing to segment clients.
Package namespace adds a concept of tenancy to OpenMeter allowing to segment clients.
productcatalog/unitconfig
Package unitconfig holds the UnitConfig domain DTO — the per-rate-card rule that converts a raw metered quantity into a billing quantity before pricing and entitlement evaluation.
Package unitconfig holds the UnitConfig domain DTO — the per-rate-card rule that converts a raw metered quantity into a billing quantity before pricing and entitlement evaluation.
pkg
ffx
Package ffx provides a simple feature flag service.
Package ffx provides a simple feature flag service.
framework/operation
Package operation provides an abstraction for RPC-style APIs.
Package operation provides an abstraction for RPC-style APIs.
kafka
Package kafka implements tools to work with kafka Producers and Consumers.
Package kafka implements tools to work with kafka Producers and Consumers.
log
ref
servicehooks
Package servicehooks provides ordered, synchronous dispatch of typed service events to hooks registered during application startup.
Package servicehooks provides ordered, synchronous dispatch of typed service events to hooks registered during application startup.
set
test
app
tools
migrate
A very lightweigh migration tool to replace `ent.Schema.Create` calls.
A very lightweigh migration tool to replace `ent.Schema.Create` calls.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL