REST API & SDKs
OpenMeter exposes a REST API for integrations, with pre-built client SDKs for
popular languages. Both come in two flavors: the current APIs (/api/v1 and /api/v2) that
the examples throughout these docs use, and the new API v3.
If you use Konnect Metering & Billing, you have to use the API v3 and the v3 SDKs. The v1 Cloud and Open Source APIs below apply to the open source project and existing OpenMeter Cloud customers only. If you need the v1 or v2 APIs as a Konnect Metering & Billing customer, reach out to Kong Support to request access.
APIs
The Cloud and Open Source APIs cover the v1 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.
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 for API v3 come with fully typed request and response models. Use them with Konnect Metering & Billing and to access new features.
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