BerriAI/litellm · error · ValueError

Google API key is required

Error message

Google API key is required

What it means

Raised by GoogleAIStudioInteractionsConfig.transform_get_interaction_request before a GET (and the sibling DELETE/CANCEL builders) on /v1beta/interactions/{id}. It resolves the key via GeminiModelInfo.get_api_key(litellm_params.api_key): explicit value, then GOOGLE_API_KEY, then GEMINI_API_KEY. If none is present the lookup URL is never built. Unlike the create-path error, this message carries no env-var hint.

Solutions

  1. export GOOGLE_API_KEY=... (or GEMINI_API_KEY) in every process that touches interactions, including pollers
  2. Or pass api_key on each get/delete/cancel call so it lands in litellm_params
  3. Share one key-resolution helper across your create and poll paths so they cannot drift
  4. Verify: python -c "from litellm.llms.gemini.common_utils import GeminiModelInfo; print(bool(GeminiModelInfo.get_api_key()))"

Example fix

# before
r = litellm.interactions.get(interaction_id=stored_id)
# ValueError: Google API key is required

# after
r = litellm.interactions.get(
    interaction_id=stored_id,
    api_key=os.environ['GOOGLE_API_KEY'],
)
Defensive patterns

Strategy: validation

Validate before calling

from litellm.llms.gemini.common_utils import GeminiModelInfo

assert GeminiModelInfo.get_api_key(), \
    'interaction get/delete/cancel needs api_key in litellm_params or GOOGLE_API_KEY/GEMINI_API_KEY'

Prevention

When it happens

Trigger: litellm.interactions.get / delete / cancel calls (polling a background interaction, cleaning up stored interaction ids) with no api_key in litellm_params and neither GOOGLE_API_KEY nor GEMINI_API_KEY exported.

Common situations: Poller/cleanup workers running in a different process (queue consumer, cron) than the creator and missing env config; storing interaction ids but not credentials context; serverless functions with sparse env.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/b2c4e7ea597919b0. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/gemini/interactions/transformation.py:280

        logging_obj: LiteLLMLoggingObj,
    ) -> InteractionsAPIStreamingResponse:
        """Parse streaming chunk."""
        verbose_logger.debug("Google AI Interactions streaming chunk: %s", parsed_chunk)
        return InteractionsAPIStreamingResponse(**parsed_chunk)

    # GET / DELETE / CANCEL - just build URLs, responses match spec directly

    def transform_get_interaction_request(
        self,
        interaction_id: str,
        api_base: str,
        litellm_params: GenericLiteLLMParams,
        headers: dict,
    ) -> tuple[str, dict]:
        """GET /{api_version}/interactions/{interaction_id}"""
        resolved_api_base: Final = GeminiModelInfo.get_api_base(api_base)
        if not GeminiModelInfo.get_api_key(litellm_params.api_key):
            raise ValueError("Google API key is required")
        encoded_interaction_id: Final = encode_url_path_segment(interaction_id, field_name="interaction_id")
        return (
            f"{resolved_api_base}/{self.api_version}/interactions/{encoded_interaction_id}",
            {},
        )

    def transform_get_interaction_response(
        self,
        raw_response: httpx.Response,
        logging_obj: LiteLLMLoggingObj,
    ) -> InteractionsAPIResponse:
        try:
            raw_json: Final = raw_response.json()
        except Exception:
            raise GeminiError(
                message=raw_response.text,
                status_code=raw_response.status_code,
                headers=dict(raw_response.headers),

View on GitHub (pinned to 77b7c6c40c)