Skip to main content

Langfuse integration

Langfuse is an LLM observability platform for traces, generations, scores and prompts. With this integration every request through the gateway becomes a Langfuse generation with its input, output, usage, cost, latency, model and metadata, so you can debug conversations and track quality per key, team or feature in Langfuse's own interface.

A real-world scenario​

A product team wants to review a sample of real conversations every week to spot bad answers. They add the Langfuse callback from the Admin UI, and their application puts the conversation id in each request's metadata.trace_id. In Langfuse the team opens a trace and sees every turn of that conversation as a generation with the prompt, the answer, the tokens and the cost, scores the bad ones, and never touches the application or the gateway config.

Turn it on from the Admin UI​

  1. Sign in as a proxy admin and open Settings, then Logging & Alerts. Click Add Callback.
  2. Pick Langfuse in the Callback dropdown and fill in Public Key, Secret Key, Host URL (leave it empty for Langfuse Cloud) and, if you want, Tracing Environment.
  3. Click Add Callback. The table shows a langfuse row with the badge Success.
  4. Open the row's actions menu and click Test, then look for the test generation in the Langfuse project.

Turn it on in the config file​

spanway_settings:
success_callback: ["langfuse"]
failure_callback: ["langfuse"]
VariablePurpose
LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEYProject credentials.
LANGFUSE_HOSTLangfuse URL. Defaults to Langfuse Cloud.
LANGFUSE_TRACING_ENVIRONMENTEnvironment label on traces, such as production.
LANGFUSE_FLUSH_INTERVALSeconds between batch flushes.
LANGFUSE_DEBUGVerbose integration logging.
LANGFUSE_SAMPLE_RATEShare of traces sent, from 0.0 to 1.0. Default 1.0, every trace. Lower it to cut Langfuse cost on high traffic, at the price of missing some requests.
LANGFUSE_TIMEOUTSeconds each export and API call may take. Default 20.
LANGFUSE_MAX_RETRIESHow many times a failed export is sent again. Default 3.
LANGFUSE_FLUSH_ATHow many events are sent in one batch. Default 512.
LANGFUSE_RELEASERelease label on traces. Default is the commit id your CI or deploy platform sets, when it sets one.
LANGFUSE_BASE_URLUsed for the Langfuse URL when LANGFUSE_HOST is unset.
LANGFUSE_OTEL_HOSTHost for the langfuse_otel callback, when it differs from LANGFUSE_HOST.
LANGFUSE_PROMPT_CACHE_DEFAULT_TTL_SECONDSSeconds a managed prompt fetched from Langfuse is cached. Default 60.

Use langfuse_otel instead of langfuse to send traces over OpenTelemetry to Langfuse's OTLP endpoint. Check the connection with GET /health/services?service=langfuse, which sends a mock request and answers Mock LLM request made - check langfuse..

Trace fields from request metadata​

curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [{"role": "user", "content": "Summarize this ticket"}],
"metadata": {
"generation_name": "ticket-summary",
"trace_id": "ticket-4411",
"session_id": "agent-session-9",
"tags": ["support", "summaries"],
"version": "2026-10-14"
}
}'

Expected result: within the flush interval, Langfuse shows a trace ticket-4411 in session agent-session-9 with a generation named ticket-summary, tagged support and summaries, carrying the model, tokens, cost, and the gateway's key alias, team and user in its metadata.

generation_name names the generation, trace_id groups generations into one trace, session_id groups traces into a session, tags and version are stored on the trace, and the request's user field becomes the Langfuse user. The calling key alias, team and user from the gateway are added as metadata automatically.

Per-team projects​

Attach Langfuse credentials to a team with a team callback, and its keys log to that project. See team logging. A client can also pass langfuse_public_key, langfuse_secret_key and langfuse_host in metadata for one request.

Prompts from Langfuse​

With prompt_integration: langfuse in a prompt definition, the gateway fetches prompt templates from Langfuse prompt management and renders them for requests that send a prompt_id. See prompt management.

Redacting content​

Set spanway_settings.turn_off_message_logging: true to send usage and cost without inputs and outputs. The Langfuse SDK itself can be routed through the gateway with the Langfuse pass-through.

Errors​

StatusWhereMeaningFix
Nothing appears in LangfuseLangfuse projectThe keys belong to another project, or the host is wrong, or the batch has not flushed yet.Check LANGFUSE_HOST, wait for LANGFUSE_FLUSH_INTERVAL, and look for Langfuse Layer Error in the gateway log.
400 naming Host URL and Secret KeySaving the callback in the Admin UIThe host changed while the stored secret was kept.Retype the secret key with the new host.
403 naming scoped_integrationsTeam callbackPer team Langfuse projects need the license feature.Use the gateway wide callback, or add the feature.
Generations show no input or outputLangfuseturn_off_message_logging is on, or the request was under zero data retention.That is by design. See what Spanway stores.

Logs​

LevelLineMeaning
ERRORLangfuse Layer Error - <traceback>Langfuse rejected a generation. The traceback holds Langfuse's answer, usually an authentication failure.
WARNINGOverwriting Langfuse <field> from request headerA request header set a trace field that the metadata also set. The header won. Normal.
ERROR[Non-blocking] Langfuse Logger: Invalid prompt format. No prompt logged to LangfuseThe prompt could not be rendered for Langfuse. The generation was still sent without it.