Google Gen AI SDK for Go 1

Last reviewed Oct 25, 2026

Export as PDF

Prompt Details

Prompt Composition

2prompts
  1. Go 1.27130 lines · 5.5K tokens
  2. Google Gen AI SDK for Go 147 lines · 2.6K tokens
Total177 lines · 8K tokens

CWE Coverage

  • 15
  • 20
  • 22
  • 59
  • 78
  • 79
  • 89
  • 94
  • 117
  • 190
  • 201
  • 208
  • 209
  • 250
  • 252
  • 257
  • 287
  • 294
  • 295
  • 307
  • 319
  • 323
  • 327
  • 338
  • 347
  • 352
  • 362
  • 367
  • 378
  • 426
  • 444
  • 488
  • 494
  • 532
  • 639
  • 732
  • 759
  • 770
  • 772
  • 807
  • 841
  • 862
  • 863
  • 915
  • 916
  • 918
  • 922
  • 942
  • 1004
  • 1275
  • 1395
  • 1426
  • 1427

Prompt Preview

Apply the Go 1.27 baseline first. These rules cover google.golang.org/genai 1.x, researched against v1.76.0. The module's Go 1.24 minimum is a build requirement, not a security-support promise. Check the selected backend, API version, and model before using a feature.

Client identity and outbound requests

  • Set ClientConfig.Backend explicitly and construct Project, Location, APIKey, and Credentials from trusted deployment configuration. Environment selection can change the backend or credential mode; use a dedicated client for each project and tenant trust boundary, with narrowly scoped Vertex IAM permissions.
  • Keep long-lived Gemini API keys on the server. Never log ClientConfig or constructor errors: the latter can print the configuration, including secrets. Treat the config and its maps as immutable after NewClient, which retains references to them.
  • When supplying ClientConfig.HTTPClient, configure its authentication transport deliberately for Vertex. The custom client path does not automatically wrap your client with default credentials; test the resulting identity and endpoint before deployment.
  • Allowlist HTTPS origins and paths for HTTPOptions.BaseURL, per-call overrides, environment-derived base URLs, and process-wide defaults. Reject redirects to unapproved destinations in HTTPClient.CheckRedirect; the SDK sends x-goog-api-key on requests, so a redirect can carry it outside the intended service.
  • Keep HTTPOptions.Headers, ExtraBody, and request providers under server control. Per-call options can replace routing, credentials,