Creates a new LangfuseClient instance.
Optional
params: LangfuseClientParamsConfiguration parameters. If not provided, will use environment variables.
Direct access to the underlying Langfuse API client. Use this for advanced API operations not covered by the high-level managers.
Create a dataset
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Create a dataset item
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Creates a new prompt in Langfuse.
The prompt data to create (chat prompt)
Promise that resolves to a ChatPromptClient
Creates a new prompt in Langfuse.
The prompt data to create (text prompt)
Promise that resolves to a TextPromptClient
Creates a new prompt in Langfuse.
The prompt data to create (chat prompt)
Promise that resolves to a ChatPromptClient
Manager for dataset operations including retrieval and item linking.
Get a media record
The unique langfuse identifier of a media record
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Get a observation
The unique langfuse identifier of an observation, can be an event, span or generation
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Get a list of observations
Optional
request: GetObservationsRequestOptional
requestOptions: RequestOptionsRequest-specific configuration.
Get a session. Please note that traces
on this endpoint are not paginated, if you plan to fetch large sessions, consider GET /api/public/traces?sessionId=<sessionId>
The unique id of a session
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Get a specific trace
The unique langfuse identifier of a trace
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Get list of traces
Optional
request: GetTracesRequestOptional
requestOptions: RequestOptionsRequest-specific configuration.
Retrieves a dataset by name along with all its items.
This method automatically handles pagination to fetch all dataset items
and enhances each item with a link
function for easy experiment tracking.
The name of the dataset to retrieve
Optional
options: { fetchItemsPageSize: number }Optional configuration for fetching
Number of items to fetch per page (default: 50)
Promise that resolves to the dataset with enhanced items
const dataset = await langfuse.dataset.get("my-dataset");
for (const item of dataset.items) {
// Use the item data for your experiment
const result = await processItem(item.input);
// Link the result to the dataset item
await item.link(
{ otelSpan: currentSpan },
"experiment-run-1",
{ description: "Testing new model" }
);
}
Get a dataset item
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Get a dataset run and its items
Optional
requestOptions: RequestOptionsRequest-specific configuration.
Get dataset runs
Optional
request: GetDatasetRunsRequestOptional
requestOptions: RequestOptionsRequest-specific configuration.
Retrieves a text prompt by name.
Name of the prompt to retrieve
Optional
options: {Optional retrieval configuration
Optional
cacheTtlSeconds?: numberCache TTL in seconds (0 to disable caching)
Optional
fallback?: stringFallback text content if prompt fetch fails
Optional
fetchTimeoutMs?: numberRequest timeout in milliseconds
Optional
label?: stringLabel to filter by
Optional
maxRetries?: numberMaximum retry attempts for failed requests
Optional
type?: "text"Specify text prompt type
Optional
version?: numberSpecific version to retrieve (defaults to latest)
Promise that resolves to a TextPromptClient
Retrieves a chat prompt by name.
Name of the prompt to retrieve
Optional
options: {Optional retrieval configuration
Optional
cacheTtlSeconds?: numberCache TTL in seconds (0 to disable caching)
Optional
fallback?: ChatMessage[]Fallback chat messages if prompt fetch fails
Optional
fetchTimeoutMs?: numberRequest timeout in milliseconds
Optional
label?: stringLabel to filter by
Optional
maxRetries?: numberMaximum retry attempts for failed requests
Specify chat prompt type
Optional
version?: numberSpecific version to retrieve (defaults to latest)
Promise that resolves to a ChatPromptClient
Manager for media upload and reference resolution.
Manager for prompt operations including creation, retrieval, and caching.
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..."
// }
// }
Manager for score creation and batch processing.
Updates the labels of an existing prompt version.
Update parameters
Name of the prompt to update
New labels to apply to the prompt version
Version number of the prompt to update
Promise that resolves to the updated prompt
Flushes any pending score events to the Langfuse API.
This method ensures all queued scores are sent immediately rather than waiting for the automatic flush interval or batch size threshold.
Promise that resolves when all pending scores have been sent
Generates a URL to view a specific trace in the Langfuse UI.
The ID of the trace to generate a URL for
Promise that resolves to the trace URL
Main client for interacting with the Langfuse API.
The LangfuseClient provides access to all Langfuse functionality including:
Example