BerriAI/litellm · error · Exception
Missing keys={missing_keys} in environment.
Error message
Missing keys={missing_keys} in environment. What it means
Exception raised by the Lago billing integration's environment validation: it requires LAGO_API_KEY, LAGO_API_BASE, and LAGO_API_EVENT_CODE to all be present as environment variables before it will log billing events to Lago. The message lists exactly which keys are missing.
Source
Thrown at litellm/integrations/lago.py:61
LAGO_API_EVENT_CODE,
Optional:
LAGO_API_CHARGE_BY
in the environment
"""
missing_keys: Final = []
if os.getenv("LAGO_API_KEY", None) is None:
missing_keys.append("LAGO_API_KEY")
if os.getenv("LAGO_API_BASE", None) is None:
missing_keys.append("LAGO_API_BASE")
if os.getenv("LAGO_API_EVENT_CODE", None) is None:
missing_keys.append("LAGO_API_EVENT_CODE")
if len(missing_keys) > 0:
raise Exception(f"Missing keys={missing_keys} in environment.")
def _common_logic(self, kwargs: dict, response_obj) -> dict:
response_obj.get("id", kwargs.get("litellm_call_id"))
get_utc_datetime().isoformat()
cost: Final = kwargs.get("response_cost", None)
model: Final = kwargs.get("model")
usage = {}
if (
isinstance(response_obj, litellm.ModelResponse) or isinstance(response_obj, litellm.EmbeddingResponse)
) and hasattr(response_obj, "usage"):
usage = {
"prompt_tokens": response_obj["usage"].get("prompt_tokens", 0),
"completion_tokens": response_obj["usage"].get("completion_tokens", 0),
"total_tokens": response_obj["usage"].get("total_tokens"),
}
litellm_params: Final = kwargs.get("litellm_params", {}) or {}View on GitHub (pinned to 6c2dcb801b)
Solutions
- Set all three vars: LAGO_API_KEY, LAGO_API_BASE, LAGO_API_EVENT_CODE
- For Docker/k8s, ensure the secret/env mapping injects all three into the proxy/SDK process
- If Lago billing is not intended, remove 'lago' from litellm.callbacks
Example fix
# before litellm.callbacks = ['lago'] # env vars unset # after export LAGO_API_KEY=... export LAGO_API_BASE=https://api.getlago.com export LAGO_API_EVENT_CODE=llm-usage litellm.callbacks = ['lago']
Defensive patterns
Strategy: validation
Validate before calling
import os
REQUIRED = ("LAGO_API_KEY", "LAGO_API_BASE", "LAGO_API_EVENT_CODE")
missing = [k for k in REQUIRED if not os.getenv(k)]
if missing:
raise RuntimeError(f"Set required env vars: {missing}") Prevention
- Check required LAGO_* vars at process startup, not at first log event
- Use a config checklist/secrets manifest for deployments
- Remove 'lago' from callbacks when billing is disabled
When it happens
Trigger: Enabling the Lago callback (litellm.callbacks = ['lago']) in a process where one or more of the three LAGO_* env vars are unset. Validation runs at logging time, so the first completion after enabling the callback triggers it.
Common situations: Deploying with the callback enabled but secrets not mounted in the container; .env file not loaded in the runtime; CI/local machine missing the vars while production has them (or vice versa); typo in var names.
Related errors
- invalid LAGO_API_CHARGE_BY set
- External Customer ID is not set. Charge_by={charge_by}. User
- Error: {response.status_code} - {response.text}
- Missing Authorization header
- Invalid bearer token
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/634fc79e6956df8e.
Report an issue: GitHub.