{"record":{"id":"8e224017c6c0ecf0","repo":"BerriAI/litellm","slug":"max-langfuse-clients-reached-litellm-initialized","errorCode":null,"errorMessage":"Max langfuse clients reached: {litellm.initialized_langfuse_clients} is greater than {MAX_LANGFUSE_INITIALIZED_CLIENTS}","messagePattern":"Max langfuse clients reached: (.+?) is greater than (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/langfuse/langfuse.py","lineNumber":216,"sourceCode":"                host=self.upstream_langfuse_host,\n                release=self.upstream_langfuse_release,\n                debug=(upstream_langfuse_debug if upstream_langfuse_debug is not None else False),\n            )\n        else:\n            self.upstream_langfuse = None\n\n    def safe_init_langfuse_client(self, parameters: dict) -> Langfuse:\n        \"\"\"\n        Safely init a langfuse client if the number of initialized clients is less than the max\n\n        Note:\n            - Langfuse initializes 1 thread everytime a client is initialized.\n            - We've had an incident in the past where we reached 100% cpu utilization because Langfuse was initialized several times.\n        \"\"\"\n        from langfuse import Langfuse\n\n        if litellm.initialized_langfuse_clients >= MAX_LANGFUSE_INITIALIZED_CLIENTS:\n            raise Exception(\n                f\"Max langfuse clients reached: {litellm.initialized_langfuse_clients} is greater than {MAX_LANGFUSE_INITIALIZED_CLIENTS}\"\n            )\n        langfuse_client: Final = Langfuse(**parameters)\n        litellm.initialized_langfuse_clients += 1\n        verbose_logger.debug(\"Created langfuse client number %s\", litellm.initialized_langfuse_clients)\n        return langfuse_client\n\n    @staticmethod\n    def add_metadata_from_header(litellm_params: dict, metadata: dict) -> dict:\n        \"\"\"\n        Adds metadata from proxy request headers to Langfuse logging if keys start with \"langfuse_\"\n        and overwrites litellm_params.metadata if already included.\n\n        For example if you want to append your trace to an existing `trace_id` via header, send\n        `headers: { ..., langfuse_existing_trace_id: your-existing-trace-id }` via proxy request.\n        \"\"\"\n        if litellm_params is None:\n            return metadata","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/langfuse/langfuse.py#L198-L234","documentation":"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.","triggerScenarios":"Too many distinct Langfuse credential sets create clients beyond MAX_LANGFUSE_INITIALIZED_CLIENTS.","commonSituations":"Per-virtual-key Langfuse credentials multiplying clients in a busy proxy.","solutions":["Reuse a single Langfuse client configuration instead of creating many distinct ones.","Restart the proxy to clear initialized clients if configurations have changed."],"exampleFix":"# configure one global langfuse credential pair instead of per-key clients","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}