Skip to main content
SubscriptionFlow Docs
Managing Usages

AI Usage Billing: Duplicate, Late and Corrected Usage Events

Updated

When you report usage to SubscriptionFlow's AI usage billing (for example tokens used by your AI feature, or calls to your API), each usage record is an event sent to:

POST https://<your-subscriptionflow-domain>/api/meter/v1/events

This article explains how SubscriptionFlow handles the same event sent twice, events that arrive late, and corrections, so you can report usage safely and never bill a customer twice.

Every event needs a stable event_id

Each event carries an event_id. SubscriptionFlow uses it to recognise an event it has already received:

  • An event whose event_id was already stored is not stored or charged again. The response counts it under duplicates.
  • So you can always resend a batch after a timeout or network error. Events that already arrived are skipped and the rest are stored.

Build the event_id from something that stays the same when you retry, such as your own request ID. Never generate a new random ID for each attempt, or a retried event will be billed twice.

{
  "events": [{
    "event_id": "req_01JA4Z8W7Q",
    "meter": "llm.tokens",
    "occurred_at": "2026-10-12T10:00:00.123Z",
    "tokens": {"input": 12000, "cached_input": 8000, "output": 1500},
    "properties": {"provider": "openai", "model": "gpt-5"}
  }]
}

When an event reports tokens, SubscriptionFlow splits it into one event per token type, with the IDs req_01JA4Z8W7Q#input, req_01JA4Z8W7Q#cached_input and req_01JA4Z8W7Q#output.

Idempotency-Key for whole requests

You can also send an Idempotency-Key header with each request. Repeating a request with the same key and the same body is safe. Reusing a key with a different body is refused with 409 idempotency_conflict, so use a new key for new work.

When usage happened: the accepted time window

Set occurred_at to when the usage happened, not when you send it. SubscriptionFlow accepts events from up to 35 days ago to 5 minutes in the future (to allow for clock differences). Events outside that window are refused with timestamp_out_of_range.

Usage that arrives after it was invoiced

Usage is added up per hour and billed on the customer's invoice for the period. If an event arrives after the hour it belongs to has already been invoiced, SubscriptionFlow doesn't change the issued invoice. Instead, the event is counted in the current hour and flagged as late, so it's billed on the next invoice. Nothing is lost, and issued invoices never change.

Usage for periods that haven't been invoiced yet is always placed in its own hour, however late it arrives within the 35-day window.

Correcting usage you over-reported

To reduce usage you reported by mistake, send a correction: an event with a negative quantity and properties.corrects set to the event_id of the original event. A correction can't remove more than the original quantity (invalid_correction). Corrections need a tenant (server) key, not a customer key.

Reading the response and retrying

Response What it means What to do
200 All events accepted. Check duplicates to see how many were already stored. Nothing
207 Some events were refused; rejected[] lists each with a code and message. The others were stored. Fix the refused events and resend only those, with the same event_ids
400, 413, 422 The request itself is wrong (bad JSON, too many events, invalid fields) Fix the request; don't retry as is
401, 403 The key is missing, wrong or not allowed to do this Check the key; don't retry
402 insufficient_credits A prepaid customer has no credit left Retry after the customer tops up
409 idempotency_conflict The Idempotency-Key was used with a different body Use a new key
429, 503 Too many requests, or a temporary problem Retry after the Retry-After time, with the same event_ids

Rule of thumb: retry network failures, 429 and 503 with the same IDs; never retry a 4xx error you haven't fixed.

Limits

Events per request 500 (and at most 1 MB)
Properties per event 16 keys, values up to 128 characters
Event time 35 days back to 5 minutes ahead
Requests 600 per minute per key; 3,000 per minute per account
Was this article helpful?0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.