BerriAI/litellm · error · Exception

External Customer ID is not set. Charge_by=

Error message

External Customer ID is not set. Charge_by={charge_by}. User_id={user_id}. End_user_id={end_user_id}. Team_id={team_id}

What it means

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.

Solutions

  1. Provide the identifier matching the configured charge_by mode (user_id, end_user_id, or team_id) in the request metadata.

Example fix

litellm.completion(model='gpt-4', messages=msgs, user='customer-123')
Defensive patterns

Strategy: validation

When it happens

Trigger: A billable request reaches the Lago logger without the external customer id required by charge_by.

Common situations: Requests missing user/end_user metadata, or charge_by pointing at a field callers never send.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/fd626226e187fd37. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/lago.py:107

        if os.getenv("LAGO_API_CHARGE_BY", None) is not None and isinstance(os.environ["LAGO_API_CHARGE_BY"], str):
            if os.environ["LAGO_API_CHARGE_BY"] in [
                "end_user_id",
                "user_id",
                "team_id",
            ]:
                charge_by = os.environ["LAGO_API_CHARGE_BY"]
            else:
                raise Exception("invalid LAGO_API_CHARGE_BY set")

        if charge_by == "end_user_id":
            external_customer_id = end_user_id
        elif charge_by == "team_id":
            external_customer_id = team_id
        elif charge_by == "user_id":
            external_customer_id = user_id

        if external_customer_id is None:
            raise Exception(
                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}"
            )

        returned_val: Final = {
            "event": {
                "transaction_id": str(uuid.uuid4()),
                "external_subscription_id": external_customer_id,
                "code": os.getenv("LAGO_API_EVENT_CODE"),
                "properties": {"model": model, "response_cost": cost, **usage},
            }
        }

        verbose_logger.debug("\x1b[91mLogged Lago Object:\n%s\x1b[0m\n", returned_val)
        return returned_val

    def log_success_event(self, kwargs, response_obj, start_time, end_time):
        _url = os.getenv("LAGO_API_BASE")
        assert _url is not None and isinstance(_url, str), (

View on GitHub (pinned to 77b7c6c40c)