@limitry/client - v0.4.1
    Preparing search index...

    Class Events

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Ingest a usage event

      Record a single usage event for metering and analytics.

      This endpoint only records the event without checking quotas or rate limits. For quota enforcement and rate limiting, use POST /v1/track instead.

      When to use this endpoint:*

      • Recording events for analytics only
      • Post-event tracking after successful operations
      • Bulk ingestion without enforcement

      When to use /v1/track instead:*

      • Need quota enforcement before processing
      • Need rate limit checking
      • Want all-in-one tracking with enforcement

      Parameters

      • request: {
            costCents?: number;
            customerId: string;
            eventType: string;
            idempotencyKey?: string;
            inputTokens?: number;
            latencyMs?: number;
            model?: string;
            outputTokens?: number;
            properties?: { [key: string]: unknown };
            provider?: string;
            timestamp?: string;
            totalTokens?: number;
        }

        Request body

        • OptionalcostCents?: number

          Cost in cents (e.g., 25 = $0.25)

        • customerId: string

          Your customer's identifier (e.g., user ID, tenant ID)

        • eventType: string

          Type of event (e.g., "model_call", "embedding", "tool_call")

        • OptionalidempotencyKey?: string

          Unique key for deduplication (prevents duplicate events)

        • OptionalinputTokens?: number

          Number of input tokens consumed

        • OptionallatencyMs?: number

          Request latency in milliseconds

        • Optionalmodel?: string

          Model used (e.g., "gpt-4", "claude-3-opus", "gpt-3.5-turbo")

        • OptionaloutputTokens?: number

          Number of output tokens generated

        • Optionalproperties?: { [key: string]: unknown }

          Custom dimensions for filtering and grouping (e.g., user_id, team_id, feature)

        • Optionalprovider?: string

          Provider name (e.g., "openai", "anthropic", "google")

        • Optionaltimestamp?: string

          Format: date-time

          ISO 8601 timestamp (defaults to current time if not provided)

        • OptionaltotalTokens?: number

          Total tokens (auto-calculated if not provided)

      Returns Promise<{ id: string }>

      Event ingested successfully

      const request: Request = {
      customerId: "customerid_123",
      eventType: "example",
      model: "example",
      provider: "provider_123"
      // ... other properties
      };

      const result = await client.events.ingest(request);
      console.log(result);

      Invalid request body

      Unauthorized - Invalid or missing API key

      If a network error occurs

    • Ingest multiple usage events

      Record multiple usage events in a single request for efficient bulk ingestion.

      Limits:*

      • Maximum 1000 events per batch
      • Events are processed asynchronously
      • All events must be valid or the entire batch will be rejected

      Use cases:*

      • Bulk import of historical data
      • Batch processing of events
      • High-throughput event ingestion

      For quota enforcement and rate limiting, use POST /v1/track instead.

      Parameters

      • request: {
            events: {
                costCents?: number;
                customerId: string;
                eventType: string;
                idempotencyKey?: string;
                inputTokens?: number;
                latencyMs?: number;
                model?: string;
                outputTokens?: number;
                properties?: { [key: string]: unknown };
                provider?: string;
                timestamp?: string;
                totalTokens?: number;
            }[];
        }

        Request body

        • events: {
              costCents?: number;
              customerId: string;
              eventType: string;
              idempotencyKey?: string;
              inputTokens?: number;
              latencyMs?: number;
              model?: string;
              outputTokens?: number;
              properties?: { [key: string]: unknown };
              provider?: string;
              timestamp?: string;
              totalTokens?: number;
          }[]

          Array of events to ingest (max 1000)

      Returns Promise<{ count: number }>

      Events ingested successfully

      const request: Request = {
      events: []
      };

      const result = await client.events.ingestBatch(request);
      console.log(result);

      Invalid request body

      Unauthorized - Invalid or missing API key

      If a network error occurs

    • List usage events

      Retrieve a paginated list of usage events with optional filtering.

      Use cursor-based pagination by passing the nextCursor from the previous response. You can filter events by customer, event type, or model.

      Pagination:*

      • Use the cursor parameter from the previous response's nextCursor field
      • The hasMore field indicates if there are more results
      • Maximum limit is 100 events per request

      Parameters

      • OptionalcustomerId: string

        Filter events by customer ID

      • OptionaleventType: string

        Filter events by type (e.g., "model_call", "embedding")

      • Optionalmodel: string

        Filter events by model name (e.g., "gpt-4", "claude-3")

      • Optionallimit: string

        Maximum number of events to return (1-100, default: 50) (default: "50")

      • Optionalcursor: string

        Pagination cursor from the previous response

      Returns Promise<EventsListResponse>

      List of events

      const items = await client.events.list();
      for (const item of items.data) {
      console.log(item);
      }

      Invalid query parameters

      Unauthorized - Invalid or missing API key

      If a network error occurs