{"record":{"id":"5ea624c10138879e","repo":"BerriAI/litellm","slug":"litellm-badrequesterror-custom-llm-provider-exce","errorCode":null,"errorMessage":"litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}","messagePattern":"litellm\\.BadRequestError: (.+?)Exception - (.+?)","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1085,"sourceCode":"                model=model,\n                llm_provider=custom_llm_provider,\n                litellm_debug_info=extra_information,\n                exception_status_code=original_exception.status_code,\n            )\n\n\ndef _map_vertex_exception(\n    *,\n    model: str,\n    original_exception: _ProviderHTTPException,\n    custom_llm_provider: str,\n    error_str: str,\n    exception_type: str,\n    exception_provider: str,\n    extra_information: str,\n) -> None:\n    if \"Vertex AI API has not been used in project\" in error_str or \"Unable to find your project\" in error_str:\n        raise BadRequestError(\n            message=f\"litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            response=httpx.Response(\n                status_code=400,\n                request=httpx.Request(\n                    method=\"POST\",\n                    url=\" https://cloud.google.com/vertex-ai/\",\n                ),\n            ),\n            litellm_debug_info=extra_information,\n        )\n    if \"400 Request payload size exceeds\" in error_str:\n        raise ContextWindowExceededError(\n            message=f\"{custom_llm_provider.capitalize()}Exception - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n        )","sourceCodeStart":1067,"sourceCodeEnd":1103,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L1067-L1103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nlitellm.completion(\n    model='gemini-1.5-pro',\n    messages=messages,\n    custom_llm_provider='vertex_ai',\n)  # project inferred wrongly / API disabled\n\n# after\n# 1) gcloud services enable aiplatform.googleapis.com --project=my-proj\nlitellm.completion(\n    model='gemini-1.5-pro',\n    messages=messages,\n    vertex_project='my-proj',\n    vertex_location='us-central1',\n)","handlingStrategy":"validation","validationCode":"from googleapiclient import discovery\n\ndef vertex_api_enabled(project_id: str, creds) -> bool:\n    service = discovery.build('serviceusage', 'v1', credentials=creds)\n    state = service.services().get(name=f'projects/{project_id}/services/aiplatform.googleapis.com').execute()\n    return state['state'] == 'ENABLED'\n\n# startup check for every project you route to\nassert vertex_api_enabled('my-proj', creds)","typeGuard":"import litellm\n\ndef is_vertex_project_error(exc: BaseException) -> bool:\n    msg = str(exc)\n    return isinstance(exc, litellm.exceptions.BadRequestError) and (\n        'Vertex AI API has not been used in project' in msg or 'Unable to find your project' in msg\n    )","tryCatchPattern":"import litellm\nfrom litellm.exceptions import BadRequestError\n\ntry:\n    resp = litellm.completion(model='vertex_ai/gemini-1.5-pro', messages=messages,\n                              vertex_project='my-proj', vertex_location='us-central1')\nexcept BadRequestError as e:\n    if 'not been used in project' in str(e) or 'Unable to find your project' in str(e):\n        raise RuntimeError('enable aiplatform.googleapis.com on project my-proj')\n    raise","preventionTips":["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"],"tags":["vertex-ai","gcp","google-cloud","project-config","api-not-enabled","litellm"],"backgroundTag":"api-not-enabled","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}