Google Gen AI SDK for Go 1
Last reviewed Oct 25, 2026
Prompt Details
Prompt Composition
2prompts
- Go 1.27130 lines · 5.5K tokens
- 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.Backendexplicitly and constructProject,Location,APIKey, andCredentialsfrom 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
ClientConfigor constructor errors: the latter can print the configuration, including secrets. Treat the config and its maps as immutable afterNewClient, 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 inHTTPClient.CheckRedirect; the SDK sendsx-goog-api-keyon 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,