BerriAI/litellm · warning · Exception
PostHog credentials not found in kwargs
Error message
PostHog credentials not found in kwargs
What it means
Inside log_success_event, PostHog credentials are resolved per request from standard_callback_dynamic_params (posthog_api_key / posthog_api_url) falling back to the instance defaults captured at init; if the final (api_key, api_url) pair contains None this Exception is raised. In stock deployments it is nearly unreachable — init already refuses to start without POSTHOG_API_KEY — and the enclosing try/except swallows it into a verbose_logger.exception, so the LLM call is never affected; you only see it in logs.
Solutions
- Confirm POSTHOG_API_KEY is set in the running process and restart so __init__ captures it
- If forwarding per-request dynamic params, send real posthog_api_key / posthog_api_url values rather than explicit None
- Audit any subclass or patch of PostHogLogger so instance attributes survive initialization
Defensive patterns
Strategy: validation
Validate before calling
logger = PostHogLogger()
if not getattr(logger, 'POSTHOG_API_KEY', None) or not getattr(logger, 'posthog_host', None):
raise RuntimeError('PostHog credentials missing on logger instance') Prevention
- Do not subclass/patch PostHogLogger in ways that drop instance credential attributes
- If forwarding standard_callback_dynamic_params, always include real values or omit the keys
- Watch verbose logs: this error is only ever logged, never raised to callers
When it happens
Trigger: A PostHogLogger subclass or patched instance whose POSTHOG_API_KEY / posthog_host attributes were deleted or never assigned; passing standard_callback_dynamic_params that explicitly set posthog_api_key=None while instance defaults are also missing; test fixtures mutating the logger.
Common situations: Custom subclasses overriding __init__ without calling super(); unit tests that monkeypatch credential attributes to None; almost never seen in normal proxy/SDK usage.
Related errors
- POSTHOG_API_KEY is not set, set 'POSTHOG_API_KEY=<>'
- Response from PostHog API status_code
- API key is required for OpenAI image variations
- API key is required for Topaz image variations
- 'api_key' is required in litellm_params for WXO agents
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/69ed1dbee632952d.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/posthog.py:84
self.flush_lock = None
self.log_queue = []
# Register cleanup handler to flush internal queue on exit
atexit.register(self._flush_on_exit)
super().__init__(**kwargs, flush_lock=None, batch_size=POSTHOG_MAX_BATCH_SIZE)
except Exception as e:
verbose_logger.exception("PostHog: Got exception on init PostHog client %s", e)
raise e
def log_success_event(self, kwargs, response_obj, start_time, end_time):
try:
verbose_logger.debug("PostHog: Sync logging - Enters logging function for model %s", kwargs)
api_key, api_url = self._get_credentials_for_request(kwargs)
if api_key is None or api_url is None:
raise Exception("PostHog credentials not found in kwargs")
event_payload: Final = self.create_posthog_event_payload(kwargs)
headers: Final = {
"Content-Type": "application/json",
}
payload: Final = self._create_posthog_payload([event_payload], api_key)
capture_url: Final = f"{api_url.rstrip('/')}/batch/"
response: Final = self.sync_client.post(
url=capture_url,
content=safe_dumps(payload),
headers=headers,
)
response.raise_for_status()
if response.status_code != 200:
raise Exception(f"Response from PostHog API status_code: {response.status_code}, text: {response.text}")View on GitHub (pinned to 77b7c6c40c)