{"record":{"id":"8480bbed37563853","repo":"BerriAI/litellm","slug":"vertex-project-and-vertex-location-are-required-fo-8480bb","errorCode":null,"errorMessage":"vertex_project and vertex_location are required for Vertex AI","messagePattern":"vertex_project and vertex_location are required for Vertex AI","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py","lineNumber":167,"sourceCode":"        Get the complete URL for Vertex AI Gemini generateContent API\n        \"\"\"\n        # Use the model name as provided, handling vertex_ai prefix\n        model_name = model\n        if model.startswith(\"vertex_ai/\"):\n            model_name = model.replace(\"vertex_ai/\", \"\")\n\n        # If a custom api_base is provided, use it directly\n        # This allows users to use proxies or mock endpoints\n        if api_base:\n            return api_base.rstrip(\"/\")\n\n        # First check litellm_params (where vertex_ai_project/vertex_ai_location are passed)\n        # then fall back to environment variables and other sources\n        vertex_project: Final = self.safe_get_vertex_ai_project(litellm_params) or self._resolve_vertex_project()\n        vertex_location: Final = self.safe_get_vertex_ai_location(litellm_params) or self._resolve_vertex_location()\n\n        if not vertex_project or not vertex_location:\n            raise ValueError(\"vertex_project and vertex_location are required for Vertex AI\")\n\n        base_url: Final = get_vertex_base_url(vertex_location)\n\n        return f\"{base_url}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model_name}:generateContent\"\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        headers = headers or {}\n\n        # If a custom api_base is provided, skip credential validation","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py#L149-L185","documentation":"For Gemini-based image generation (e.g. gemini-2.5-flash-image style models) on Vertex AI, litellm must construct .../projects/{project}/locations/{location}/publishers/google/models/{model}:generateContent. Project and location are resolved from vertex_ai_project/vertex_ai_location params, VERTEXAI_PROJECT/VERTEXAI_LOCATION env vars, module-level litellm.vertex_project/vertex_location, and secrets; if both remain unset this ValueError raises pre-flight. An api_base kwarg short-circuits resolution and is used verbatim.","triggerScenarios":"litellm.image_generation(model='vertex_ai/gemini-2.5-flash-image', prompt=...) in an environment with no VERTEXAI_PROJECT/VERTEXAI_LOCATION and no per-call project/location; works on a dev laptop (env set in .bashrc) but fails in CI/docker where the env is clean.","commonSituations":"Env vars not propagated into systemd/docker/proxy processes; wrong env var names (GOOGLE_CLOUD_PROJECT is not consulted here); teams relying on ADC credentials and forgetting the URL also needs project/region.","solutions":["Pass vertex_ai_project and vertex_ai_location on the call","Or export VERTEXAI_PROJECT / VERTEXAI_LOCATION where the process runs","Or set litellm.vertex_project / litellm.vertex_location once at app startup","For gateway/proxy setups, pass api_base to skip resolution"],"exampleFix":"# before\nresp = litellm.image_generation(\n    model='vertex_ai/gemini-2.5-flash-image',\n    prompt='a cat wearing sunglasses',\n)  # raises in env without VERTEXAI_PROJECT/LOCATION\n\n# after\nresp = litellm.image_generation(\n    model='vertex_ai/gemini-2.5-flash-image',\n    prompt='a cat wearing sunglasses',\n    vertex_ai_project='my-gcp-project',\n    vertex_ai_location='us-central1',\n)","handlingStrategy":"validation","validationCode":"import os\n\nassert os.environ.get('VERTEXAI_PROJECT') and (\n    os.environ.get('VERTEXAI_LOCATION') or os.environ.get('VERTEX_LOCATION')\n), 'set vertex project/location before image generation calls'","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_generation(model='vertex_ai/gemini-2.5-flash-image', prompt=p)\nexcept ValueError as e:\n    if 'vertex_project and vertex_location are required' in str(e):\n        raise RuntimeError('missing Vertex config — pass vertex_ai_project/location') from e\n    raise","preventionTips":["Pass vertex_ai_project/vertex_ai_location per call; do not rely on ambient env","Validate config in a startup healthcheck for each worker process","Use api_base when routing through a gateway that handles auth itself"],"tags":["vertex-ai","gemini","image-generation","configuration","gcp-project","missing-config"],"backgroundTag":"missing-required-config","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}