Overview
@core-ai/langfuse provides middleware that records model operations as Langfuse observations. Generations, embeddings, and image operations are tracked with model parameters, token usage, and costs in the Langfuse dashboard.
Installation
@langfuse/otel and @langfuse/tracing are peer dependencies. You need a Langfuse project configured with the appropriate environment variables (LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and optionally LANGFUSE_BASEURL).Usage
Chat models
generate, stream, generateObject, streamObject) are tracked. For streaming operations, the observation stays open until the stream completes and captures the final usage.
Embedding models
Image models
Options
All three factory functions accept an optionalLangfuseMiddlewareOptions object:
recordContent
Whentrue, input messages and output content are recorded on the Langfuse observation. Defaults to false to avoid sending sensitive data.
Metadata
Themetadata field on generation, embed, and image options is forwarded to the Langfuse observation. Use this to attach custom data to your traces.
Tracked attributes
Each Langfuse observation includes:
The
usageDetails keys match the names in Langfuse’s managed model prices, so Langfuse prices cached input at the cache rates. Reasoning tokens stay in output, because providers bill them at the output rate and Claude price definitions have no separate reasoning key.