Kaiten
Guides

Entitlement Metering

Deep dive into NUMBER entitlements, meter types, aggregation, and threshold alerts.

Entitlement Metering Guide

This guide covers advanced metering patterns with NUMBER entitlements.

Meter Types

Meter TypeDescriptionUse Case
CALCULATED_USAGEKaiten calculates usage from reported eventsAPI calls, data storage
RAW_EVENTEach report is an individual eventTransaction records

Aggregation Methods

MethodDescriptionExample
SUMTotal of all reported valuesTotal API calls
COUNTNumber of eventsNumber of logins
AVERAGEAverage of reported valuesAverage response time
MAXHighest reported valuePeak concurrent users
MINLowest reported valueMinimum SLA uptime
LATESTMost recent valueCurrent storage used

Reporting Usage

POST /api/instances/{instanceSlug}/entitlements/{entitlementSlug}/usage
{"value": 42}

Each report updates the aggregated usage value based on the entitlement's aggregation method.

Threshold Alerts

When usage reaches the configured threshold, Kaiten emits:

INSTANCE_ENTITLEMENT_USAGE_REACHED

Subscribe to this event via webhooks to trigger:

  • Email notifications to your sales team
  • In-app upgrade prompts
  • CRM pipeline updates
  • Automated billing adjustments

Patterns

Per-Request Metering

Report usage on every API call from your customer's instance:

// In your API middleware
kaiten.ReportUsage(ctx, "acme-production", "api-calls", 1)

Batch Metering

Aggregate usage locally and report periodically:

// Every hour
kaiten.ReportUsage(ctx, "acme-production", "api-calls", hourlyCount)

Gauge Metering (LATEST)

For metrics like "current storage used", use LATEST aggregation:

kaiten.ReportUsage(ctx, "acme-production", "storage-gb", currentStorageGB)

On this page