Target:
langfuse-cli(npm) Purpose: Command-line interface wrapping the Langfuse REST API for traces, prompts, datasets, and scores. Optimized for AI agents.
🚀 Quick Start
- Zero-Install Execution: Run
npx langfuse-cli api <resource> <action>. - Dynamic Discovery: Use
npx langfuse-cli api __schemato discover resources dynamically rather than assuming endpoints.
🔧 Configuration
- Credentials Precedence:
--hostflag >LANGFUSE_BASE_URL(standard) >LANGFUSE_HOST> Default cloud URL. - Preferred Setup: Use an
.envfile containingLANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEY, andLANGFUSE_BASE_URL. - Piping Output: Append
--jsonfor jq/script parsing or--curlto preview raw requests.
💡 Best Practices & Patterns
- Agent Provisioning: Instead of hardcoding API knowledge, have agents run
langfuse get-skillto fetch and inject the latest Agent Skill directly into their prompt context. - Schema Patching: The CLI auto-flattens discriminated unions (
oneOf/allOf) viapatch-openapi.ts. Always runlangfuse api <resource> --helpto view the flattened parameter flags. - Security: Always prefer
.envover CLI flags (like--public-key) to prevent leaking credentials in bash history.
🚨 Gotchas / Warnings (Anti-patterns)
- The
--versionFlag Collision: Do NOT use--versionto fetch specific API resource versions (e.g., prompt versions). Commander.js intercepts--versionglobally. Anti-pattern:langfuse api prompts get my-prompt --version 4. Pattern: Use--prompt-version 4instead. - Host Variable Deprecation: Do not rely solely on
LANGFUSE_HOSTin newer setups. Pattern: Migrate toLANGFUSE_BASE_URLas the ecosystem standard. - Raw Union Payloads: Do not pass raw nested discriminated union JSON bodies directly; use the flattened flag structure shown in the CLI help.