BerriAI/litellm · error · BadRequestError
litellm.BadRequestError
Error message
litellm.BadRequestError: {custom_llm_provider}Exception - {error_str} What it means
Vertex AI replied 'Vertex AI API has not been used in project' or 'Unable to find your project', and litellm maps it to BadRequestError with a synthetic 400 response and litellm_debug_info. The Google project litellm used either does not exist, is misspelled, or does not have the Vertex AI API (aiplatform.googleapis.com) enabled.
Solutions
- Enable the API: gcloud services enable aiplatform.googleapis.com --project=<project>
- Pass the exact project: litellm.completion(..., vertex_project='my-proj', vertex_location='us-east1') and make sure it matches the credentials' project
- Verify the project id exists as spelled: gcloud projects describe <project>
- Re-authenticate: gcloud auth application-default login, or point GOOGLE_APPLICATION_CREDENTIALS at a valid service account JSON for that project
Example fix
# before
litellm.completion(
model='gemini-1.5-pro',
messages=messages,
custom_llm_provider='vertex_ai',
) # project inferred wrongly / API disabled
# after
# 1) gcloud services enable aiplatform.googleapis.com --project=my-proj
litellm.completion(
model='gemini-1.5-pro',
messages=messages,
vertex_project='my-proj',
vertex_location='us-central1',
) Defensive patterns
Strategy: validation
Validate before calling
from googleapiclient import discovery
def vertex_api_enabled(project_id: str, creds) -> bool:
service = discovery.build('serviceusage', 'v1', credentials=creds)
state = service.services().get(name=f'projects/{project_id}/services/aiplatform.googleapis.com').execute()
return state['state'] == 'ENABLED'
# startup check for every project you route to
assert vertex_api_enabled('my-proj', creds) Type guard
import litellm
def is_vertex_project_error(exc: BaseException) -> bool:
msg = str(exc)
return isinstance(exc, litellm.exceptions.BadRequestError) and (
'Vertex AI API has not been used in project' in msg or 'Unable to find your project' in msg
) Try / catch
import litellm
from litellm.exceptions import BadRequestError
try:
resp = litellm.completion(model='vertex_ai/gemini-1.5-pro', messages=messages,
vertex_project='my-proj', vertex_location='us-central1')
except BadRequestError as e:
if 'not been used in project' in str(e) or 'Unable to find your project' in str(e):
raise RuntimeError('enable aiplatform.googleapis.com on project my-proj')
raise Prevention
- Codify gcloud services enable aiplatform.googleapis.com in project bootstrap scripts
- Always pass vertex_project and vertex_location explicitly instead of relying on inferred defaults
- Add a startup probe that lists models on the configured project before serving traffic
When it happens
Trigger: custom_llm_provider='vertex_ai' where vertex_project / config project_id is misspelled; the project exists but aiplatform.googleapis.com was never enabled; credentials from project A while the request targets project B.
Common situations: New GCP project where Vertex AI API was never turned on; service account JSON from a different project; vertex_project parameter omitted so litellm resolves the wrong default project.
Related errors
- ContextWindowExceededError
- Exception BadRequestError
- Exception ContentPolicyViolationError
- Exception
- litellm.RateLimitError
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/5ea624c10138879e.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1085
model=model,
llm_provider=custom_llm_provider,
litellm_debug_info=extra_information,
exception_status_code=original_exception.status_code,
)
def _map_vertex_exception(
*,
model: str,
original_exception: _ProviderHTTPException,
custom_llm_provider: str,
error_str: str,
exception_type: str,
exception_provider: str,
extra_information: str,
) -> None:
if "Vertex AI API has not been used in project" in error_str or "Unable to find your project" in error_str:
raise BadRequestError(
message=f"litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}",
model=model,
llm_provider=custom_llm_provider,
response=httpx.Response(
status_code=400,
request=httpx.Request(
method="POST",
url=" https://cloud.google.com/vertex-ai/",
),
),
litellm_debug_info=extra_information,
)
if "400 Request payload size exceeds" in error_str:
raise ContextWindowExceededError(
message=f"{custom_llm_provider.capitalize()}Exception - {error_str}",
model=model,
llm_provider=custom_llm_provider,
)View on GitHub (pinned to 77b7c6c40c)