BerriAI/litellm · error · VertexAIError

vertexai import failed please run `pip install -U "google-cl

Error message

vertexai import failed please run `pip install -U "google-cloud-aiplatform>=1.38"`. Got error: {e}

What it means

This VertexAIError (HTTP 400) is raised by the Vertex Model Garden OpenAI-compatible route (`vertex_ai/openai/{MODEL_ID}` models) when importing the `vertexai` package (google-cloud-aiplatform SDK) or LiteLLM's OpenAILikeChatHandler fails at call time. The import is done lazily inside the completion function, so an ImportError for any reason — package missing, broken install, incompatible dependency — surfaces wrapped in this message with the original error appended.

Source

Thrown at litellm/llms/vertex_ai/vertex_model_garden/main.py:91

        litellm_params: dict,
        vertex_project=None,
        vertex_location=None,
        vertex_credentials=None,
        logger_fn=None,
        acompletion: bool = False,
        client=None,
    ):
        """
        Handles calling Vertex AI Model Garden Models in OpenAI compatible format

        Sent to this route when `model` is in the format `vertex_ai/openai/{MODEL_ID}`
        """
        try:
            import vertexai

            from litellm.llms.openai_like.chat.handler import OpenAILikeChatHandler
        except Exception as e:
            raise VertexAIError(
                status_code=400,
                message=f"""vertexai import failed please run `pip install -U "google-cloud-aiplatform>=1.38"`. Got error: {e}""",
            )

        if not (hasattr(vertexai, "preview") or hasattr(vertexai.preview, "language_models")):
            raise VertexAIError(
                status_code=400,
                message="""Upgrade vertex ai. Run `pip install "google-cloud-aiplatform>=1.38"`""",
            )
        try:
            model = get_vertex_base_model_name(model=model)

            access_token, project_id = self._ensure_access_token(
                credentials=vertex_credentials,
                project_id=vertex_project,
                custom_llm_provider="vertex_ai",
            )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. pip install -U "google-cloud-aiplatform>=1.38" in the same environment that runs litellm.
  2. If it still fails, inspect the "Got error: ..." suffix — it contains the original ImportError (often a protobuf/grpcio conflict) and fix that dependency.
  3. Recreate/repair the environment: pip install --force-reinstall google-cloud-aiplatform google-auth requests.
  4. For Docker, add the package to the image rather than relying on runtime install.

Example fix

# before: import fails at call time
litellm.completion(model="vertex_ai/openai/meta-llama/Llama-3.1-405B", ...)

# after: install the SDK first
# pip install -U "google-cloud-aiplatform>=1.38"
litellm.completion(model="vertex_ai/openai/meta-llama/Llama-3.1-405B", ...)
Defensive patterns

Strategy: validation

Validate before calling

def model_garden_deps_ok() -> bool:
    try:
        import vertexai  # noqa: F401
        import litellm.llms.openai_like.chat.handler  # noqa: F401
        return True
    except Exception:
        return False

if not model_garden_deps_ok():
    raise RuntimeError("Run: pip install -U 'google-cloud-aiplatform>=1.38'")

Try / catch

try:
    litellm.completion(model="vertex_ai/openai/llama-3.1-405b-instruct", messages=msgs)
except VertexAIError as e:
    if "vertexai import failed" in str(e):
        raise RuntimeError("google-cloud-aiplatform not installed in this environment") from e
    raise

Prevention

When it happens

Trigger: Calling completion with a model like "vertex_ai/openai/llama-3.1-405b-instruct" on an environment where `pip show google-cloud-aiplatform` fails, or where a dependency conflict (e.g. protobuf, grpcio, google-api-core versions) makes `import vertexai` raise.

Common situations: Slim Docker images that installed litellm without the vertex extras; pip dependency resolution downgrading google-cloud-aiplatform to <1.38 or uninstalling it; virtualenvs shared between projects with conflicting google packages.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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