{"record":{"id":"ac7d710b7a01dac0","repo":"BerriAI/litellm","slug":"posthog-api-key-is-not-set-set-posthog-api-key","errorCode":null,"errorMessage":"POSTHOG_API_KEY is not set, set 'POSTHOG_API_KEY=<>'","messagePattern":"POSTHOG_API_KEY is not set, set 'POSTHOG_API_KEY=<>'","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/posthog.py","lineNumber":55,"sourceCode":"class PostHogLogger(CustomBatchLogger):\n    def __init__(self, **kwargs):\n        \"\"\"\n        Initializes the PostHog logger, checks if the correct env variables are set\n\n        Required environment variables:\n        `POSTHOG_API_KEY` - your PostHog API key\n        `POSTHOG_API_URL` - your PostHog API URL (defaults to https://app.posthog.com)\n        \"\"\"\n        try:\n            verbose_logger.debug(\"PostHog: in init posthog logger\")\n\n            self.is_mock_mode = should_use_posthog_mock()\n            if self.is_mock_mode:\n                create_mock_posthog_client()\n                verbose_logger.debug(\"[POSTHOG MOCK] PostHog logger initialized in mock mode\")\n\n            if os.getenv(\"POSTHOG_API_KEY\", None) is None:\n                raise Exception(\"POSTHOG_API_KEY is not set, set 'POSTHOG_API_KEY=<>'\")\n\n            self.async_client = get_async_httpx_client(llm_provider=httpxSpecialProvider.LoggingCallback)\n            self.sync_client = _get_httpx_client()\n\n            self.POSTHOG_API_KEY = os.getenv(\"POSTHOG_API_KEY\")\n            posthog_api_url: Final = os.getenv(\"POSTHOG_API_URL\", \"https://us.i.posthog.com\")\n            self.posthog_host = posthog_api_url.rstrip(\"/\")\n            self.capture_url = f\"{self.posthog_host}/batch/\"\n\n            self._async_initialized = False\n            self.flush_lock = None\n            self.log_queue = []\n\n            # Register cleanup handler to flush internal queue on exit\n            atexit.register(self._flush_on_exit)\n\n            super().__init__(**kwargs, flush_lock=None, batch_size=POSTHOG_MAX_BATCH_SIZE)\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/posthog.py#L37-L73","documentation":"Error \"POSTHOG_API_KEY is not set, set 'POSTHOG_API_KEY=<>'\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/integrations/posthog.py:55 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set POSTHOG_API_KEY in the environment."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}