Creates a new LangfuseClient instance.
Optionalparams: 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.
Manager for dataset operations including retrieval and item linking.
Manager for running experiments on datasets and data items.
The experiment manager provides comprehensive functionality for:
const langfuse = new LangfuseClient();
const result = await langfuse.experiment.run({
name: "Model Evaluation",
description: "Testing model performance on Q&A tasks",
data: [
{ input: "What is 2+2?", expectedOutput: "4" },
{ input: "What is the capital of France?", expectedOutput: "Paris" }
],
task: async ({ input }) => {
// Your model/task implementation
const response = await myModel.generate(input);
return response;
},
evaluators: [
async ({ output, expectedOutput }) => ({
name: "exact_match",
value: output.trim().toLowerCase() === expectedOutput.toLowerCase() ? 1 : 0
})
]
});
console.log(await result.format());
const dataset = await langfuse.dataset.get("my-test-dataset");
const result = await dataset.runExperiment({
name: "Production Readiness Test",
task: myTask,
evaluators: [accuracyEvaluator, latencyEvaluator],
runEvaluators: [overallQualityEvaluator]
});
Manager for media upload and reference resolution.
Manager for prompt operations including creation, retrieval, and caching.
Manager for score creation and batch processing.
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 an experiment in the Langfuse UI.
The ID of the experiment, e.g. ExperimentResult.experimentId
Promise that resolves to the experiment results URL
InternalReturns the ID of the project the API keys belong to. Cached after the first successful lookup.
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 non-tracing Langfuse functionality:
langfuse.prompt) — fetch, cache, compile, and version promptslangfuse.dataset) — manage test datasets and link items to runslangfuse.experiment) — run tasks + evaluators over datasetslangfuse.score) — create evaluation/feedback scores for traces and observationslangfuse.media) — upload media and resolve media referenceslangfuse.api) — the full generated Langfuse REST API clientTracing/observability is intentionally NOT part of this client. To trace your application, use
@langfuse/tracing(instrumentation) together with theLangfuseSpanProcessorfrom@langfuse/otel(export).Example
See