BerriAI/litellm · error

Importing google.generativeai failed, please run 'pip…

Error message

Importing google.generativeai failed, please run 'pip install -q google-generativeai

What it means

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.

Solutions

  1. Install the dependency: pip install -q google-generativeai
  2. Note the palm provider is deprecated; prefer the gemini provider which uses the maintained SDK.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/llms/deprecated_providers/palm.py:104 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/22781d32b38f0242. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/deprecated_providers/palm.py:104

        }


def completion(
    model: str,
    messages: list,
    model_response: ModelResponse,
    print_verbose: Callable,
    api_key,
    encoding,
    logging_obj,
    optional_params: dict,
    litellm_params=None,
    logger_fn=None,
):
    try:
        import google.generativeai as palm
    except Exception:
        raise Exception("Importing google.generativeai failed, please run 'pip install -q google-generativeai")
    palm.configure(api_key=api_key)

    model = model

    ## Load Config
    inference_params: Final = copy.deepcopy(optional_params)
    inference_params.pop(
        "stream", None
    )  # palm does not support streaming, so we handle this by fake streaming in main.py
    config: Final = litellm.PalmConfig.get_config()
    for k, v in config.items():
        if (
            k not in inference_params
        ):  # completion(top_k=3) > palm_config(top_k=3) <- allows for dynamic variables to be passed in
            inference_params[k] = v

    prompt = ""
    for message in messages:

View on GitHub (pinned to 77b7c6c40c)