lf-cli
An open-source CLI for Langfuseยฎ
A powerful command-line interface for querying and analyzing Langfuse LLM observability data. Built with Ruby and designed for developers who prefer working in the terminal.
Disclaimer
This is an unofficial, community-maintained CLI tool for Langfuse.
This project is not affiliated with, endorsed by, or sponsored by Langfuse GmbH. Langfuseยฎ is a registered trademark of Langfuse GmbH.
Features
- ๐ Query Traces - List and filter traces by name, user, session, tags, or time range
- ๐ Analyze Sessions - View complete session details with all associated traces
- ๐ฏ Inspect Observations - List LLM generations, spans, and events
- ๐ Query Metrics - Run analytics queries with custom aggregations and dimensions
- โญ View Scores - Access quality scores and evaluation metrics
- ๐จ Multiple Output Formats - Table, JSON, CSV, or Markdown
- ๐ Multi-Profile Support - Manage credentials for dev, staging, and production
- ๐ Interactive Setup - Browser-integrated credential configuration
- โก Type-Safe - Built with Sorbet Runtime for reliability
Installation
Install from RubyGems
gem install lf-cliInstall from Source
git clone https://github.com/vicentereig/lf-cli.git
cd lf-cli
bundle install
bundle exec rake installRequirements
- Ruby >= 2.7.0
- Langfuse account (cloud or self-hosted)
Quick Start
1. Configure Credentials
Run the interactive setup wizard:
lf config setupThis will:
- Ask for your Langfuse project name
- Open your browser to the Langfuse settings page
- Prompt you to enter your API keys
- Test the connection
- Save credentials securely to
~/.langfuse/config.yml
2. Start Querying
# List recent traces
lf traces list --from "1 hour ago" --limit 20
# Get specific trace details
lf traces get trace_abc123
# Query metrics
lf metrics query --view traces --measure count --aggregation countUsage
Configuration Commands
# Interactive setup (recommended)
lf config setup
# Set credentials manually
lf config set production \
--public-key pk_... \
--secret-key sk_...
# Show current configuration (keys are masked)
lf config show
# List all profiles
lf config listTrace Commands
# List all traces
lf traces list
# Filter traces by various criteria
lf traces list \
--name "chat_completion" \
--user-id user_123 \
--from "2024-01-01" \
--limit 50
# Get detailed trace information
lf traces get trace_abc123
# Export to CSV
lf traces list --format csv --output traces.csvSession Commands
# List all sessions
lf sessions list
# Show specific session with details
lf sessions show session_xyz789Observation Commands
# List all observations
lf observations list
# Filter by type
lf observations list --type generation
# Filter by trace
lf observations list --trace-id trace_abc123Score Commands
# List all scores
lf scores list
# Filter by name
lf scores list --name quality
# Get specific score
lf scores get score_123Metrics Commands
# Count total traces
lf metrics query \
--view traces \
--measure count \
--aggregation count
# Average latency by trace name
lf metrics query \
--view observations \
--measure latency \
--aggregation avg \
--dimensions name
# Token usage with time range
lf metrics query \
--view observations \
--measure tokens \
--aggregation sum \
--from "2024-01-01" \
--to "2024-12-31"
# P95 latency grouped by model
lf metrics query \
--view observations \
--measure latency \
--aggregation p95 \
--dimensions modelGlobal Options
All commands support these global options:
-f, --format [table|json|csv|markdown] # Output format (default: table)
-o, --output FILE # Save output to file
-l, --limit N # Limit number of results
-P, --profile PROFILE # Use specific profile
--from TIMESTAMP # Start of time range (ISO 8601 or relative)
--to TIMESTAMP # End of time range
-v, --verbose # Verbose outputTime Range Examples
Supports both ISO 8601 and natural language:
# ISO 8601
--from "2024-01-01T00:00:00Z" --to "2024-12-31T23:59:59Z"
# Natural language (requires 'chronic' gem)
--from "1 hour ago"
--from "yesterday"
--from "last monday"Output Formats
Table (Default)
lf traces list --format tableOutputs a formatted ASCII table - great for terminal viewing.
JSON
lf traces list --format jsonPerfect for piping to jq or other tools:
lf traces list --format json | jq '.[] | select(.name == "chat")'CSV
lf traces list --format csv --output data.csvImport into spreadsheets or data analysis tools.
Markdown
lf traces list --format markdownGreat for documentation and reports.
Configuration
Configuration File
Credentials are stored in ~/.langfuse/config.yml:
profiles:
default:
host: https://cloud.langfuse.com
public_key: pk_...
secret_key: sk_...
output_format: table
page_limit: 50
production:
host: https://cloud.langfuse.com
public_key: pk_prod_...
secret_key: sk_prod_...The file is created with 0600 permissions (owner read/write only) for security.
Environment Variables
You can also use environment variables:
export LANGFUSE_PUBLIC_KEY="pk_..."
export LANGFUSE_SECRET_KEY="sk_..."
export LANGFUSE_HOST="https://cloud.langfuse.com"
export LANGFUSE_PROFILE="production"Priority Order
Configuration is loaded in this order (highest to lowest priority):
- Command-line flags (
--public-key,--secret-key, etc.) - Environment variables (
LANGFUSE_PUBLIC_KEY, etc.) - Config file (
~/.langfuse/config.yml) - Defaults
Development
Setup
git clone https://github.com/vicentereig/lf-cli.git
cd lf-cli
bundle installRun Tests
# Run all tests
bundle exec rspec
# Run with documentation format
bundle exec rspec --format documentation
# Run specific test file
bundle exec rspec spec/unit/commands/traces_spec.rbRun CLI Locally
./bin/lf help
./bin/lf config setupCode Structure
lib/langfuse/cli/
โโโ client.rb # API client with Faraday
โโโ config.rb # Configuration management
โโโ types.rb # Sorbet type definitions
โโโ formatters/ # Output formatters
โ โโโ table_formatter.rb
โ โโโ csv_formatter.rb
โ โโโ markdown_formatter.rb
โโโ commands/ # Command modules
โโโ traces.rb
โโโ sessions.rb
โโโ observations.rb
โโโ scores.rb
โโโ metrics.rb
โโโ config.rb
API Reference
This CLI uses the Langfuse Public API:
- API Documentation: https://api.reference.langfuse.com/
- OpenAPI Spec: https://cloud.langfuse.com/generated/api/openapi.yml
Valid enum values for metrics query:
-
View:
traces,observations,scores-numeric,scores-categorical -
Measure:
count,latency,value,tokens,cost -
Aggregation:
count,sum,avg,p50,p95,p99,min,max,histogram -
Granularity:
minute,hour,day,week,month,auto
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Thor CLI framework
- Uses Faraday for HTTP requests
- Type safety with Sorbet Runtime
- Inspired by the excellent Langfuse observability platform
Support
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Questions: GitHub Discussions
- ๐ง Email: hey@vicente.services
Roadmap
- Add support for filtering by metadata
- Implement trace export with full observation trees
- Add watch mode for real-time trace monitoring
- Support for creating/updating scores via CLI
- Integration with other observability tools
Note: This is a community project. For official Langfuse support and documentation, visit langfuse.com.