googleapis / googleapis/python-genai
generate_videos() and operations.get() have incompatible auth requirements
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
## Description
When using the `google-genai` SDK with `GOOGLE_GENAI_USE_VERTEXAI=True` in the environment, `generate_videos()` fails with:
> "This method is only supported in the Gemini Developer client."
However, when using the Developer client with API key auth, `generate_videos()` succeeds but the subsequent `operations.get()` polling call fails with:
> 401 UNAUTHENTICATED: "API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal."
This means there is no single client configuration that supports the full `generate_videos()` → `operations.get()` flow:
| Client Type | `generate_videos()` | `operations.get()` |
|---|---|---|
| `genai.Client(vertexai=True, ...)` | Fails ("Developer client only") | Would work (OAuth2) |
| `genai.Client(api_key=...)` | Works | Fails (401, needs OAuth2) |
| `genai.Client(project=..., location=...)` (no env var) | Works | Works (ADC) |
## The Problem
The third option works, but **only if `GOOGLE_GENAI_USE_VERTEXAI` is NOT set** in the environment. In production environments where this env var is `True` (for other Gemini services like image generation, transcription, etc.), there is no way to create a Developer client with ADC auth for video generation without temporarily mutating the environment variable.
There is no SDK parameter to override the env var behavior (e.g., `vertexai=False` forces API key mode, not ADC).
## Expected Behavior
One of:
1. `generate_videos()` should work with the Vertex AI client (`vertexai=True`)
2. OR `genai.Client(vertexai=False)` should support ADC auth (not just API key)
3. OR a parameter like `genai.Client(vertexai=None)` to explicitly ignore the env var
## Current Workaround
Temporarily removing the env var during client creation:
```python
env_val = os.environ.pop("GOOGLE_GENAI_USE_VERTEXAI", None)
try:
client = genai.Client(project=project, location=location)
finally:
if env_val is not None:
os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = env_val
```
This is fragile and not thread-safe.
## Environment
- `google-genai` >= 1.20.0
- Python 3.12
- Using Veo 3.1 (`veo-3.1-fast-generate-preview`)
- GCP project with service account (ADC via `GOOGLE_APPLICATION_CREDENTIALS`)
Contributor guide
Assessment
This issue has not been assessed yet.