InternalCreates a new MediaManager instance.
Configuration object containing the API client
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.
Configuration object
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..."
// }
// }
Uploads a media object to Langfuse without associating it with a trace.
Used when attaching media to dataset items, where the media is not tied to a trace or observation. Requests a presigned upload URL, uploads the content with retries, and reports completion. If the media has already been uploaded, this resolves without re-uploading.
The media to upload
StaticparseParses a media reference string into a ParsedMediaReference.
Example reference string: "@@@langfuseMedia:type=image/jpeg|id=some-uuid|source=base64DataUri@@@"
The reference string to parse.
An object with the mediaId, source, and contentType.
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).