Usage Metering

How AMADEV tracks API consumption, counts token usage, and feeds the billing subsystem — so Free/Pro/Pro Plus tiers are enforced correctly.

Overview

Every API request that touches a billable model consumes tokens. AMADEV records usage per client through a pool-based gateway: clients claim a gateway slot, emit usage events, then release the slot.

Usage is recorded to the usage_events table in real time. The admin dashboard aggregates these into per-client and global counters that feed the subscription billing engine.

Pool gateway flow

  1. POST /api/v1/pool/claim — client claims a gateway slot and receives connection details (host, port, session token).
  2. While the slot is held, the gateway emits recordUsage events for each model call (prompt_tokens, completion_tokens, cost_usd).
  3. DELETE /api/v1/pool/release — releases the slot so another client can claim it.

Billing endpoints

Aggregated usage is served by the billing API:

  • GET /api/v1/billing/usage — per-client token + cost totals for the current billing period.
  • GET /api/v1/billing/subscription — current tier, entitlements, and quota limits.
  • POST /api/v1/billing/checkout — start a checkout session on Stripe.

See API Reference for the full OpenAPI spec.

Admin dashboard

The admin dashboard shows global and per-client usage. Click through from the Usage metering section for live counters.