{"record":{"id":"fd626226e187fd37","repo":"BerriAI/litellm","slug":"external-customer-id-is-not-set-charge-by-charge","errorCode":null,"errorMessage":"External Customer ID is not set. Charge_by={charge_by}. User_id={user_id}. End_user_id={end_user_id}. Team_id={team_id}","messagePattern":"External Customer ID is not set\\. Charge_by=(.+?)\\. User_id=(.+?)\\. End_user_id=(.+?)\\. Team_id=(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/lago.py","lineNumber":107,"sourceCode":"        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\"),\n                \"properties\": {\"model\": model, \"response_cost\": cost, **usage},\n            }\n        }\n\n        verbose_logger.debug(\"\\x1b[91mLogged Lago Object:\\n%s\\x1b[0m\\n\", returned_val)\n        return returned_val\n\n    def log_success_event(self, kwargs, response_obj, start_time, end_time):\n        _url = os.getenv(\"LAGO_API_BASE\")\n        assert _url is not None and isinstance(_url, str), (","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/lago.py#L89-L125","documentation":"Lago charge lookup resolved no external_customer_id for the configured charge_by mode (all relevant ids shown in the message), meaning the request cannot be attributed to any Lago customer and would be unbilled.","triggerScenarios":"A billable request reaches the Lago logger without the external customer id required by charge_by.","commonSituations":"Requests missing user/end_user metadata, or charge_by pointing at a field callers never send.","solutions":["Provide the identifier matching the configured charge_by mode (user_id, end_user_id, or team_id) in the request metadata."],"exampleFix":"litellm.completion(model='gpt-4', messages=msgs, user='customer-123')","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"}