Xtopay

Meters & Usage Ingestion API

Model usage meters, ingest high-throughput customer consumption events with idempotency, and query logs.

Meters & Usage Ingestion API

The Meters & Usage Ingestion API allows you to charge customers based on their active consumption of your service. Usage-based billing (or metered billing) requires creating Meters that represent the metric you want to track (e.g. database disk size, API calls, active users), and Usage Events to ingest consumption data in real-time as users interact with your system.


Define a Meter

Create a new meter to track a billable metric.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/meters
Request TypePOST
Content Typeapplication/json
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopemeters:write

Request Parameters

ParameterTypeRequiredDescription
nameStringYesHuman-readable name of the meter (e.g. "AI GPT-4 Token Meter").
eventNameStringYesThe exact event name you will use when sending events (e.g. "gpt4_tokens"). Must be unique.
aggregationStringNoStrategy to sum/aggregate usage: SUM, COUNT, MAX, LAST. Defaults to SUM.
valueFieldStringNoThe JSON key in the event payload containing the quantity. Defaults to "value".

Code Examples

curl https://api.xtopay.co/v1/meters \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "AI Text Ingestion",
    "eventName": "ai_words_processed",
    "aggregation": "SUM",
    "valueField": "value"
  }'

Sample Response

201 Created

{
  "success": true,
  "data": {
    "id": "met_cl8z2e9z50000y",
    "name": "AI Text Ingestion",
    "eventName": "ai_words_processed",
    "aggregation": "SUM",
    "valueField": "value",
    "active": true,
    "createdAt": "2026-06-05T12:00:00Z",
    "updatedAt": "2026-06-05T12:00:00Z"
  }
}

Retrieve a Meter

Retrieve details of an existing meter.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/meters/:id
Request TypeGET
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopemeters:read

Path Parameters

ParameterTypeRequiredDescription
:idStringYesUnique Meter ID (e.g. met_cl8z2e...).

Ingest a Usage Event

Submit usage data in real-time as a customer consumes services. Xtopay supports high-throughput event ingestion.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/meters/:id/events
Request TypePOST
Content Typeapplication/json
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopemeters:write

Request Parameters

ParameterTypeRequiredDescription
customerIdStringNoThe customer ID to associate with the usage.
valueNumberNoThe numeric count/quantity to ingest. Defaults to 1.
timestampStringNoISO 8601 date string when the event occurred. Defaults to the current server time.
idempotencyKeyStringNoA unique string to prevent double-ingesting the exact same event. Duplicate keys are safely ignored.
metadataObjectNoOptional key-value object containing transaction metadata.

Code Examples

curl https://api.xtopay.co/v1/meters/met_cl8z2e9z50000y/events \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "cust_cl8z2e9z50000a",
    "value": 150,
    "idempotencyKey": "evt_unique_1289182391283",
    "metadata": {
      "modelUsed": "gpt-4o"
    }
  }'

Sample Response

201 Created

{
  "success": true,
  "data": {
    "id": "mte_cl8z2f8z80000x",
    "meterId": "met_cl8z2e9z50000y",
    "customerId": "cust_cl8z2e9z50000a",
    "value": 150,
    "idempotencyKey": "evt_unique_1289182391283",
    "timestamp": "2026-06-05T12:05:00Z",
    "metadata": {
      "modelUsed": "gpt-4o"
    },
    "createdAt": "2026-06-05T12:05:00Z"
  }
}

Query Ingested Events

Fetch logs of usage events recorded by a specific meter.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/meters/:id/events
Request TypeGET
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopemeters:read

Query Parameters

ParameterTypeRequiredDescription
customerIdStringNoFilter logs by customer ID.
fromStringNoISO 8601 date string. Filter events created on or after this date.
toStringNoISO 8601 date string. Filter events created on or before this date.
limitIntegerNoMaximum results to return per page (range 1–100, default 20).
cursorStringNoPagination cursor from a previous response.

How is this guide?

Edit this page on GitHub
Last updated on June 6, 2026

On this page