Skip to main content

Overview

The events sub-client provides real-time streaming of authorization events. You can consume events as an async generator via stream(), or use the convenience subscribe() wrapper for a callback-based approach. Events are delivered via Server-Sent Events (SSE).

events.stream()

Open an SSE connection and yield authorization events as an async generator. The connection remains open until you break out of the loop or the server closes it.

Parameters

string[]
Filter to specific event types. If omitted, all event types are streamed.
string
ISO 8601 timestamp to replay events from. Useful for catching up after a disconnection.

Yielded: GrantexEvent

string
Unique event identifier.
string
Event type: 'grant.created', 'grant.revoked', 'token.issued', 'budget.threshold', or 'budget.exhausted'.
string
ISO 8601 timestamp when the event occurred.
object
Event payload. Shape varies by event type — see Event types below.

events.subscribe()

Subscribe to events with a callback function. This is a convenience wrapper around stream() that handles the async iteration for you and returns an unsubscribe function to close the connection.

Parameters

(event: GrantexEvent) => void
required
Callback function invoked for each event.
object
Optional configuration with eventTypes and since fields (same as stream()).

Returns: () => void

An unsubscribe function. Call it to close the SSE connection and stop receiving events.

Event types

grant.created

Emitted when a new grant is created after user consent.

grant.revoked

Emitted when a grant is revoked (by the developer, principal, or system).

token.issued

Emitted when a grant token is issued (via exchange or refresh).

budget.threshold

Emitted when a grant’s budget consumption crosses 50% or 80%.

budget.exhausted

Emitted when a grant’s budget is fully consumed.

Full example

Last modified on March 8, 2026