BerriAI/litellm · error · BadRequestError

litellm.BadRequestError: {custom_llm_provider}Exception - {e

Error message

litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}

What it means

LiteLLM raises this BadRequestError (HTTP 400) inside _map_vertex_exception when the Vertex AI error string indicates 'Vertex AI API has not been used in project' or 'Unable to find your project'. It means the Google Cloud project you referenced has never enabled or called the Vertex AI API, so Google rejects the request before any model inference happens. LiteLLM re-raises it as a structured exception with a synthetic 400 response so callers can handle it uniformly.

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 6c2dcb801b)

Solutions

  1. Verify the project ID: run `gcloud config get-value project` and compare it to the vertex_project / GOOGLE_CLOUD_PROJECT you pass to LiteLLM
  2. Enable the Vertex AI API in that project: `gcloud services enable aiplatform.googleapis.com --project=YOUR_PROJECT`
  3. Confirm billing is enabled on the project in the GCP console; Vertex AI requires an active billing account
  4. If using a service account, check its JSON file's project_id field matches the project you are targeting

Example fix

# before
from litellm import completion
resp = completion(model="vertex_ai/gemini-1.5-pro", messages=[...])
# raises BadRequestError: Vertex AI API has not been used in project 'my-proj'

# after (enable API + pin project)
# gcloud services enable aiplatform.googleapis.com --project=my-proj
resp = completion(
    model="vertex_ai/gemini-1.5-pro",
    messages=[...],
    vertex_project="my-proj",
    vertex_location="us-central1",
)
Defensive patterns

Strategy: validation

Validate before calling

import subprocess, sys

def vertex_project_ready(project: str) -> bool:
    """Fail fast if Vertex AI API is not enabled on the project."""
    out = subprocess.run(
        ["gcloud", "services", "list", "--enabled", "--project", project,
         "--filter", "config.name=aiplatform.googleapis.com", "--format", "value(config.name)"],
        capture_output=True, text=True,
    )
    if "aiplatform.googleapis.com" not in out.stdout:
        print(f"Enable first: gcloud services enable aiplatform.googleapis.com --project={project}",
              file=sys.stderr)
        return False
    return True

assert vertex_project_ready("my-proj")

Try / catch

import litellm

try:
    resp = litellm.completion(model="vertex_ai/gemini-1.5-pro", messages=msgs)
except litellm.BadRequestError as e:
    if "has not been used in project" in str(e) or "Unable to find your project" in str(e):
        raise RuntimeError(f"Vertex AI API not enabled / wrong project: {e}") from e
    raise

Prevention

When it happens

Trigger: Calling completion()/acompletion() with custom_llm_provider='vertex_ai' (or a model string like 'vertex_ai/gemini-1.5-pro') where GOOGLE_CLOUD_PROJECT / vertex_project points to a project that has not enabled the Vertex AI API (aiplatform.googleapis.com), or where the project ID is misspelled so Google reports it cannot find the project.

Common situations: Fresh GCP project where aiplatform.googleapis.com was never enabled; wrong or typo'd vertex_project in litellm.Router or completion() kwargs; service account credentials from one project pointed at another; using a project where billing is not set up so the API was never activated.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/5ea624c10138879e. Report an issue: GitHub.