Skip to main content

Overview

Langfuse is an open-source LLM observability and analytics platform. Track, debug, and improve your AI applications with detailed traces, metrics, and cost analysis.
Perfect for production monitoring, debugging, and optimizing your AI applications.

Installation

Quick Start

1. Setup Langfuse

2. Make Tracked API Calls

That’s it! View traces in your Langfuse dashboard.

Advanced Tracking

Custom Trace Names

Add Metadata and Tags

Function Tracing with @observe()

Track complex workflows with nested LLM calls:

Streaming with Langfuse

Multi-Model Comparison

Track different models to compare performance:

Cost Tracking

Langfuse automatically tracks costs for API calls:

User Tracking

Associate requests with specific users:

Session Tracking

Group related requests into sessions:

Scoring and Feedback

Add scores and feedback to traces:

What Gets Tracked

Langfuse automatically captures:
  • Request/Response: Full messages and completions
  • Tokens: Input, output, and total token counts
  • Latency: API response times
  • Cost: Estimated costs per request
  • Model: Which model was used
  • Metadata: Custom tags and metadata
  • Errors: API errors and exceptions
  • Users/Sessions: User and session tracking

Langfuse Dashboard Features

1. Traces View

See all API calls with:
  • Full request/response
  • Timing information
  • Cost breakdown
  • Nested function calls

2. Metrics Dashboard

Track:
  • Total requests
  • Average latency
  • Token usage
  • Cost trends
  • Error rates

3. User Analytics

Analyze:
  • Requests per user
  • Cost per user
  • User engagement
  • Session patterns

4. Model Comparison

Compare:
  • Performance across models
  • Cost efficiency
  • Response quality
  • Latency differences

Self-Hosted Langfuse

Use your own Langfuse instance:

Best Practices

Tag requests by feature, user type, or use case for better analytics.
Include metadata like user tier, pricing plan, or feature flags.
Use scoring to correlate costs with user satisfaction.
Set up alerts for unusual spending patterns.
Use traces to debug issues without reproducing them locally.

Example: Production Chatbot

Resources

Next Steps

OpenAI SDK

Learn about OpenAI SDK integration

Error Handling

Implement proper error handling