Google Gen AI SDK for TypeScript 2.21

Last reviewed Sep 6, 2026

Export as PDF

Prompt Details

Prompt Composition

4prompts
  1. JavaScript ES2026102 lines · 3.1K tokens
  2. Node.js 24101 lines · 5.3K tokens
  3. TypeScript 746 lines · 1.5K tokens
  4. Google Gen AI SDK for TypeScript 2.2183 lines · 2.9K tokens
Total332 lines · 12.9K tokens

CWE Coverage

  • 20
  • 22
  • 59
  • 73
  • 78
  • 79
  • 88
  • 89
  • 94
  • 95
  • 113
  • 117
  • 200
  • 201
  • 208
  • 209
  • 214
  • 250
  • 287
  • 295
  • 297
  • 319
  • 323
  • 330
  • 338
  • 346
  • 347
  • 352
  • 354
  • 362
  • 367
  • 377
  • 426
  • 444
  • 459
  • 471
  • 488
  • 494
  • 502
  • 522
  • 524
  • 532
  • 602
  • 613
  • 639
  • 653
  • 732
  • 754
  • 770
  • 772
  • 807
  • 829
  • 838
  • 841
  • 862
  • 863
  • 908
  • 915
  • 916
  • 918
  • 922
  • 923
  • 942
  • 943
  • 1004
  • 1321
  • 1333
  • 1427

Prompt Preview

Apply the Node.js 24 and TypeScript 7 prompts first. These rules cover @google/genai 2.21 client construction, backend selection, prompt assembly, tools and function calling, safety controls, grounding and retrieval, files, caches, batches, live sessions, and ephemeral tokens. The package requires Node.js 20 or later; pin <3.0.0 if you cannot move to Node.js 22 when the 3.0 line ships.

Client construction and backend selection

  • Create GoogleGenAI once on the server from deployment configuration, and never let request data choose between the Gemini Developer API and the Gemini Enterprise Agent Platform (Vertex) backend.
  • Prefer the enterprise: true flag with fixed project and location over the older vertexai alias, and never set both to conflicting values — the constructor throws when they disagree.
  • Authenticate enterprise clients with googleAuthOptions or workload identity rather than an embedded key, and give the service account only the model, file, and cache permissions the workload actually calls.
  • Treat apiKey as a server-only secret. The web build accepts one, but a key in browser or mobile code is extractable; front the SDK with your own authenticated endpoint instead.
  • Pin httpOptions.apiVersion to the version whose behavior you tested. The client otherwise defaults to v1beta on the Gemini API and v1beta1 on the enterprise backend, so a default upgrade can change validation and field handling under you.
  • Keep httpOptions.baseUrl, baseUrlResourceScope, and headers in configuration. A base URL derived from user input sends