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

    Class Usage

    Index

    Constructors

    Methods

    • Get usage breakdown

      Retrieve usage metrics grouped by a specific dimension.

      This endpoint provides detailed breakdowns of usage data, allowing you to see how usage is distributed across different dimensions like models, customers, event types, or providers.

      Use Cases:*

      • See which models consume the most tokens
      • Identify top customers by usage
      • Compare usage across different event types
      • Analyze provider-specific consumption

      Parameters

      • groupBy: "model" | "customer_id" | "event_type" | "provider"

        Dimension to group usage by (one of: "model", "customer_id", "event_type", "provider")

      • startDate: string

        Start of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")

      • endDate: string

        End of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")

      • OptionalcustomerId: string

        Filter usage by customer ID before grouping

      • OptionaleventType: string

        Filter usage by event type before grouping

      • Optionalmodel: string

        Filter usage by model name before grouping

      Returns Promise<
          {
              data: {
                  dimension?: string
                  | null;
                  totalCostCents: number;
                  totalEvents: number;
                  totalInputTokens: number;
                  totalOutputTokens: number;
                  totalTokens: number;
              }[];
          },
      >

      Usage breakdown

      const result = await client.usage.getBreakdown(
      groupBy: "example",
      startDate: "2024-01-01T00:00:00Z",
      endDate: "2024-01-01T00:00:00Z"
      );
      console.log(result);

      Invalid query parameters

      Unauthorized - Invalid or missing API key

      If a network error occurs

    • Get usage summary

      Retrieve aggregated usage metrics for the project.

      Returns totals for events, tokens, and costs within the specified date range. You can filter by customer, event type, or model to get specific subsets of data.

      Metrics Included:*

      • Total events count
      • Total tokens (input + output)
      • Total input tokens
      • Total output tokens
      • Total cost in cents

      Parameters

      • startDate: string

        Start of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")

      • endDate: string

        End of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")

      • OptionalcustomerId: string

        Filter usage by customer ID

      • OptionaleventType: string

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

      • Optionalmodel: string

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

      Returns Promise<
          {
              totalCostCents: number;
              totalEvents: number;
              totalInputTokens: number;
              totalOutputTokens: number;
              totalTokens: number;
          },
      >

      Usage summary

      const result = await client.usage.getSummary(
      startDate: "2024-01-01T00:00:00Z",
      endDate: "2024-01-01T00:00:00Z"
      );
      console.log(result);

      Invalid query parameters

      Unauthorized - Invalid or missing API key

      If a network error occurs

    • Get usage timeseries

      Retrieve usage metrics bucketed by time interval.

      Returns time-series data showing how usage changes over time. Useful for creating charts, identifying trends, and monitoring usage patterns.

      Intervals:*

      • hour: Bucket data by hour
      • day: Bucket data by day
      • week: Bucket data by week

      Each data point includes the timestamp and all usage metrics for that time period.

      Parameters

      • interval: "hour" | "day" | "week"

        Time interval for bucketing data (one of: "hour", "day", "week")

      • startDate: string

        Start of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")

      • endDate: string

        End of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")

      • OptionalcustomerId: string

        Filter usage by customer ID

      • OptionaleventType: string

        Filter usage by event type

      • Optionalmodel: string

        Filter usage by model name

      Returns Promise<
          {
              data: {
                  timestamp: string;
                  totalCostCents: number;
                  totalEvents: number;
                  totalInputTokens: number;
                  totalOutputTokens: number;
                  totalTokens: number;
              }[];
          },
      >

      Usage timeseries

      const result = await client.usage.getTimeseries(
      interval: "example",
      startDate: "2024-01-01T00:00:00Z",
      endDate: "2024-01-01T00:00:00Z"
      );
      console.log(result);

      Invalid query parameters

      Unauthorized - Invalid or missing API key

      If a network error occurs