integrations/eval/Langfuse
LF

Langfuse + AIgateway

Open-source LLM observability — trace every AIgateway call into Langfuse with one wrapper.

Langfuse traces LLM calls into a self-hosted or cloud observability layer. Its OpenAI wrapper handles base URLs natively, so AIgateway calls show up in Langfuse traces with cost, latency, and token attribution preserved.

Langfuse homepage →
Setup

Three steps or fewer.

STEP 01

Install both clients

pip install langfuse openai
STEP 02

Wrap the OpenAI client

langfuse.openai.OpenAI is a drop-in replacement that traces every call. Configure it with AIgateway's base URL + key; Langfuse traces still write to your Langfuse host with full request/response capture.

from langfuse.openai import OpenAI  # not "from openai"

client = OpenAI(
    base_url="https://api.aigateway.sh/v1",
    api_key="sk-aig-...",
)

# Every call below is traced to Langfuse
r = client.chat.completions.create(
    model="anthropic/claude-opus-4.7",
    messages=[{"role": "user", "content": "hi"}],
)
STEP 03

Set Langfuse env vars

Standard Langfuse setup — host, public key, secret. Your AIgateway calls appear in the Langfuse UI with model name, cost, tokens, latency.

export LANGFUSE_HOST="https://cloud.langfuse.com"
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
Notes
  • Langfuse and AIgateway are complementary: Langfuse owns the trace store + UI; AIgateway owns the routing, caching, and billing. Use both.
  • For PII redaction before traces leave your infrastructure, configure Langfuse's mask_input/mask_output hooks.
  • AIgateway's own observability (request logs, cost-by-tag) is in your dashboard — Langfuse adds the conversation/session/score layer on top.
More integrations

Same key. Every other tool.