BerriAI/litellm · error · ValueError

Cannot parse IAM endpoint from URL: missing host or username

Error message

Cannot parse IAM endpoint from URL: missing host or username

What it means

Raised by parse_iam_endpoint_from_url when the Postgres connection URL parses without a hostname or username, so an IAM endpoint (host + port for cloud-sql IAM auth) cannot be derived from it. This fires while wiring up reader-replica IAM refresh from a DATABASE_URL-style string; the URL is malformed for that purpose (missing host or user component).

Source

Thrown at litellm/proxy/db/prisma_client.py:152

    async def rollback_transaction(self, tx_id: str) -> None:
        self.tracker.begin_operation()
        try:
            await self._engine.rollback_transaction(tx_id)
        finally:
            self.tracker.end_operation()
            self.tracker.transaction_finished(tx_id)


def parse_iam_endpoint_from_url(url: str) -> IAMEndpoint:
    """Parse an IAMEndpoint from a Postgres URL.

    Used so a reader URL can drive its own IAM refresh without requiring
    callers to set parallel DATABASE_HOST_READ_REPLICA / etc. env vars.
    """
    parsed: Final = urllib.parse.urlparse(url)
    if not parsed.hostname or not parsed.username:
        raise ValueError("Cannot parse IAM endpoint from URL: missing host or username")
    name: Final = (parsed.path or "/").lstrip("/")
    if not name:
        raise ValueError("Cannot parse IAM endpoint from URL: missing database name")
    port: Final = str(parsed.port) if parsed.port else "5432"
    schema: str | None = None
    if parsed.query:
        qs: Final = urllib.parse.parse_qs(parsed.query)
        schema_vals: Final = qs.get("schema")
        if schema_vals:
            schema = schema_vals[0]
    return IAMEndpoint(
        host=parsed.hostname,
        port=port,
        user=parsed.username,
        name=name,
        schema=schema,
    )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Include host and username in the database URL used for IAM auth.

Example fix

DATABASE_URL=postgresql://dbuser@mydb.cluster-xyz.us-east-1.rds.amazonaws.com:5432/litellm
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/db/prisma_client.py:152 when the library encounters an invalid state.

Common situations: The IAM database URL is malformed and lacks a host or username.


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