BerriAI/litellm · error · ValueError
vertex_project and vertex_location are required for Vertex A
Error message
vertex_project and vertex_location are required for Vertex AI
What it means
Vertex AI Imagen image edit calls the predict API, whose URL embeds both the GCP project and the region: {base}/v1/projects/{project}/locations/{location}/publishers/google/models/{model}:predict. The config resolves them from vertex_ai_project/vertex_ai_location params, VERTEXAI_PROJECT/VERTEXAI_LOCATION (or VERTEX_LOCATION) env vars, module-level litellm.vertex_project/vertex_location, and secrets; if either is missing this ValueError fires. Important nuance: unlike the Gemini handlers, api_base does NOT bypass this check — project/location are needed to build the path even when api_base is supplied.
Source
Thrown at litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py:132
project_id=vertex_project,
custom_llm_provider="vertex_ai",
)
return self.set_headers(access_token, headers)
def get_complete_url(
self,
model: str,
api_base: str | None,
litellm_params: dict,
) -> str:
"""
Get the complete URL for Vertex AI Imagen predict API
"""
vertex_project: Final = self.safe_get_vertex_ai_project(litellm_params) or self._resolve_vertex_project()
vertex_location: Final = self.safe_get_vertex_ai_location(litellm_params) or self._resolve_vertex_location()
if not vertex_project or not vertex_location:
raise ValueError("vertex_project and vertex_location are required for Vertex AI")
# Use the model name as provided, handling vertex_ai prefix
model_name = model
if model.startswith("vertex_ai/"):
model_name = model.replace("vertex_ai/", "")
if api_base:
base_url = api_base.rstrip("/")
else:
base_url = get_vertex_base_url(vertex_location)
return f"{base_url}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model_name}:predict"
def transform_image_edit_request(
self,
model: str,
prompt: str | None,
image: FileTypes | None,View on GitHub (pinned to 77b7c6c40c)
Solutions
- Pass vertex_ai_project='my-project' and vertex_ai_location='us-central1' on every image_edit call targeting vertex_ai/imagen-* edit models
- Or export VERTEXAI_PROJECT and VERTEXAI_LOCATION in the process environment
- Or set litellm.vertex_project / litellm.vertex_location module-level defaults
- Do not rely on api_base alone for Imagen edit — it cannot substitute for project/location
Example fix
# before (raises even with api_base)
resp = litellm.image_edit(
model='vertex_ai/imagen-3.0-capability-001',
prompt='remove the background',
image=open('cat.png', 'rb').read(),
api_base='https://my-proxy.example.com',
)
# after
resp = litellm.image_edit(
model='vertex_ai/imagen-3.0-capability-001',
prompt='remove the background',
image=open('cat.png', 'rb').read(),
vertex_ai_project='my-gcp-project',
vertex_ai_location='us-central1',
api_base='https://my-proxy.example.com',
) Defensive patterns
Strategy: validation
Validate before calling
import os
project = os.environ.get('VERTEXAI_PROJECT')
location = os.environ.get('VERTEXAI_LOCATION') or os.environ.get('VERTEX_LOCATION')
if not (project and location):
raise RuntimeError('imagen edit needs project+location even when api_base is set') Try / catch
try:
resp = litellm.image_edit(model='vertex_ai/imagen-3.0-capability-001', prompt=p, image=img)
except ValueError as e:
if 'vertex_project and vertex_location are required' in str(e):
raise RuntimeError('configure vertex_ai_project/vertex_ai_location (api_base will not bypass this)') from e
raise Prevention
- Never assume api_base replaces project/location for Imagen edit — it does not
- Centralize Vertex config in one provider object that injects project/location into every call
- Smoke-test config at deploy time with a tiny image_edit call
When it happens
Trigger: litellm.image_edit(model='vertex_ai/imagen-3.0-capability-001', prompt=..., image=f, api_base='https://my-proxy') still raises, because the project/location check precedes the api_base branch; likewise any call without params or env vars set.
Common situations: Assuming a proxy api_base removes the need for project/location (it does not for Imagen edit); credentials-only setup (GOOGLE_APPLICATION_CREDENTIALS) with no project/location; env vars missing in dockerized proxy deployments.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- vertex_project and vertex_location are required for Vertex A
- vertex_project and vertex_location are required for Vertex A
- vertex_project and vertex_location are required for Vertex A
- Vertex AI Imagen image edit requires at least one reference
- Vertex AI Imagen image edit requires a prompt.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/d4d804df833ae559.
Report an issue: GitHub.