Interface LDAIConfigTracker

The LDAIConfigTracker is used to track various details about AI operations.

Hierarchy

  • LDAIConfigTracker

Properties

resumptionToken: string

A URL-safe Base64-encoded token that encodes the tracker's runId, configKey, variationKey, and version. Pass this to AIClient.createTracker() to reconstruct the tracker across process boundaries (e.g. for associating deferred feedback with the original invocation).

Methods

  • Get the data for tracking.

    Returns {
        configKey: string;
        graphKey?: string;
        modelName: string;
        providerName: string;
        runId: string;
        variationKey: string;
        version: number;
    }

    • configKey: string
    • Optional graphKey?: string
    • modelName: string
    • providerName: string
    • runId: string
    • variationKey: string
    • version: number
  • Track an operation which uses Bedrock.

    This function will track the duration of the operation, the token usage, and the success or error status.

    Type Parameters

    • TRes extends {
          $metadata: {
              httpStatusCode?: number;
          };
          metrics?: {
              latencyMs?: number;
          };
          usage?: {
              inputTokens?: number;
              outputTokens?: number;
              totalTokens?: number;
          };
      }

    Parameters

    • res: TRes

      The result of the Bedrock operation.

    Returns TRes

    The input operation.

  • Track the duration of generation.

    At-most-once per execution: subsequent calls on the same tracker are dropped with a warning. Use createTracker() on the config result to obtain a fresh tracker for a new execution.

    Ideally this would not include overhead time such as network communication.

    Parameters

    • durationMs: number

      The duration in milliseconds.

    Returns void

  • Track the duration of execution of the provided function.

    If the provided function throws, then this method will also throw. In the case the provided function throws, this function will still record the duration.

    This function does not automatically record an error when the function throws.

    Parameters

    • func: (() => Promise<any>)

      The function to track the duration of.

        • (): Promise<any>
        • Returns Promise<any>

    Returns Promise<any>

    The result of the function.

  • An error was encountered during generation.

    At-most-once per execution: subsequent calls (including trackSuccess) on the same tracker are dropped with a warning.

    Returns void

  • Track sentiment about the generation.

    At-most-once per execution: subsequent calls on the same tracker are dropped with a warning.

    Parameters

    Returns void

  • Track a judge evaluation result.

    No event is emitted when the result was not sampled (result.sampled is false).

    Parameters

    • result: LDJudgeResult

      Judge result containing score, reasoning, and metadata

    Returns void

  • Track metrics for a generic AI operation.

    This function will track the duration of the operation, extract metrics using the provided metrics extractor function, and track success or error status accordingly.

    If the provided function throws, then this method will also throw. In the case the provided function throws, this function will record the duration and an error. A failed operation will not have any token usage data.

    Type Parameters

    • TRes

    Parameters

    • metricsExtractor: ((result) => LDAIMetrics)

      Function that extracts LDAIMetrics from the operation result

    • func: (() => Promise<TRes>)

      Function which executes the operation

        • (): Promise<TRes>
        • Returns Promise<TRes>

    Returns Promise<TRes>

    The result of the operation

  • Track an OpenAI operation.

    This function will track the duration of the operation, the token usage, and the success or error status.

    If the provided function throws, then this method will also throw. In the case the provided function throws, this function will record the duration and an error. A failed operation will not have any token usage data.

    Type Parameters

    • TRes extends {
          usage?: {
              completion_tokens?: number;
              prompt_tokens?: number;
              total_tokens?: number;
          };
      }

    Parameters

    • func: (() => Promise<TRes>)

      Function which executes the operation.

        • (): Promise<TRes>
        • Returns Promise<TRes>

    Returns Promise<TRes>

    The result of the operation.

  • Track metrics for a streaming AI operation.

    This function will track the duration of the operation, extract metrics using the provided metrics extractor function, and track success or error status accordingly.

    Unlike trackMetricsOf, this method is designed for streaming operations where:

    • The stream is created and returned immediately (synchronously)
    • Metrics are extracted asynchronously in the background once the stream completes
    • Duration is tracked from stream creation to metrics extraction completion

    The stream is returned immediately so the caller can begin consuming it without waiting. Metrics extraction happens in the background and does not block stream consumption.

    If the stream creator throws, then this method will also throw and record an error. If metrics extraction fails, the error is logged but does not affect stream consumption.

    Type Parameters

    • TStream

    Parameters

    • streamCreator: (() => TStream)

      Function that creates and returns the stream (synchronous)

        • (): TStream
        • Returns TStream

    • metricsExtractor: ((stream) => Promise<LDAIMetrics>)

      Function that asynchronously extracts metrics from the stream

    Returns TStream

    The stream result (returned immediately, not a Promise)

  • Generation was successful.

    At-most-once per execution: subsequent calls (including trackError) on the same tracker are dropped with a warning.

    Returns void

  • Track the time to first token for this generation.

    At-most-once per execution: subsequent calls on the same tracker are dropped with a warning.

    Parameters

    • timeToFirstTokenMs: number

      The duration in milliseconds.

    Returns void

  • Track information about token usage.

    At-most-once per execution: subsequent calls on the same tracker are dropped with a warning.

    Parameters

    Returns void

  • Track a single tool invocation.

    Parameters

    • toolKey: string

      The identifier of the tool that was invoked.

    Returns void

  • Track multiple tool invocations.

    Parameters

    • toolKeys: string[]

      The identifiers of the tools that were invoked.

    Returns void

  • Track a Vercel AI SDK generateText operation.

    This function will track the duration of the operation, the token usage, and the success or error status.

    If the provided function throws, then this method will also throw. In the case the provided function throws, this function will record the duration and an error. A failed operation will not have any token usage data.

    Type Parameters

    • TRes extends {
          usage?: {
              completionTokens?: number;
              inputTokens?: number;
              outputTokens?: number;
              promptTokens?: number;
              totalTokens?: number;
          };
      }

    Parameters

    • func: (() => Promise<TRes>)

      Function which executes the operation.

        • (): Promise<TRes>
        • Returns Promise<TRes>

    Returns Promise<TRes>

    The result of the operation.

Generated using TypeDoc