BerriAI/litellm · error · ValueError
Google API key is required. Set GOOGLE_API_KEY or…
Error message
Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY environment variable.
What it means
Raised while building the URL for the Gemini Interactions API (POST /v1beta/interactions, used by litellm.interactions.create). GeminiModelInfo.get_api_key resolves litellm_params['api_key'], then the GOOGLE_API_KEY env var, then GEMINI_API_KEY; if all are empty the request is aborted before it starts. Note this path (unlike the image handlers) does accept GOOGLE_API_KEY.
Solutions
- export GOOGLE_API_KEY=... or GEMINI_API_KEY=... before starting the process
- Or pass api_key via litellm_params: litellm.interactions.create(..., api_key=KEY)
- Confirm with: python -c "from litellm.llms.gemini.common_utils import GeminiModelInfo; print(bool(GeminiModelInfo.get_api_key()))"
- In containers, verify the env var exists inside the running process (printenv)
Example fix
# before
r = litellm.interactions.create(model='gemini-2.5-flash', input={'text': 'hi'})
# ValueError: Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY environment variable.
# after
r = litellm.interactions.create(
model='gemini-2.5-flash',
input={'text': 'hi'},
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(), \
'interactions.create needs api_key or GOOGLE_API_KEY/GEMINI_API_KEY in env' Prevention
- Export GOOGLE_API_KEY/GEMINI_API_KEY in every service that creates interactions
- Pass api_key explicitly from your secret store rather than trusting ambient env
- Fail fast at startup with GeminiModelInfo.get_api_key() checks
When it happens
Trigger: litellm.interactions.create(model='gemini-2.5-flash', input=...) with no api_key in litellm_params and neither GOOGLE_API_KEY nor GEMINI_API_KEY in the environment; streaming creates hit the same check before the ?alt=sse URL is built.
Common situations: New Interactions-API integrations where env vars were wired for other providers only; serverless/cold-start processes missing env config; keys stored in a vault but not exported into the process.
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
- Google API key is required
- Either 'model' or 'agent' must be provided
- GEMINI_API_KEY is not set
- GEMINI_API_KEY is not set
- Gemini managed-agent endpoints require a caller-supplied…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/777981c528c26d78.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/gemini/interactions/transformation.py:116
headers["Api-Revision"] = "2026-05-20"
return headers
def get_complete_url(
self,
api_base: str | None,
model: str | None,
agent: str | None = None,
litellm_params: dict | None = None,
stream: bool | None = None,
) -> str:
"""POST /{api_version}/interactions"""
litellm_params = litellm_params or {}
api_base = GeminiModelInfo.get_api_base(api_base)
api_key: Final = GeminiModelInfo.get_api_key(litellm_params.get("api_key"))
if not api_key:
raise ValueError("Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY environment variable.")
if stream:
return f"{api_base}/{self.api_version}/interactions?alt=sse"
return f"{api_base}/{self.api_version}/interactions"
def transform_request(
self,
model: str | None,
agent: str | None,
input: InteractionInput | None,
optional_params: InteractionsAPIOptionalRequestParams,
litellm_params: GenericLiteLLMParams,
headers: dict,
) -> dict:
"""
Build request body per OpenAPI spec.
View on GitHub (pinned to 77b7c6c40c)