Skip to main content
Baseten meters standard token-based traffic at the Distribution Platform inference gateway. Report usage that only your model can measure, such as usage from streaming, WebSocket, or custom protocol traffic, with the Usage Reporting API. For each inference request attributed to a Distribution Platform customer, Baseten sends a signed identity token in the X-Baseten-Identity-Token header. Copy that token exactly into each usage event. Baseten injects the reporting URL into your model container as the BASETEN_USAGE_ENDPOINT environment variable.

Report one usage event

To report one token-usage event with cURL:Set BASETEN_IDENTITY_TOKEN to the exact value of the X-Baseten-Identity-Token header from a distribution-attributed request. Set ts to the RFC 3339 timestamp when the usage occurred. Set each usage value to the measured, non-negative delta for this event, not a cumulative total.
In a production handler, pass the per-request X-Baseten-Identity-Token value to report_usage after inference succeeds. If the header is absent, skip usage reporting for that request. The helper logs the final failure without failing inference. Monitor this warning so that persistent reporting failures don’t leave usage unreported.

Use supported metrics

Every usage value is a non-negative integer delta for that event, not a cumulative total. A token event includes one or more of uncached_input_tokens, cached_input_tokens, and output_tokens. You can combine token fields, and omitted token fields default to 0. A non-token event uses exactly one of input_characters, audio_seconds, or image_generations. Send separate events for token usage and for each non-token metric type. Baseten sums the deltas from all accepted events for a request or session.

Batch events

A batch can contain events from multiple distribution-attributed inference requests. Each event carries the identity token from its corresponding request. To inspect partial acceptance in a two-event batch: Set FIRST_BASETEN_IDENTITY_TOKEN from a distribution-attributed request. This integration example deliberately uses an invalid identity token for the second event:
The endpoint validates events independently. A 200 OK response means the endpoint processed the request envelope, but it may still reject some events. Check rejected and use each entry’s index in results to identify rejected events. results contains only rejected events. A 400 Bad Request response means the request envelope is invalid, such as malformed JSON or an events value that isn’t an array. The endpoint processes no events.

Retry events

In production integrations, always include ts and format it as RFC 3339. It records when the usage occurred and participates in deduplication. Reuse the exact original ts on every retry. If an event omits ts, the server uses its receive time; retrying that event isn’t idempotent and may double-bill the same usage. After partial acceptance, resend only the rejected events. Don’t resend accepted events as part of the retry.

Limits

The JSON request body must not exceed 1 MiB. The endpoint rejects unknown fields: unknown envelope fields invalidate the request, while unknown event fields reject that event independently.

Next steps

  • Insights: Review customers, models, and estimated gross proceeds associated with accepted usage.
  • Manage your model: Complete the other requirements before your listing goes live.