REST API & SDKs
OpenMeter exposes a REST API for integrations, with pre-built client SDKs for
popular languages. Both come in two flavors: the stable current APIs (/api/v1)
that the examples throughout these docs use, and the new API v3 in preview.
APIs
The Cloud and Open Source APIs are the stable surface:
Cloud API
Open Source API
API v3
API v3 is a rewrite of the OpenMeter API with AIP (API Improvement Proposal) standardization. It provides a cleaner, more consistent design for metering, billing, and related resources.
API v3 is in preview and incomplete. Some functionalities available in the Cloud and Open Source APIs are not yet available in v3, and endpoints marked unstable may still change. We are iterating on the spec and adding capabilities over time. For production use, prefer the stable Cloud and Open Source APIs above.
SDKs
Currently, we provide pre-built client SDKs for:
Install and Initialize
Install the JavaScript SDK:
npm install --save @openmeter/sdkInitialize the client:
import { OpenMeter } from '@openmeter/sdk';
const openmeter = new OpenMeter({
baseUrl: 'https://openmeter.cloud',
apiKey: '<API_TOKEN>',
});For self-hosted OpenMeter, point the client at your instance (by default
http://127.0.0.1:8888) instead of https://openmeter.cloud; no API key is
required.
v3 SDKs
New SDKs generated from the OpenMeter TypeSpec definitions target API v3 with fully typed request and response models. Like the API, they are in preview.
Install the TypeScript SDK:
npm install @openmeter/clientInitialize the client with the v3 base URL, then call any resource. The
API key is sent as a Bearer token on every request:
import { OpenMeter } from '@openmeter/client';
const client = new OpenMeter({
baseUrl: 'https://openmeter.cloud/api/v3',
apiKey: process.env.OPENMETER_API_KEY,
});
// Create a meter
const meter = await client.meters.create({
name: 'Tokens',
key: 'tokens',
aggregation: 'sum',
eventType: 'request',
valueProperty: '$.tokens',
});
// Ingest a usage event (CloudEvents)
await client.events.ingest({
id: 'evt-00001',
source: 'my-service',
type: 'request',
subject: 'customer-1',
data: { tokens: '123456', model: 'gpt-4' },
});Every list operation also has an …All companion returning an
AsyncIterable that fetches pages lazily:
for await (const meter of client.meters.listAll()) {
console.log(meter.key);
}Responses return date-time fields as native Date objects, and requests
accept either a Date or an RFC 3339 string.
In cases where no specific SDK is available for your preferred programming language, you can utilize the OpenAPI Definitions. Please raise a GitHub issue in our repository to request SDK support in other languages.
Last updated on