BerriAI/litellm · error · TypeError
Expected project_id to be a str but got {type(project_id)}
Error message
Expected project_id to be a str but got {type(project_id)} What it means
Type guard after project_id resolution: a project_id was found but is not a string (e.g. an int or object from a malformed credential file), which would break URL construction. The actual type is included.
Source
Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:196
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
if project_id is None:
project_id = getattr(creds, "project_id", None)
else:
creds, creds_project_id = self._credentials_from_default_auth(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
if project_id is None:
project_id = creds_project_id
self.refresh_auth(creds)
if not project_id:
raise ValueError("Could not resolve project_id")
if not isinstance(project_id, str):
raise TypeError(f"Expected project_id to be a str but got {type(project_id)}")
return creds, project_id
# Google Auth Helpers -- extracted for mocking purposes in tests
def _credentials_from_identity_pool(self, json_obj, scopes):
try:
from google.auth import identity_pool
except ImportError:
raise ImportError(GOOGLE_IMPORT_ERROR_MESSAGE)
creds = identity_pool.Credentials.from_info(json_obj)
if scopes and hasattr(creds, "requires_scopes") and creds.requires_scopes:
creds = creds.with_scopes(scopes)
return creds
def _credentials_from_pluggable(self, json_obj, scopes):
try:
from google.auth import pluggableView on GitHub (pinned to 77b7c6c40c)
Solutions
- Pass project_id as a string; convert the value (see its type in the error) with str() or fix the source providing it.
- Check that VERTEXAI_PROJECT / vertex_project is not being set to a non-string object.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:196 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0ad9b6b2c4d87e3f.
Report an issue: GitHub.