BerriAI/litellm · error · Exception

Required 'GEMINI_API_KEY'/'GOOGLE_API_KEY' in environment to

Error message

Required 'GEMINI_API_KEY'/'GOOGLE_API_KEY' in environment to make pass-through calls to Google AI Studio.

What it means

HTTPException raised on the Google AI Studio pass-through route: neither GEMINI_API_KEY nor GOOGLE_API_KEY is present in the environment (or resolvable via the passthrough route lock), so the proxied request to Google cannot be authenticated. The admin must set one of these variables.

Source

Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:223

    # Ensure endpoint starts with '/' for proper URL construction
    if not encoded_endpoint.startswith("/"):
        encoded_endpoint = "/" + encoded_endpoint

    # Construct the full target URL using httpx, preserving any base path
    # prefix that the operator configured on base_target_url.
    base_url: Final = httpx.URL(base_target_url)
    updated_url: Final = base_url.copy_with(
        path=HttpPassThroughEndpointHelpers.join_base_and_endpoint_path(base_url, encoded_endpoint)
    )

    # Add or update query parameters
    gemini_api_key: Final[str | None] = passthrough_endpoint_router.get_credentials(
        custom_llm_provider="gemini",
        region_name=None,
    )
    if gemini_api_key is None:
        raise Exception(
            "Required 'GEMINI_API_KEY'/'GOOGLE_API_KEY' in environment to make pass-through calls to Google AI Studio."
        )
    # Merge query parameters, giving precedence to those in updated_url
    merged_params: Final = dict(request.query_params)
    merged_params.update({"key": gemini_api_key})

    ## check for streaming
    is_streaming_request = False
    if "stream" in str(updated_url):
        is_streaming_request = True

    ## CREATE PASS-THROUGH
    endpoint_func: Final = create_pass_through_route(
        endpoint=endpoint,
        target=str(updated_url),
        custom_llm_provider="gemini",
        is_streaming_request=is_streaming_request,
        query_params=merged_params,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set GEMINI_API_KEY or GOOGLE_API_KEY in the proxy environment before calling the Gemini pass-through endpoint.
  2. Alternatively configure the credential on the model/vector store entry in config.yaml so the pass-through route can resolve it.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:223 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/e441ae4024c53e98. Report an issue: GitHub.