{"record":{"id":"22781d32b38f0242","repo":"BerriAI/litellm","slug":"importing-google-generativeai-failed-please-run","errorCode":null,"errorMessage":"Importing google.generativeai failed, please run 'pip install -q google-generativeai","messagePattern":"Importing google\\.generativeai failed, please run 'pip install -q google-generativeai","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"litellm/llms/deprecated_providers/palm.py","lineNumber":104,"sourceCode":"        }\n\n\ndef completion(\n    model: str,\n    messages: list,\n    model_response: ModelResponse,\n    print_verbose: Callable,\n    api_key,\n    encoding,\n    logging_obj,\n    optional_params: dict,\n    litellm_params=None,\n    logger_fn=None,\n):\n    try:\n        import google.generativeai as palm\n    except Exception:\n        raise Exception(\"Importing google.generativeai failed, please run 'pip install -q google-generativeai\")\n    palm.configure(api_key=api_key)\n\n    model = model\n\n    ## Load Config\n    inference_params: Final = copy.deepcopy(optional_params)\n    inference_params.pop(\n        \"stream\", None\n    )  # palm does not support streaming, so we handle this by fake streaming in main.py\n    config: Final = litellm.PalmConfig.get_config()\n    for k, v in config.items():\n        if (\n            k not in inference_params\n        ):  # completion(top_k=3) > palm_config(top_k=3) <- allows for dynamic variables to be passed in\n            inference_params[k] = v\n\n    prompt = \"\"\n    for message in messages:","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/deprecated_providers/palm.py#L86-L122","documentation":"Import guard in the deprecated PaLM completion path: importing google.generativeai failed because the optional dependency is not installed (or failed to load). The message includes the exact pip command needed to enable this deprecated provider.","triggerScenarios":"Thrown at litellm/llms/deprecated_providers/palm.py:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Install the dependency: pip install -q google-generativeai","Note the palm provider is deprecated; prefer the gemini provider which uses the maintained SDK."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}