NotFound
google.api_core.exceptions.NotFound
Stack trace
google.api_core.exceptions.NotFound: 404 The model "projects/your-project/locations/us-central1/models/nonexistent-model" was not found. at google.cloud.aiplatform_v1.services.model_service.client.ModelServiceClient.get_model(ModelServiceClient.java:...)
Why it happens
This error occurs when the model ID provided to the Vertex AI GenerativeModel client does not exist in the specified project or location, or the authenticated user lacks permission to access it. It can also happen if the model name is misspelled or the location is incorrect.
Detection
Catch google.api_core.exceptions.NotFound exceptions when calling model-related methods and log the full model resource name to verify correctness before retrying.
Causes & fixes
Incorrect or misspelled model resource name passed to the GenerativeModel client.
Verify and correct the full model resource name format: 'projects/{project}/locations/{location}/models/{model_id}'.
Model does not exist in the specified project or location.
Confirm the model is deployed in the correct project and location via the Google Cloud Console or gcloud CLI.
Insufficient IAM permissions to access the model resource.
Ensure the service account or user has roles/aiplatform.user or equivalent permissions for the model.
Code: broken vs fixed
from google.cloud import aiplatform
client = aiplatform.gapic.GenerativeModelServiceClient()
model_name = "projects/my-project/locations/us-central1/models/nonexistent-model"
response = client.generate_text(model=model_name, prompt="Hello") # This line triggers NotFound error import os
from google.cloud import aiplatform
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") # Use env var for auth
client = aiplatform.gapic.GenerativeModelServiceClient()
model_name = "projects/my-project/locations/us-central1/models/valid-model-id" # Correct model ID
response = client.generate_text(model=model_name, prompt="Hello")
print(response) Workaround
Wrap calls in try/except for NotFound and fallback to a default known good model or notify the user to check model availability.
Prevention
Use infrastructure as code or deployment scripts to manage and verify model deployment and resource names before runtime to avoid invalid references.