Get Started with Tracing

This quickstart helps you to ingest your first trace in Langfuse.

Get API keys

  1. Create Langfuse account or self-host Langfuse.
  2. Create new API credentials in the project settings.

Ingest your first trace

Use the drop-in replacement for the OpenAI Python SDK to get full observability.

pip install langfuse

Add you Langfuse credentials as environment variables.

.env
LANGFUSE_SECRET_KEY = "sk-lf-..."
LANGFUSE_PUBLIC_KEY = "pk-lf-..."
LANGFUSE_HOST = "https://cloud.langfuse.com" # πŸ‡ͺπŸ‡Ί EU region
# LANGFUSE_HOST = "https://us.cloud.langfuse.com" # πŸ‡ΊπŸ‡Έ US region

Change the import to use the OpenAI drop-in replacement.

from langfuse.openai import openai

Use the OpenAI SDK as usual.

completion = openai.chat.completions.create(
  name="test-chat",
  model="gpt-4o",
  messages=[
      {"role": "system", "content": "You are a very accurate calculator. You output only the result of the calculation."},
      {"role": "user", "content": "1 + 1 = "}],
  metadata={"someMetadataKey": "someValue"},
)

See your trace in Langfuse

After running your application, visit the Langfuse interface to view the trace you just created. (Example LangGraph trace in Langfuse)

Core Features