LangfuseHostNotConfiguredError
langfuse.errors.LangfuseHostNotConfiguredError
Stack trace
langfuse.errors.LangfuseHostNotConfiguredError: Langfuse host URL not configured. Please set LANGFUSE_HOST environment variable for self-hosted usage.
File "/app/main.py", line 12, in <module>
client = LangfuseClient()
File "/app/langfuse/client.py", line 45, in __init__
raise LangfuseHostNotConfiguredError("Langfuse host URL not configured.") Why it happens
Langfuse requires a host URL to connect to the self-hosted backend. If the LANGFUSE_HOST environment variable or equivalent config is missing, the client cannot initialize and throws this error.
Detection
Check for the presence of LANGFUSE_HOST in your environment variables before client initialization, or catch LangfuseHostNotConfiguredError to log missing config early.
Causes & fixes
LANGFUSE_HOST environment variable is not set in the deployment environment
Set the LANGFUSE_HOST environment variable to your self-hosted Langfuse backend URL before starting your application.
Application code does not read or pass the host URL to Langfuse client constructor
Ensure your code reads LANGFUSE_HOST from os.environ and passes it explicitly to LangfuseClient(host=...) if required.
Misconfigured environment where LANGFUSE_HOST is set but empty or malformed
Validate the LANGFUSE_HOST value is a well-formed URL and non-empty string before client initialization.
Code: broken vs fixed
from langfuse import LangfuseClient
client = LangfuseClient() # Raises LangfuseHostNotConfiguredError if LANGFUSE_HOST not set
print("Client initialized") import os
from langfuse import LangfuseClient
os.environ["LANGFUSE_HOST"] = "https://your-self-hosted-langfuse.example.com" # Set your host URL here
client = LangfuseClient() # Now initializes successfully
print("Client initialized") Workaround
Wrap LangfuseClient initialization in try/except LangfuseHostNotConfiguredError and provide a fallback or prompt to set LANGFUSE_HOST dynamically.
Prevention
Always set and validate LANGFUSE_HOST environment variable in deployment pipelines and local environments before starting your Langfuse client.