mem0ai/mem0 · error · ValueError

Project ID could not be determined. Please provide project_i

Error message

Project ID could not be determined. Please provide project_id parameter or set GOOGLE_CLOUD_PROJECT environment variable.

What it means

Raised by GCPAuthenticator.setup_vertex_ai when neither the explicit project_id parameter, the credentials' project_id, nor the GOOGLE_CLOUD_PROJECT env var yields a project. Vertex AI requires a project at init, so the call aborts before vertexai.init().

Source

Thrown at mem0/utils/gcp_auth.py:129

        Raises:
            ValueError: If authentication fails
        """
        try:
            import vertexai
        except ImportError:
            raise ImportError("google-cloud-aiplatform is required for Vertex AI. Install with: pip install google-cloud-aiplatform")

        credentials, detected_project_id = GCPAuthenticator.get_credentials(
            service_account_json=service_account_json,
            credentials_path=credentials_path,
            scopes=["https://www.googleapis.com/auth/cloud-platform"]
        )

        # Use provided project_id or fall back to detected one
        final_project_id = project_id or detected_project_id or os.getenv("GOOGLE_CLOUD_PROJECT")

        if not final_project_id:
            raise ValueError("Project ID could not be determined. Please provide project_id parameter or set GOOGLE_CLOUD_PROJECT environment variable.")

        vertexai.init(project=final_project_id, location=location, credentials=credentials)
        return final_project_id

    @staticmethod
    def get_genai_client(
        service_account_json: Optional[Dict[str, Any]] = None,
        credentials_path: Optional[str] = None,
        api_key: Optional[str] = None
    ):
        """
        Get a Google GenAI client with authentication.

        Args:
            service_account_json: Service account credentials as dict
            credentials_path: Path to service account JSON file
            api_key: API key (takes precedence over service account)

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass project_id explicitly in the provider config (vertexai embedder config accepts it)
  2. export GOOGLE_CLOUD_PROJECT=your-project-id in the shell/service environment
  3. Fix the service account JSON so it contains a non-empty project_id
  4. If using gcloud locally: gcloud config set project your-project-id and re-login

Example fix

# before
emb_cfg = {"provider": "vertexai", "config": {"model": "textembedding-005"}}

# after
emb_cfg = {"provider": "vertexai", "config": {"model": "textembedding-005", "project_id": "my-gcp-project"}}
Defensive patterns

Strategy: validation

Validate before calling

import os
PROJECT = cfg.get('project_id') or os.getenv('GOOGLE_CLOUD_PROJECT')
if not PROJECT:
    raise ConfigError('set project_id in config or GOOGLE_CLOUD_PROJECT env var')

Try / catch

try:
    GCPAuthenticator.setup_vertex_ai(location='us-central1')
except ValueError as e:
    if 'Project ID could not be determined' in str(e):
        raise ConfigError('provide project_id explicitly') from e
    raise

Prevention

When it happens

Trigger: Authenticating with an API-key-style flow or a service account JSON whose project_id field is empty; using default credentials in an environment where google.auth.default() returns project None (e.g. some Workload Identity setups); no GOOGLE_CLOUD_PROJECT set and no project passed in config.

Common situations: Hand-crafted service account JSON missing project_id; running on non-GCP infra with ADC from gcloud but no project configured locally (gcloud config has no project and no env var); copy-pasted config examples that omit project_id.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/50ff48b8d92dfe96. Report an issue: GitHub.