Skip to main content

langfuse-cli (lf)

CI PyPI version Python License: MIT

Observability-first CLI for the Langfuse LLM platform, following gh-ux patterns.

Features: traces, observations, prompts, scores, datasets, experiments, sessions | JSON/table/TSV output | config profiles | system keyring secrets | agent-friendly --json mode

Installation

# With uv (recommended)
uv tool install langfuse-cli

# With pip
pip install langfuse-cli

# With Homebrew
brew install aviadshiber/tap/langfuse-cli

# From source
git clone https://github.com/aviadshiber/langfuse-cli.git && cd langfuse-cli
uv sync && uv run lf --version

Quick Start

# Set credentials (or use config file below)
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_HOST="https://cloud.langfuse.com"  # optional, this is the default

# List recent traces
lf traces list --limit 5 --from 2026-02-01

# List prompts
lf prompts list

# Get JSON output (agent-friendly)
lf --json traces list --limit 5 --from 2026-02-01

Configuration

Resolution Order

Configuration is resolved in this order (first match wins):

  1. CLI flags (--host, --profile)
  2. Environment variables (LANGFUSE_HOST, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY)
  3. Config file (~/.config/langfuse/config.toml)
  4. System keyring (macOS Keychain / Linux Secret Service)
  5. Defaults (host: https://cloud.langfuse.com)

Config File

# ~/.config/langfuse/config.toml

[default]
host = "https://cloud.langfuse.com"
public_key = "pk-lf-..."
# secret_key stored in keyring, NOT in plaintext

[profiles.staging]
host = "https://staging.langfuse.example.com"
public_key = "pk-lf-staging-..."

[defaults]
limit = 50
output = "table"

Secret Storage

Secret keys are stored in the system keyring (service: langfuse-cli):

  • macOS: Keychain (security add-generic-password -s langfuse-cli -a default/secret_key -w <secret>)
  • Linux: Secret Service API (GNOME Keyring / KDE Wallet)
  • Fallback: Environment variables or config file

Environment Variables

Variable Description
LANGFUSE_HOST Langfuse host URL
LANGFUSE_BASEURL Alias for LANGFUSE_HOST (SDK compatibility)
LANGFUSE_PUBLIC_KEY Public API key
LANGFUSE_SECRET_KEY Secret API key
LANGFUSE_PROFILE Config profile name
LANGFUSE_FORCE_TTY Force TTY mode (set to 1)
NO_COLOR Disable color output

Global Options

Global options go before the subcommand:

lf --json traces list --limit 5       # correct
lf --quiet scores summary             # correct
Flag Description
--version, -v Show version and exit
--host URL Override Langfuse host URL
--profile NAME Use named config profile
--json Output as JSON
--fields FIELDS Filter JSON to specific fields (comma-separated, implies --json)
--jq EXPR Filter JSON with jq expression (implies --json)
--quiet, -q Suppress status messages

Commands

Traces

# List traces (use --from to avoid timeouts on large projects)
lf traces list --limit 10 --from 2026-02-01
lf traces list --user-id user-123 --session-id sess-456
lf traces list --tags production,v2 --name chat-completion
lf traces list --metadata tenant=acme --metadata env=prod

# Get a single trace
lf traces get <trace-id>

# Visualize trace hierarchy as a tree
lf traces tree <trace-id>
Flag Type Description
--limit, -l INT Max results (default: 50)
--user-id, -u TEXT Filter by user ID
--session-id, -s TEXT Filter by session ID
--tags TEXT Filter by tags (comma-separated)
--name, -n TEXT Filter by trace name
--from DATETIME Start time filter (ISO 8601)
--to DATETIME End time filter (ISO 8601)
--metadata TEXT Filter by metadata field as KEY=VALUE (repeatable; ANDed)

Prompts

# List all prompts
lf prompts list

# Get a specific prompt
lf prompts get my-prompt
lf prompts get my-prompt --label production
lf prompts get my-prompt --version 3

# Compile a prompt with variables
lf prompts compile my-prompt --var name=Alice --var role=engineer

# Compare two versions
lf prompts diff my-prompt --v1 3 --v2 5

Scores

# List scores
lf scores list --trace-id abc-123
lf scores list --name quality --from 2026-01-01

# Aggregated statistics
lf scores summary
lf scores summary --name quality --from 2026-01-01

Datasets

# List datasets
lf datasets list

# Get dataset with items
lf datasets get my-dataset --limit 10

Experiments

# List runs for a dataset
lf experiments list my-dataset

# Compare two runs
lf experiments compare my-dataset run-baseline run-improved

Sessions

# List sessions
lf sessions list --limit 20 --from 2026-01-01

# Get session details
lf sessions get session-abc-123

Observations

# List observations for a trace
lf observations list --trace-id abc-123

# Filter by type and name
lf observations list --type GENERATION --name llm-call --limit 20

# With time range
lf observations list --trace-id abc-123 --from 2026-01-01 --to 2026-01-31

# Filter by metadata
lf observations list --metadata tenant=acme
Flag Type Description
--limit, -l INT Max results (default: 50)
--trace-id, -t TEXT Filter by trace ID
--type TEXT Filter by type (GENERATION, SPAN, EVENT)
--name, -n TEXT Filter by observation name
--from DATETIME Start time filter (ISO 8601)
--to DATETIME End time filter (ISO 8601)
--metadata TEXT Filter by metadata field as KEY=VALUE (repeatable; ANDed)

Output Modes

Context Format Status Messages
Terminal (TTY) Rich aligned columns with colors Shown
Piped (non-TTY) Tab-separated values Suppressed
--json flag JSON array Suppressed unless error
--quiet flag Normal tables All suppressed
# Rich table (terminal)
lf prompts list

# Tab-separated (piped)
lf traces list --limit 5 --from 2026-02-01 | head

# JSON (agent-friendly)
lf --json traces list --limit 5 --from 2026-02-01

# Filtered JSON fields
lf --fields id,name,userId traces list --limit 5 --from 2026-02-01

# jq expression
lf --jq '.[].name' traces list --limit 5 --from 2026-02-01

Exit Codes

Code Meaning
0 Success
1 Error (API failure, auth, general)
2 Resource not found
3 Cancelled (Ctrl+C)

Architecture

Hybrid SDK + REST approach:

  • REST (httpx): Traces, observations, scores, sessions — full filter control, 60s timeout
  • SDK (langfuse): Prompts (built-in 300s caching), datasets, experiments — complex operations

Troubleshooting

Timeouts on large projects — Use --from to limit the time range:

lf traces list --from 2026-02-01          # fast: scoped query
lf traces list                             # slow: may timeout on large projects

Datetime format — --from/--to accept ISO 8601 without milliseconds or Z suffix:

lf traces list --from 2026-02-16                  # date only
lf traces list --from 2026-02-16T10:30:00         # datetime
lf traces list --from "2026-02-16 10:30:00"       # space separator (quote it)
# NOT supported: 2026-02-16T10:30:00.213Z (ms + Z suffix)

Authentication errors — Verify credentials are set:

echo $LANGFUSE_PUBLIC_KEY   # should show pk-lf-...
echo $LANGFUSE_SECRET_KEY   # should show sk-lf-...
lf --json traces list --limit 1 --from 2026-02-01  # test connectivity

Batch processing — Use --to with the last timestamp to page through results:

# Batch 1
RAW=$(lf --jq '.[-1].timestamp' traces list --limit 50 --from 2026-02-01 2>/dev/null)
CURSOR=$(echo "$RAW" | tr -d '"' | sed 's/\.[0-9]*Z$//')

# Batch 2 (older results)
lf --json traces list --limit 50 --from 2026-02-01 --to "$CURSOR"

Shell Completions

lf supports tab completions for bash, zsh, and fish via Typer's built-in mechanism.

Bash — add to ~/.bashrc:

eval "$(_LF_COMPLETE=bash_source lf)"

Zsh — add to ~/.zshrc:

eval "$(_LF_COMPLETE=zsh_source lf)"

Fish — add to ~/.config/fish/config.fish:

_LF_COMPLETE=fish_source lf | source

After adding, restart your shell or source the config file.

Development

# Setup
git clone https://github.com/aviadshiber/langfuse-cli.git && cd langfuse-cli
uv sync

# Run tests
uv run pytest

# Lint, format & type check
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run mypy src/

# Run locally
uv run lf --version

See CONTRIBUTING.md for detailed development guidelines.

License

MIT

Metadata

Release files for langfuse-cli 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langfuse-cli 0.1.6
File Size Uploaded Provenance
langfuse_cli-0.1.6.tar.gz 147.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langfuse-cli 0.1.6
File Interpreter ABI Platform
langfuse_cli-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 175.0 kB

Release files / langfuse_cli-0.1.6.tar.gz

Download URL langfuse_cli-0.1.6.tar.gz
Size 147.4 kB
Tags Source
SHA-256 checksum
How to use checksums
35d612aaf1c959ff328a94544bfa85be188f76841e9eea00550be9c3de0a15ca
BLAKE2b-256 checksum
How to use checksums
1802491b20ff75aaaa0b0b568b26d85d9d25f8db905ede263703e085e8623736
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

Release files / langfuse_cli-0.1.6-py3-none-any.whl

Download URL langfuse_cli-0.1.6-py3-none-any.whl
Size 27.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6c245abbe2b24205e740c5d3a7559fc791837dabebd82c2cc598e341e053db7
BLAKE2b-256 checksum
How to use checksums
b247a0d5a061761ad7e7a20a6d2298dc4434c712246de1f2f6e872d3902a52e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

Security for langfuse-cli 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langfuse_cli-0.1.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page