Google Gen AI SDK for Python 2.22
Last reviewed Sep 12, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Google Gen AI SDK for Python 2.22119 lines · 3.5K tokens
Total274 lines · 7.3K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 79
- 89
- 95
- 117
- 201
- 208
- 209
- 214
- 250
- 295
- 306
- 319
- 328
- 338
- 347
- 367
- 379
- 409
- 416
- 426
- 427
- 470
- 502
- 524
- 532
- 611
- 639
- 674
- 732
- 770
- 772
- 776
- 807
- 829
- 862
- 916
- 918
- 941
- 1104
- 1333
- 1395
- 1426
- 1427
Prompt Preview
Apply the Python 3 baseline first. These rules cover google-genai 2.22.0 on Python 3.10 through 3.14: backend selection, endpoint and transport trust, function calling, MCP toolsets, the agent-platform interactions surface, webhooks, files, live sessions, and operations.
Client construction and backend selection
- Decide the backend in trusted server configuration:
enterprise=Truewith an explicitprojectandlocationfor the Gemini Enterprise Agent Platform, orapi_keyfor the Gemini Developer API. - Never let request data, model output, or tenant input choose the backend, project, location, or credential the client is built with.
- Prefer passing
api_keyorcredentialstogenai.Clientdirectly instead of relying onGOOGLE_API_KEY,GEMINI_API_KEY,GOOGLE_GENAI_USE_ENTERPRISE, or the legacyGOOGLE_GENAI_USE_VERTEXAIbeing configured correctly in every deployment. - Set only one of
GOOGLE_API_KEYandGEMINI_API_KEYwhen you do use the environment, becauseGOOGLE_API_KEYsilently wins and the SDK only warns. - Do not pass conflicting
enterpriseandvertexaivalues; 2.22 raises on the conflict, andvertexaiis now only a legacy alias forenterprise. - Use Application Default Credentials backed by a least-privilege service account for the enterprise backend rather than a long-lived API key.
- Give each environment and each mutually untrusted tenant its own project, credential, quota, and data boundary instead of one shared client.
- Close synchronous and asynchronous clients deterministically so pooled connections and aiohttp sessions