Langfuse Cheatsheet
Langfuse is an open-source LLM observability platform offering trace/span tracking, token usage statistics, scoring, prompt version management, and dataset management. Supports self-hosting and cloud with deep LangChain and OpenAI integration.
Updated: 2026-07-20·14 commands
Quick Start
``bash
pip install langfuse
export LANGFUSE_PUBLIC_KEY=pk-lf-xxx
export LANGFUSE_SECRET_KEY=sk-lf-xxx
export LANGFUSE_HOST=https://cloud.langfuse.com
``
Core Concepts
Traces represent end-to-end LLM operations. Spans break traces into sub-steps. Generations track LLM calls with prompt/completion tokens. Scores enable human or automated evaluation. Datasets hold test cases for eval runs.
Startup & Modes(12)
| Command | Level | ||
|---|---|---|---|
langfuse --helpShow Langfuse CLI help | Basic | langfuse --help | |
pip install langfuseInstall Langfuse Python SDK | Basic | pip install langfuse | |
git clone langfuseClone Langfuse source | Basic | git clone https://github.com/langfuse/langfuse.git | |
export LANGFUSE_PUBLIC_KEYSet Langfuse public key | Basic | export LANGFUSE_PUBLIC_KEY=pk-lf-xxx | |
export LANGFUSE_SECRET_KEYSet Langfuse secret key | Basic | export LANGFUSE_SECRET_KEY=sk-lf-xxx | |
export LANGFUSE_HOSTSet Langfuse server URL | Basic | export LANGFUSE_HOST=http://localhost:3000 | |
langfuse traceCreate a Langfuse trace | Intermediate | python -c 'from langfuse import Langfuse; lf = Langfuse(); trace = lf.trace(name="my-llm-call"); trace.update(output="result")'
| |
langfuse spanCreate a span (sub-step of a trace) | Intermediate | python -c 'from langfuse import Langfuse; lf = Langfuse(); trace = lf.trace(name="pipeline"); span = trace.span(name="llm-call"); span.end()'
| |
langfuse generationTrack LLM generation (with token counting) | Intermediate | python -c 'from langfuse import Langfuse; lf = Langfuse(); lf.generation(name="chat", model="gpt-4", input="Hello", output="Hi", usage={"promptTokens":10,"completionTokens":5})'
| |
langfuse scoreAdd a score to a trace | Expert | python -c 'from langfuse import Langfuse; lf = Langfuse(); lf.score(name="accuracy", value=0.95, trace_id="xxx")'
| |
langfuse promptGet managed prompt template from Langfuse | Intermediate | python -c 'from langfuse import Langfuse; lf = Langfuse(); prompt = lf.get_prompt("my-prompt"); print(prompt.compile(input="value"))'
| |
langfuse datasetCreate or get an evaluation dataset | Expert | python -c 'from langfuse import Langfuse; lf = Langfuse(); dataset = lf.get_dataset("eval-data"); print(len(dataset.items))'
|
ai-server(2)
| Command | Level | ||
|---|---|---|---|
langfuse serverStart Langfuse local server (Docker) | Intermediate | langfuse server | |
docker compose langfuseStart Langfuse with Docker Compose | Intermediate | docker compose -f docker-compose.yml up -d |
FAQ
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-20.