mem0ai/mem0 · error · ImportError

google-genai is required. Install with: pip install google-g

Error message

google-genai is required. Install with: pip install google-genai

What it means

Raised by GCPAuthenticator.get_genai_client when the google.genai package (the new Google GenAI SDK) cannot be imported. The method needs google.genai.Client to build the client; its absence aborts before authentication. Older google-generativeai packages do not satisfy this import.

Source

Thrown at mem0/utils/gcp_auth.py:154

        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)

        Returns:
            Google GenAI client instance
        """
        try:
            from google.genai import Client as GenAIClient
        except ImportError:
            raise ImportError("google-genai is required. Install with: pip install google-genai")

        # If API key is provided, use it directly
        if api_key:
            return GenAIClient(api_key=api_key)

        # Otherwise, try service account authentication
        credentials, _ = GCPAuthenticator.get_credentials(
            service_account_json=service_account_json,
            credentials_path=credentials_path,
            scopes=["https://www.googleapis.com/auth/generative-language"]
        )

        return GenAIClient(credentials=credentials)

View on GitHub (pinned to 001c235229)

Solutions

  1. pip install google-genai
  2. Add google-genai (not google-generativeai) to requirements.txt
  3. Verify: python -c "from google.genai import Client"
  4. Rebuild Docker/CI images after updating dependencies

Example fix

# before: ImportError: google-genai is required ...
client = GCPAuthenticator.get_genai_client(api_key=key)

# after
# pip install google-genai
client = GCPAuthenticator.get_genai_client(api_key=key)
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec('google.genai') is None:
    raise ConfigError('google-genai missing — pip install google-genai (not google-generativeai)')

Try / catch

try:
    client = GCPAuthenticator.get_genai_client(api_key=key)
except ImportError as e:
    if 'google-genai is required' in str(e):
        raise ConfigError('install google-genai') from e
    raise

Prevention

When it happens

Trigger: Using a Gemini/GenAI provider that routes through get_genai_client while only google-generativeai (the legacy SDK) is installed; fresh env with no Google SDKs; version drift where google-genai was never added to requirements.

Common situations: Migrating from the deprecated google-generativeai SDK and assuming it covers google.genai; Docker images built before the codebase switched to the new SDK; pip installing generativeai instead of genai.

Related errors


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