Langfuse JS/TS SDKs
    Preparing search index...

    Manager for media operations in Langfuse.

    Provides methods to resolve media references in objects by replacing them with actual media content (e.g., base64 data URIs).

    Index

    Constructors

    • Internal

      Creates a new MediaManager instance.

      Parameters

      • params: { apiClient: LangfuseAPIClient }

        Configuration object containing the API client

      Returns MediaManager

    Methods

    • Replaces media reference strings in an object with base64 data URIs.

      This method recursively traverses an object looking for media reference strings in the format "@@@langfuseMedia:...@@@". When found, it fetches the actual media content from Langfuse and replaces the reference string with a base64 data URI.

      If fetching media content fails for a reference string, a warning is logged and the reference string is left unchanged.

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

      A deep copy of the input object with media references resolved

      const obj = {
      image: "@@@langfuseMedia:type=image/jpeg|id=123|source=bytes@@@",
      nested: {
      pdf: "@@@langfuseMedia:type=application/pdf|id=456|source=bytes@@@"
      }
      };

      const result = await langfuse.media.resolveReferences({
      obj,
      resolveWith: "base64DataUri"
      });

      // Result:
      // {
      // image: "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
      // nested: {
      // pdf: "data:application/pdf;base64,JVBERi0xLjcK..."
      // }
      // }
    • Parses a media reference string into a ParsedMediaReference.

      Example reference string: "@@@langfuseMedia:type=image/jpeg|id=some-uuid|source=base64DataUri@@@"

      Parameters

      • referenceString: string

        The reference string to parse.

      Returns ParsedMediaReference

      An object with the mediaId, source, and contentType.

      Error if the reference string is invalid or missing required fields.