- Fetch them on demand with
GET /v1/gateway/events. Nothing to provision: the endpoint works with your workspace API key and you poll on your schedule. - Receive them as signed webhooks pushed to your endpoint as requests happen. Baseten configures webhook delivery per workspace during managed onboarding: your Baseten team provisions the target URL and webhook signing secret before your first event ships. Choose webhooks when you want near-real-time push delivery or need the request’s
requestMetadatapassthrough, which fetched events don’t include.
Fetch events
Call the events API with a time window.start_time is required and inclusive, end_time defaults to the current time and is exclusive, and events come back in ascending timestamp order, cursor-paginated:
idempotencyKey. For the full request, response, and error reference, see List gateway events.
Webhook payload
Baseten POSTs a JSON body to your configured webhook URL. Every payload uses the standard Baseten envelope, wheretype is the discriminator and data holds the event-specific fields. Frontier Gateway emits the API_BILLING_USAGE event type; future event types may share the same envelope.
The data.events array can contain one or more events per delivery. Each event corresponds to a single inference request. Payloads may carry fields beyond those documented here; ignore them, as they’re internal and can change without notice.
string
required
Stable identifier for the event. Use this to deduplicate on your side.
string
required
ISO 8601 UTC timestamp of the inference request.
string
required
Per-request identifier, useful for correlating billing events with platform logs.
object | null
required
Freeform JSON object passed through from the inference request. May be
null when no metadata is supplied.string
required
The model slug invoked, in
your-org/your-model form.string
required
The
metadata.external_entity_id you set on the group that owns the key used for the request, the same value you write when you create or update the group.string
required
Prefix of the federated API key that made the request (the substring before the
. in the full key string). The group identifies your customer; the prefix identifies which of that customer’s keys drove the usage.object
required
Token counts for the request.
- inputTokens (
integer, required): Prompt tokens. - outputTokens (
integer, required): Generated tokens. - cachedInputTokens (
integer, required): Prompt tokens served from cache, when applicable.
Headers
Baseten sets two headers on every delivery:X-Baseten-Signature: HMAC signature of the raw request body. For more information, see Verify the signature.X-Baseten-Request-ID: UUID generated per outbound delivery. Log this on your receiver as a correlation ID for debugging against Baseten platform logs. UseidempotencyKey, not this header, to dedupe events on your side; the samerequestIdis reused across retry attempts of a single delivery.
Verify the signature
TheX-Baseten-Signature header has the format v1=<hex>, where <hex> is the HMAC-SHA256 of the raw request body computed with your workspace’s webhook signing secret. Verify the signature on every request before trusting the payload.
Two requirements:
- Verify against the raw bytes of the request body, not a re-serialized version. JSON re-serialization changes whitespace and field order and breaks the HMAC.
- Use a constant-time comparison (
hmac.compare_digestin Python,crypto.timingSafeEqualin Node.js) to avoid timing attacks.
- Python
- Node.js
To verify the signature:
verify.py
Webhook delivery semantics
Baseten retries failed deliveries with exponential backoff so a transient blip on your endpoint doesn’t drop billing events. Use these numbers to size your endpoint SLOs and to know when a failure is terminal.- Per-attempt timeout: 10 seconds. If your endpoint doesn’t respond within this window, Baseten cancels the attempt and treats it as a failure.
- Backoff: Exponential, starting at 1 second between attempts and capping at 5 seconds.
- Maximum elapsed time: 15 seconds. After this, Baseten stops retrying and routes the event to a dead-letter queue. The retry window is tight: the realistic budget is one or two attempts.
- 4xx responses are terminal: Any 4xx status from your endpoint stops retries immediately. Only 5xx responses, network errors, and timeouts trigger a retry.
Recommended webhook consumption pattern
Treat the webhook handler as an ingestion endpoint, not a billing pipeline. The handler’s job is to durably accept the event and return as fast as possible:- Verify the signature.
- Persist the event to your own queue or database, keyed on
idempotencyKey. - Return a 2xx response.
- Process and forward to your billing provider asynchronously.
Next steps
- List gateway events: Fetch billing events on demand instead of running a webhook receiver.
- Manage groups and API keys: Create groups, build a hierarchy, mint and revoke keys, and delete groups.
- Rate and usage limits: Cap per-group, per-model token and request volume.