{"record":{"id":"159f1b02871bb61a","repo":"BerriAI/litellm","slug":"vertex-project-and-vertex-location-are-required-fo-159f1b","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_imagen_transformation.py","lineNumber":140,"sourceCode":"        Get the complete URL for Vertex AI Imagen predict 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}:predict\"\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":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_generation/vertex_imagen_transformation.py#L122-L158","documentation":"Imagen image generation (imagegeneration / imagen-* models) targets the predict endpoint, whose URL embeds the GCP project and region. get_complete_url resolves them from vertex_ai_project/vertex_ai_location request params, VERTEXAI_PROJECT/VERTEXAI_LOCATION (or VERTEX_LOCATION) env vars, module-level litellm.vertex_project/vertex_location, and secrets. If neither is found the call aborts with this ValueError. Note: for the image-generation handler (unlike image_edit's Imagen path), an api_base kwabypasses the check and returns early.","triggerScenarios":"litellm.image_generation(model='vertex_ai/imagegeneration', prompt=...) with clean env and no per-call params; SDK version drift where a previously-working env-based setup stops being read; serverless deployments (Lambda/Cloud Run) that strip shell env vars.","commonSituations":"Moving from local dev to containerized deploys; .env files loaded by the web framework but not by the celery worker invoking litellm; multi-project GCP setups where the wrong project env var was assumed.","solutions":["Pass vertex_ai_project='my-project' and vertex_ai_location='us-central1' explicitly","Or export VERTEXAI_PROJECT / VERTEXAI_LOCATION in every process that calls litellm (workers included)","Or set litellm.vertex_project / litellm.vertex_location at startup","Or provide api_base, which for image generation skips project/location resolution entirely"],"exampleFix":"# before\nresp = litellm.image_generation(\n    model='vertex_ai/imagen-3.0-generate-002',\n    prompt='a cat',\n)\n\n# after\nresp = litellm.image_generation(\n    model='vertex_ai/imagen-3.0-generate-002',\n    prompt='a cat',\n    vertex_ai_project='my-gcp-project',\n    vertex_ai_location='us-central1',\n)","handlingStrategy":"validation","validationCode":"import os\n\nPROJECT = os.environ.get('VERTEXAI_PROJECT')\nLOCATION = os.environ.get('VERTEXAI_LOCATION') or os.environ.get('VERTEX_LOCATION')\nif not (PROJECT and LOCATION):\n    PROJECT, LOCATION = 'my-project', 'us-central1'  # or hard fail","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_generation(model='vertex_ai/imagegeneration', prompt=p)\nexcept ValueError as e:\n    if 'vertex_project and vertex_location are required' in str(e):\n        raise RuntimeError('set VERTEXAI_PROJECT/VERTEXAI_LOCATION or pass them per call') from e\n    raise","preventionTips":["Set project/location once in shared config and inject into every image_generation call","For proxy setups, api_base skips the check on the generation path","Add config assertions to CI so missing env fails the build, not the request"],"tags":["vertex-ai","imagen","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"}