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
All four chat operations (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 optional LangfuseMiddlewareOptions object:
recordContent
When true, input messages and output content are recorded on the Langfuse observation. Defaults to false to avoid sending sensitive data.
The metadata 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: