Google Gen AI SDK for Python 2.22

Last reviewed Sep 12, 2026

Export as PDF

Prompt Details

Prompt Composition

2prompts
  1. Python 3155 lines · 3.8K tokens
  2. 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=True with an explicit project and location for the Gemini Enterprise Agent Platform, or api_key for 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_key or credentials to genai.Client directly instead of relying on GOOGLE_API_KEY, GEMINI_API_KEY, GOOGLE_GENAI_USE_ENTERPRISE, or the legacy GOOGLE_GENAI_USE_VERTEXAI being configured correctly in every deployment.
  • Set only one of GOOGLE_API_KEY and GEMINI_API_KEY when you do use the environment, because GOOGLE_API_KEY silently wins and the SDK only warns.
  • Do not pass conflicting enterprise and vertexai values; 2.22 raises on the conflict, and vertexai is now only a legacy alias for enterprise.
  • 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