Google Gen AI SDK for Python 2.20

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.2060 lines · 1.5K tokens
Total215 lines · 5.3K tokens

CWE Coverage

  • 20
  • 23
  • 36
  • 59
  • 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
  • 829
  • 862
  • 916
  • 918
  • 941
  • 1104
  • 1333
  • 1395
  • 1426
  • 1427

Prompt Preview

Apply the Python 3 baseline first. These rules cover Google Gen AI SDK for Python 2.20 authentication modes, content construction, function calling, safety settings, structured output, files, caches, streaming, and operations.

Client mode and credentials

  • Select Gemini Developer API or Vertex AI mode in trusted server configuration and do not let request data change projects, locations, endpoints, or API versions.
  • Keep Gemini API keys server-side and prefer scoped workload identity for Vertex AI production workloads.
  • Separate projects, service accounts, quotas, and data boundaries across environments and mutually untrusted tenants.
  • Set types.HttpOptions(api_version='v1') when stable API behavior is required; the SDK otherwise selects beta endpoints, and a custom base_url can bypass normal project, location, and API-key checks.
  • Treat proxy and CA environment variables as configuration inputs because the default HTTPX and aiohttp clients use environment proxy discovery with trust_env=True.
  • Close synchronous and asynchronous clients and their transports deterministically.

Contents and system instructions

  • Keep trusted system_instruction content separate from user text, retrieved documents, tool results, and uploaded media.
  • Preserve Content roles and Part provenance instead of flattening all data into one prompt string.
  • Allowlist model names, generation parameters, safety settings, and token limits on the server.
  • Keep HttpOptions.extra_body in trusted configuration because it can overwrite serialized request fields after typed