Installation and setup
The Langfuse Python SDK installs with pip. Without keys it switches itself off and your code still runs; with keys it sends traces to Langfuse Cloud.
pip install langfuse 4.15.4
Three packages: the SDK, the OpenAI client that model calls go through, and pytest.
pip install "langfuse==4.15.4" openai pytestfrom importlib.metadata import version
print("langfuse", version("langfuse"))
print("opentelemetry-sdk", version("opentelemetry-sdk"))python versions.pyThe SDK brings the OpenTelemetry packages with it. Langfuse builds its tracing on them, which is why a Langfuse trace can also hold steps recorded by other OpenTelemetry tools.
What the SDK does without keys
from langfuse import observe
@observe()
def answer(ticket):
return "Order A17 shipped on 3 March."
print(answer("Where is my order A17?"))python no_keys.py@observe asks the SDK to record the function; lesson 3 explains it. With no LANGFUSE_PUBLIC_KEY set, the client logs an authentication warning and disables itself, and the function still returns its answer. The SDK is designed so that a tracing problem never breaks the application it traces.
With keys set, the default destination is https://cloud.langfuse.com, Langfuse Cloud's EU region. Lesson 2 shows that happening, and points the SDK at a server on your own machine instead.
Langfuse Cloud keys and a free modelOptional
No lesson needs these. To see traces in Langfuse's own interface, create a free Langfuse Cloud project, copy its public and secret keys from the project settings, and set three variables. For a hosted model instead of the local one, any provider with an OpenAI-compatible endpoint works with lesson 7's code; these have a free tier.
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_BASE_URL="https://cloud.langfuse.com"
export GROQ_API_KEY="gsk_..."| Provider | Key | OpenAI-compatible base_url | Model |
|---|---|---|---|
| Groq | Free, console.groq.com/keys | https://api.groq.com/openai/v1 | openai/gpt-oss-120b |
| Gemini | Free, aistudio.google.com/apikey | https://generativelanguage.googleapis.com/v1beta/openai/ | gemini-2.5-flash |
| OpenRouter | Free models end in :free, openrouter.ai/keys | https://openrouter.ai/api/v1 | google/gemma-4-31b-it:free |
Other Langfuse Cloud regions have their own address, such as https://us.cloud.langfuse.com; a self-hosted server has whatever address you gave it.
- Run
pip show langfuseand findopentelemetry-sdkin itsRequiresline. - Set
LANGFUSE_PUBLIC_KEYto any value, leave the secret key unset, and runno_keys.pyagain. Which key does the warning name now?
Little by little, you're building something great.