{"record":{"id":"e51f42afb674087e","repo":"BerriAI/litellm","slug":"invalid-lago-api-charge-by-set","errorCode":null,"errorMessage":"invalid LAGO_API_CHARGE_BY set","messagePattern":"invalid LAGO_API_CHARGE_BY set","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/lago.py","lineNumber":97,"sourceCode":"        litellm_params: Final = kwargs.get(\"litellm_params\", {}) or {}\n        proxy_server_request: Final = litellm_params.get(\"proxy_server_request\") or {}\n        end_user_id: Final = proxy_server_request.get(\"body\", {}).get(\"user\", None)\n        user_id: Final = litellm_params[\"metadata\"].get(\"user_api_key_user_id\", None)\n        team_id: Final = litellm_params[\"metadata\"].get(\"user_api_key_team_id\", None)\n        litellm_params[\"metadata\"].get(\"user_api_key_org_id\", None)\n\n        charge_by: Literal[\"end_user_id\", \"team_id\", \"user_id\"] = \"end_user_id\"\n        external_customer_id: str | None = None\n\n        if os.getenv(\"LAGO_API_CHARGE_BY\", None) is not None and isinstance(os.environ[\"LAGO_API_CHARGE_BY\"], str):\n            if os.environ[\"LAGO_API_CHARGE_BY\"] in [\n                \"end_user_id\",\n                \"user_id\",\n                \"team_id\",\n            ]:\n                charge_by = os.environ[\"LAGO_API_CHARGE_BY\"]\n            else:\n                raise Exception(\"invalid LAGO_API_CHARGE_BY set\")\n\n        if charge_by == \"end_user_id\":\n            external_customer_id = end_user_id\n        elif charge_by == \"team_id\":\n            external_customer_id = team_id\n        elif charge_by == \"user_id\":\n            external_customer_id = user_id\n\n        if external_customer_id is None:\n            raise Exception(\n                f\"External Customer ID is not set. Charge_by={charge_by}. User_id={user_id}. End_user_id={end_user_id}. Team_id={team_id}\"\n            )\n\n        returned_val: Final = {\n            \"event\": {\n                \"transaction_id\": str(uuid.uuid4()),\n                \"external_subscription_id\": external_customer_id,\n                \"code\": os.getenv(\"LAGO_API_EVENT_CODE\"),","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/lago.py#L79-L115","documentation":"Lago billing callback guard: the LAGO_API_CHARGE_BY setting did not match any of the allowed literals ('end_user_id', 'team_id', 'user_id'), so the callback cannot decide which identifier to bill against in Lago.","triggerScenarios":"LAGO_API_CHARGE_BY is set to a value the integration does not support.","commonSituations":"Typo in the env var value or using a charge mode this integration version does not implement.","solutions":["Set LAGO_API_CHARGE_BY to a supported value such as 'user_id', 'end_user_id', or 'team_id'."],"exampleFix":"export LAGO_API_CHARGE_BY=user_id","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"}