{"record":{"id":"464c43f5eb45bb20","repo":"crewAIInc/crewAI","slug":"google-genai-is-required-for-gemini-file-uploads","errorCode":null,"errorMessage":"google-genai is required for Gemini file uploads. Install with: pip install google-genai","messagePattern":"google-genai is required for Gemini file uploads\\. Install with: pip install google-genai","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/uploaders/gemini.py","lineNumber":124,"sourceCode":"            client: Optional pre-instantiated Gemini client.\n        \"\"\"\n        self._api_key = api_key or os.environ.get(\"GOOGLE_API_KEY\")\n        self._client: Any = client\n\n    @property\n    def provider_name(self) -> str:\n        \"\"\"Return the provider name.\"\"\"\n        return \"gemini\"\n\n    def _get_client(self) -> Any:\n        \"\"\"Get or create the Gemini client.\"\"\"\n        if self._client is None:\n            try:\n                from google import genai\n\n                self._client = genai.Client(api_key=self._api_key)\n            except ImportError as e:\n                raise ImportError(\n                    \"google-genai is required for Gemini file uploads. \"\n                    \"Install with: pip install google-genai\"\n                ) from e\n        return self._client\n\n    def upload(self, file: FileInput, purpose: str | None = None) -> UploadResult:\n        \"\"\"Upload a file to Gemini.\n\n        For FilePath sources, passes the path directly to the SDK which handles\n        streaming internally via resumable uploads, avoiding memory overhead.\n\n        Args:\n            file: The file to upload.\n            purpose: Optional purpose/description (used as display name).\n\n        Returns:\n            UploadResult with the file URI and metadata.\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/uploaders/gemini.py#L106-L142","documentation":"ImportError raised lazily by GeminiFileUploader._get_client when 'from google import genai' fails: the google-genai SDK is not installed. Note the required package is the newer google-genai distribution (not the legacy google-generativeai), so installing the wrong package reproduces the error.","triggerScenarios":"Constructing GeminiFileUploader and calling upload (which triggers _get_client) when google-genai is missing, or when only the legacy google-generativeai package is installed.","commonSituations":"Following older tutorials that say pip install google-generativeai; deploying without the Gemini extra; using a notebook kernel whose environment lacks the SDK.","solutions":["pip install google-genai (the correct, current SDK for this uploader).","Uninstall the legacy package if present to avoid confusion: pip uninstall google-generativeai.","Warm the client at startup with uploader._get_client() to fail fast."],"exampleFix":"# before\n# pip install google-generativeai  (wrong package)\nuploader = GeminiFileUploader(api_key=...)\nuploader.upload(file)  # ImportError\n\n# after\n# pip install google-genai\nuploader = GeminiFileUploader(api_key=...)\nuploader._get_client()  # fail fast\nuploader.upload(file)","handlingStrategy":"validation","validationCode":"from importlib.util import find_spec\n\nif find_spec(\"google.genai\") is None:\n    raise RuntimeError(\"pip install google-genai (not google-generativeai) required\")","typeGuard":null,"tryCatchPattern":"try:\n    uploader.upload(file)\nexcept ImportError as e:\n    if \"google-genai\" in str(e):\n        raise RuntimeError(\"wrong or missing SDK: pip install google-genai\") from e\n    raise","preventionTips":["Install google-genai, the current SDK; do not mix with legacy google-generativeai.","Warm _get_client() at startup.","Document the exact extra in the project's dependency manifest."],"tags":["import-error","gemini","google-genai","dependency","file-upload"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}