BerriAI/litellm · error · ValueError

Invalid vertex_location format

Error message

Invalid vertex_location format

What it means

Raised by get_vertex_base_url when the supplied vertex_location string does not match a recognized Vertex region or 'global'; the location is used verbatim in the aiplatform hostname, so malformed values would produce an invalid URL.

Source

Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:1493

        return get_vertex_base_url(vertex_location)

    @staticmethod
    def update_base_target_url_with_credential_location(base_target_url: str, vertex_location: str | None) -> str:
        return get_vertex_base_url(vertex_location)


def get_vertex_base_url(vertex_location: str | None) -> str:
    """
    Base URL for Vertex AI pass-through (trailing slash for URL joining).

    Keep location rules aligned with ``litellm.llms.vertex_ai.common_utils.get_vertex_base_url``.
    """
    if vertex_location == "global":
        return "https://aiplatform.googleapis.com/"
    if vertex_location is None:
        raise ValueError("vertex_location is required")
    if not re.match(r"^[a-z][a-z0-9-]*$", vertex_location):
        raise ValueError("Invalid vertex_location format")
    if "-" not in vertex_location:
        return f"https://aiplatform.{vertex_location}.rep.googleapis.com/"
    return f"https://{vertex_location}-aiplatform.googleapis.com/"


def get_vertex_ai_allowed_incoming_headers(request: Request) -> dict:
    """
    Extract only the allowed headers from incoming request for Vertex AI pass-through.

    Uses an allowlist approach for security - only forwards headers we explicitly trust.
    This prevents accidentally forwarding sensitive headers like the LiteLLM auth token.

    Args:
        request: The FastAPI request object

    Returns:
        dict: Headers dictionary with only allowed headers
    """

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Use a valid GCP region format for vertex_location, e.g. us-central1 or europe-west4.
  2. Remove any scheme or path from the location value.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:1493 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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