{"record":{"id":"488774a7b266d055","repo":"BerriAI/litellm","slug":"vertexai-import-failed-please-run-pip-install-u-488774","errorCode":null,"errorMessage":"vertexai import failed please run `pip install -U \"google-cloud-aiplatform>=1.38\"`. Got error: {e}","messagePattern":"vertexai import failed please run `pip install -U \"google-cloud-aiplatform>=1\\.38\"`\\. Got error: (.+?)","errorType":"http","errorClass":"VertexAIError","httpStatus":400,"severity":"error","filePath":"litellm/llms/vertex_ai/vertex_model_garden/main.py","lineNumber":91,"sourceCode":"        litellm_params: dict,\n        vertex_project=None,\n        vertex_location=None,\n        vertex_credentials=None,\n        logger_fn=None,\n        acompletion: bool = False,\n        client=None,\n    ):\n        \"\"\"\n        Handles calling Vertex AI Model Garden Models in OpenAI compatible format\n\n        Sent to this route when `model` is in the format `vertex_ai/openai/{MODEL_ID}`\n        \"\"\"\n        try:\n            import vertexai\n\n            from litellm.llms.openai_like.chat.handler import OpenAILikeChatHandler\n        except Exception as e:\n            raise VertexAIError(\n                status_code=400,\n                message=f\"\"\"vertexai import failed please run `pip install -U \"google-cloud-aiplatform>=1.38\"`. Got error: {e}\"\"\",\n            )\n\n        if not (hasattr(vertexai, \"preview\") or hasattr(vertexai.preview, \"language_models\")):\n            raise VertexAIError(\n                status_code=400,\n                message=\"\"\"Upgrade vertex ai. Run `pip install \"google-cloud-aiplatform>=1.38\"`\"\"\",\n            )\n        try:\n            model = get_vertex_base_model_name(model=model)\n\n            access_token, project_id = self._ensure_access_token(\n                credentials=vertex_credentials,\n                project_id=vertex_project,\n                custom_llm_provider=\"vertex_ai\",\n            )\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/vertex_model_garden/main.py#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["pip install -U \"google-cloud-aiplatform>=1.38\" in the same environment that runs litellm.","If it still fails, inspect the \"Got error: ...\" suffix — it contains the original ImportError (often a protobuf/grpcio conflict) and fix that dependency.","Recreate/repair the environment: pip install --force-reinstall google-cloud-aiplatform google-auth requests.","For Docker, add the package to the image rather than relying on runtime install."],"exampleFix":"# before: import fails at call time\nlitellm.completion(model=\"vertex_ai/openai/meta-llama/Llama-3.1-405B\", ...)\n\n# after: install the SDK first\n# pip install -U \"google-cloud-aiplatform>=1.38\"\nlitellm.completion(model=\"vertex_ai/openai/meta-llama/Llama-3.1-405B\", ...)","handlingStrategy":"validation","validationCode":"def model_garden_deps_ok() -> bool:\n    try:\n        import vertexai  # noqa: F401\n        import litellm.llms.openai_like.chat.handler  # noqa: F401\n        return True\n    except Exception:\n        return False\n\nif not model_garden_deps_ok():\n    raise RuntimeError(\"Run: pip install -U 'google-cloud-aiplatform>=1.38'\")","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=\"vertex_ai/openai/llama-3.1-405b-instruct\", messages=msgs)\nexcept VertexAIError as e:\n    if \"vertexai import failed\" in str(e):\n        raise RuntimeError(\"google-cloud-aiplatform not installed in this environment\") from e\n    raise","preventionTips":["Declare google-cloud-aiplatform>=1.38 as a direct dependency in your project, not an optional extra.","Add an import smoke test (import vertexai) to your deployment healthcheck.","Pin your environment (lockfile or image) so transitive downgrades can't remove the SDK."],"tags":["vertex-ai","model-garden","dependency","import-error","pip"],"backgroundTag":"missing-dependency","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}