BerriAI/litellm · error · Exception
Max langfuse clients reached
Error message
Max langfuse clients reached: {litellm.initialized_langfuse_clients} is greater than {MAX_LANGFUSE_INITIALIZED_CLIENTS} What it means
safe_init_langfuse_client refused to create another Langfuse client because the count of initialized clients already meets MAX_LANGFUSE_INITIALIZED_CLIENTS — a guard against unbounded thread growth from repeated client creation.
Solutions
- Reuse a single Langfuse client configuration instead of creating many distinct ones.
- Restart the proxy to clear initialized clients if configurations have changed.
Example fix
# configure one global langfuse credential pair instead of per-key clients
Defensive patterns
Strategy: validation
When it happens
Trigger: Too many distinct Langfuse credential sets create clients beyond MAX_LANGFUSE_INITIALIZED_CLIENTS.
Common situations: Per-virtual-key Langfuse credentials multiplying clients in a busy proxy.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/8e224017c6c0ecf0.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/langfuse/langfuse.py:216
host=self.upstream_langfuse_host,
release=self.upstream_langfuse_release,
debug=(upstream_langfuse_debug if upstream_langfuse_debug is not None else False),
)
else:
self.upstream_langfuse = None
def safe_init_langfuse_client(self, parameters: dict) -> Langfuse:
"""
Safely init a langfuse client if the number of initialized clients is less than the max
Note:
- Langfuse initializes 1 thread everytime a client is initialized.
- We've had an incident in the past where we reached 100% cpu utilization because Langfuse was initialized several times.
"""
from langfuse import Langfuse
if litellm.initialized_langfuse_clients >= MAX_LANGFUSE_INITIALIZED_CLIENTS:
raise Exception(
f"Max langfuse clients reached: {litellm.initialized_langfuse_clients} is greater than {MAX_LANGFUSE_INITIALIZED_CLIENTS}"
)
langfuse_client: Final = Langfuse(**parameters)
litellm.initialized_langfuse_clients += 1
verbose_logger.debug("Created langfuse client number %s", litellm.initialized_langfuse_clients)
return langfuse_client
@staticmethod
def add_metadata_from_header(litellm_params: dict, metadata: dict) -> dict:
"""
Adds metadata from proxy request headers to Langfuse logging if keys start with "langfuse_"
and overwrites litellm_params.metadata if already included.
For example if you want to append your trace to an existing `trace_id` via header, send
`headers: { ..., langfuse_existing_trace_id: your-existing-trace-id }` via proxy request.
"""
if litellm_params is None:
return metadataView on GitHub (pinned to 77b7c6c40c)