@google/genai 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
26
26
 
27
27
  /**
28
28
  * @license
29
- * Copyright 2024 Google LLC
29
+ * Copyright 2025 Google LLC
30
30
  * SPDX-License-Identifier: Apache-2.0
31
31
  */
32
32
  class BaseModule {
@@ -153,7 +153,7 @@ function getValueByPath(data, keys) {
153
153
 
154
154
  /**
155
155
  * @license
156
- * Copyright 2024 Google LLC
156
+ * Copyright 2025 Google LLC
157
157
  * SPDX-License-Identifier: Apache-2.0
158
158
  */
159
159
  function tModel(apiClient, model) {
@@ -521,14 +521,12 @@ function tFileName(apiClient, fromName) {
521
521
 
522
522
  /**
523
523
  * @license
524
- * Copyright 2024 Google LLC
524
+ * Copyright 2025 Google LLC
525
525
  * SPDX-License-Identifier: Apache-2.0
526
526
  */
527
527
  /**
528
528
  * @fileoverview Pagers for the GenAI List APIs.
529
529
  */
530
- // TODO(b/401555348): Re-enable linting after enforcing strong types.
531
- /* eslint-disable @typescript-eslint/no-explicit-any */
532
530
  var PagedItem;
533
531
  (function (PagedItem) {
534
532
  PagedItem["PAGED_ITEM_BATCH_JOBS"] = "batchJobs";
@@ -543,6 +541,7 @@ var PagedItem;
543
541
  class Pager {
544
542
  constructor(name, request, response, params) {
545
543
  this.pageInternal = [];
544
+ this.paramsInternal = {};
546
545
  this.requestInternal = request;
547
546
  this.init(name, response, params);
548
547
  }
@@ -699,7 +698,7 @@ class Pager {
699
698
 
700
699
  /**
701
700
  * @license
702
- * Copyright 2024 Google LLC
701
+ * Copyright 2025 Google LLC
703
702
  * SPDX-License-Identifier: Apache-2.0
704
703
  */
705
704
  // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
@@ -1288,7 +1287,7 @@ class SessionSendToolResponseParameters {
1288
1287
 
1289
1288
  /**
1290
1289
  * @license
1291
- * Copyright 2024 Google LLC
1290
+ * Copyright 2025 Google LLC
1292
1291
  * SPDX-License-Identifier: Apache-2.0
1293
1292
  */
1294
1293
  class Caches extends BaseModule {
@@ -1303,7 +1302,7 @@ class Caches extends BaseModule {
1303
1302
  *
1304
1303
  * @example
1305
1304
  * ```ts
1306
- * const cachedContents = await client.caches.list({config: {'pageSize': 2}});
1305
+ * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
1307
1306
  * for (const cachedContent of cachedContents) {
1308
1307
  * console.log(cachedContent);
1309
1308
  * }
@@ -1322,7 +1321,7 @@ class Caches extends BaseModule {
1322
1321
  * @example
1323
1322
  * ```ts
1324
1323
  * const contents = ...; // Initialize the content to cache.
1325
- * const response = await client.caches.create({
1324
+ * const response = await ai.caches.create({
1326
1325
  * model: 'gemini-2.0-flash',
1327
1326
  * config: {
1328
1327
  * 'contents': contents,
@@ -1393,7 +1392,7 @@ class Caches extends BaseModule {
1393
1392
  *
1394
1393
  * @example
1395
1394
  * ```ts
1396
- * await client.caches.get({name: 'gemini-1.5-flash'});
1395
+ * await ai.caches.get({name: 'gemini-1.5-flash'});
1397
1396
  * ```
1398
1397
  */
1399
1398
  async get(params) {
@@ -1456,7 +1455,7 @@ class Caches extends BaseModule {
1456
1455
  *
1457
1456
  * @example
1458
1457
  * ```ts
1459
- * await client.caches.delete({name: 'gemini-1.5-flash'});
1458
+ * await ai.caches.delete({name: 'gemini-1.5-flash'});
1460
1459
  * ```
1461
1460
  */
1462
1461
  async delete(params) {
@@ -1523,7 +1522,7 @@ class Caches extends BaseModule {
1523
1522
  *
1524
1523
  * @example
1525
1524
  * ```ts
1526
- * const response = await client.caches.update({
1525
+ * const response = await ai.caches.update({
1527
1526
  * name: 'gemini-1.5-flash',
1528
1527
  * config: {'ttl': '7600s'}
1529
1528
  * });
@@ -2527,7 +2526,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
2527
2526
 
2528
2527
  /**
2529
2528
  * @license
2530
- * Copyright 2024 Google LLC
2529
+ * Copyright 2025 Google LLC
2531
2530
  * SPDX-License-Identifier: Apache-2.0
2532
2531
  */
2533
2532
  /**
@@ -2632,16 +2631,35 @@ class Chats {
2632
2631
  /**
2633
2632
  * Creates a new chat session.
2634
2633
  *
2634
+ * @remarks
2635
+ * The config in the params will be used for all requests within the chat
2636
+ * session unless overridden by a per-request `config` in
2637
+ * {@link ./types.SendMessageParameters}.
2638
+ *
2635
2639
  * @param params - Parameters for creating a chat session.
2636
2640
  * @returns A new chat session.
2641
+ *
2642
+ * @example
2643
+ * ```ts
2644
+ * const chat = ai.chats.create({
2645
+ * model: 'gemini-2.0-flash'
2646
+ * config: {
2647
+ * temperature: 0.5,
2648
+ * maxOutputTokens: 1024,
2649
+ * }
2650
+ * });
2651
+ * ```
2637
2652
  */
2638
2653
  create(params) {
2639
2654
  return new Chat(this.apiClient, this.modelsModule, params.model, params.config, params.history);
2640
2655
  }
2641
2656
  }
2642
2657
  /**
2643
- * Chat session that enables sending messages and stores the chat history so
2644
- * far.
2658
+ * Chat session that enables sending messages to the model with previous
2659
+ * conversation context.
2660
+ *
2661
+ * @remarks
2662
+ * The session maintains all the turns between user and model.
2645
2663
  */
2646
2664
  class Chat {
2647
2665
  constructor(apiClient, modelsModule, model, config = {}, history = []) {
@@ -2665,6 +2683,15 @@ class Chat {
2665
2683
  * @see {@link Chat#sendMessageStream} for streaming method.
2666
2684
  * @param params - parameters for sending messages within a chat session.
2667
2685
  * @returns The model's response.
2686
+ *
2687
+ * @example
2688
+ * ```ts
2689
+ * const chat = ai.chats.create({model: 'gemini-2.0-flash'});
2690
+ * const response = await chat.sendMessage({
2691
+ * message: 'Why is the sky blue?'
2692
+ * });
2693
+ * console.log(response.text);
2694
+ * ```
2668
2695
  */
2669
2696
  async sendMessage(params) {
2670
2697
  var _a;
@@ -2696,6 +2723,17 @@ class Chat {
2696
2723
  * @see {@link Chat#sendMessage} for non-streaming method.
2697
2724
  * @param params - parameters for sending the message.
2698
2725
  * @return The model's response.
2726
+ *
2727
+ * @example
2728
+ * ```ts
2729
+ * const chat = ai.chats.create({model: 'gemini-2.0-flash'});
2730
+ * const response = await chat.sendMessageStream({
2731
+ * message: 'Why is the sky blue?'
2732
+ * });
2733
+ * for await (const chunk of response) {
2734
+ * console.log(chunk.text);
2735
+ * }
2736
+ * ```
2699
2737
  */
2700
2738
  async sendMessageStream(params) {
2701
2739
  var _a;
@@ -2787,7 +2825,7 @@ class Chat {
2787
2825
 
2788
2826
  /**
2789
2827
  * @license
2790
- * Copyright 2024 Google LLC
2828
+ * Copyright 2025 Google LLC
2791
2829
  * SPDX-License-Identifier: Apache-2.0
2792
2830
  */
2793
2831
  class Models extends BaseModule {
@@ -2817,14 +2855,12 @@ class Models extends BaseModule {
2817
2855
  *
2818
2856
  * Some models support multimodal input and output.
2819
2857
  *
2820
- * @param model - The model to use for generating content.
2821
- * @param contents - The input contents to use for generating content.
2822
- * @param [config] - The configuration for generating content.
2858
+ * @param params - The parameters for generating content.
2823
2859
  * @return The response from generating content.
2824
2860
  *
2825
2861
  * @example
2826
2862
  * ```ts
2827
- * const response = await client.models.generateContent({
2863
+ * const response = await ai.models.generateContent({
2828
2864
  * model: 'gemini-2.0-flash',
2829
2865
  * contents: 'why is the sky blue?',
2830
2866
  * config: {
@@ -2861,14 +2897,12 @@ class Models extends BaseModule {
2861
2897
  *
2862
2898
  * Some models support multimodal input and output.
2863
2899
  *
2864
- * @param model - The model to use for generating content.
2865
- * @param contents - The input contents to use for generating content.
2866
- * @param [config] - The configuration for generating content.
2900
+ * @param params - The parameters for generating content with streaming response.
2867
2901
  * @return The response from generating content.
2868
2902
  *
2869
2903
  * @example
2870
2904
  * ```ts
2871
- * const response = await client.models.generateContentStream({
2905
+ * const response = await ai.models.generateContentStream({
2872
2906
  * model: 'gemini-2.0-flash',
2873
2907
  * contents: 'why is the sky blue?',
2874
2908
  * config: {
@@ -3027,14 +3061,12 @@ class Models extends BaseModule {
3027
3061
  /**
3028
3062
  * Calculates embeddings for the given contents. Only text is supported.
3029
3063
  *
3030
- * @param model - The model to use.
3031
- * @param contents - The contents to embed.
3032
- * @param [config] - The config for embedding contents.
3064
+ * @param params - The parameters for embedding contents.
3033
3065
  * @return The response from the API.
3034
3066
  *
3035
3067
  * @example
3036
3068
  * ```ts
3037
- * const response = await client.models.embedContent({
3069
+ * const response = await ai.models.embedContent({
3038
3070
  * model: 'text-embedding-004',
3039
3071
  * contents: [
3040
3072
  * 'What is your name?',
@@ -3106,14 +3138,12 @@ class Models extends BaseModule {
3106
3138
  /**
3107
3139
  * Generates an image based on a text description and configuration.
3108
3140
  *
3109
- * @param model - The model to use.
3110
- * @param prompt - A text description of the image to generate.
3111
- * @param [config] - The config for image generation.
3141
+ * @param params - The parameters for generating images.
3112
3142
  * @return The response from the API.
3113
3143
  *
3114
3144
  * @example
3115
3145
  * ```ts
3116
- * const response = await client.models.generateImages({
3146
+ * const response = await ai.models.generateImages({
3117
3147
  * model: 'imagen-3.0-generate-002',
3118
3148
  * prompt: 'Robot holding a red skateboard',
3119
3149
  * config: {
@@ -3184,14 +3214,12 @@ class Models extends BaseModule {
3184
3214
  * Counts the number of tokens in the given contents. Multimodal input is
3185
3215
  * supported for Gemini models.
3186
3216
  *
3187
- * @param model - The model to use for counting tokens.
3188
- * @param contents - The contents to count tokens for.
3189
- * @param [config] - The config for counting tokens.
3217
+ * @param params - The parameters for counting tokens.
3190
3218
  * @return The response from the API.
3191
3219
  *
3192
3220
  * @example
3193
3221
  * ```ts
3194
- * const response = await client.models.countTokens({
3222
+ * const response = await ai.models.countTokens({
3195
3223
  * model: 'gemini-2.0-flash',
3196
3224
  * contents: 'The quick brown fox jumps over the lazy dog.'
3197
3225
  * });
@@ -3260,14 +3288,12 @@ class Models extends BaseModule {
3260
3288
  *
3261
3289
  * This method is not supported by the Gemini Developer API.
3262
3290
  *
3263
- * @param model - The model to use.
3264
- * @param contents - The content to compute tokens for.
3265
- * @param [config] - The config for computing tokens.
3291
+ * @param params - The parameters for computing tokens.
3266
3292
  * @return The response from the API.
3267
3293
  *
3268
3294
  * @example
3269
3295
  * ```ts
3270
- * const response = await client.models.computeTokens({
3296
+ * const response = await ai.models.computeTokens({
3271
3297
  * model: 'gemini-2.0-flash',
3272
3298
  * contents: 'What is your name?'
3273
3299
  * });
@@ -5246,7 +5272,7 @@ function computeTokensResponseFromVertex(apiClient, fromObject) {
5246
5272
 
5247
5273
  /**
5248
5274
  * @license
5249
- * Copyright 2024 Google LLC
5275
+ * Copyright 2025 Google LLC
5250
5276
  * SPDX-License-Identifier: Apache-2.0
5251
5277
  */
5252
5278
  const FUNCTION_RESPONSE_REQUIRES_ID = 'FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.';
@@ -5507,6 +5533,12 @@ function liveServerMessageFromVertex(apiClient, fromObject) {
5507
5533
  /**
5508
5534
  * Handles incoming messages from the WebSocket.
5509
5535
  *
5536
+ * @remarks
5537
+ * This function is responsible for parsing incoming messages, transforming them
5538
+ * into LiveServerMessages, and then calling the onmessage callback. Note that
5539
+ * the first message which is received from the server is a setupComplete
5540
+ * message.
5541
+ *
5510
5542
  * @param apiClient The ApiClient instance.
5511
5543
  * @param onmessage The user-provided onmessage callback (if any).
5512
5544
  * @param event The MessageEvent from the WebSocket.
@@ -5544,20 +5576,14 @@ class Live {
5544
5576
  Establishes a connection to the specified model with the given
5545
5577
  configuration and returns a Session object representing that connection.
5546
5578
 
5547
- > [!CAUTION] This SDK does not yet support the live API for **Google Vertex AI**.
5548
-
5549
5579
  @experimental
5550
5580
 
5551
- @param model - Model to use for the Live session.
5552
- @param config - Configuration parameters for the Live session.
5553
- @param callbacks - Optional callbacks for websocket events. If not
5554
- provided, default no-op callbacks will be used. Generally, prefer to
5555
- provide explicit callbacks to allow for proper handling of websocket
5556
- events (e.g. connection errors).
5581
+ @param params - The parameters for establishing a connection to the model.
5582
+ @return A live session.
5557
5583
 
5558
5584
  @example
5559
5585
  ```ts
5560
- const session = await client.live.connect({
5586
+ const session = await ai.live.connect({
5561
5587
  model: 'gemini-2.0-flash-exp',
5562
5588
  config: {
5563
5589
  responseModalities: [Modality.AUDIO],
@@ -5581,9 +5607,6 @@ class Live {
5581
5607
  */
5582
5608
  async connect(params) {
5583
5609
  var _a, _b;
5584
- if (this.apiClient.isVertexAI()) {
5585
- throw new Error('This SDK does not yet support the live API for **Google Vertex AI**.');
5586
- }
5587
5610
  const websocketBaseUrl = this.apiClient.getWebsocketBaseUrl();
5588
5611
  const apiVersion = this.apiClient.getApiVersion();
5589
5612
  let url;
@@ -5659,8 +5682,7 @@ class Session {
5659
5682
  if (params.turns !== null && params.turns !== undefined) {
5660
5683
  let contents = [];
5661
5684
  try {
5662
- contents =
5663
- tContents(apiClient, params.turns);
5685
+ contents = tContents(apiClient, params.turns);
5664
5686
  if (apiClient.isVertexAI()) {
5665
5687
  contents = contents.map((item) => contentToVertex(apiClient, item));
5666
5688
  }
@@ -5700,8 +5722,10 @@ class Session {
5700
5722
  throw new Error('functionResponses is required.');
5701
5723
  }
5702
5724
  for (const functionResponse of functionResponses) {
5703
- if (typeof functionResponse !== 'object' || functionResponse === null ||
5704
- !('name' in functionResponse) || !('response' in functionResponse)) {
5725
+ if (typeof functionResponse !== 'object' ||
5726
+ functionResponse === null ||
5727
+ !('name' in functionResponse) ||
5728
+ !('response' in functionResponse)) {
5705
5729
  throw new Error(`Could not parse function response, type '${typeof functionResponse}'.`);
5706
5730
  }
5707
5731
  if (!apiClient.isVertexAI() && !('id' in functionResponse)) {
@@ -5709,7 +5733,7 @@ class Session {
5709
5733
  }
5710
5734
  }
5711
5735
  const clientMessage = {
5712
- toolResponse: { functionResponses: functionResponses }
5736
+ toolResponse: { functionResponses: functionResponses },
5713
5737
  };
5714
5738
  return clientMessage;
5715
5739
  }
@@ -5827,7 +5851,7 @@ class Session {
5827
5851
 
5828
5852
  @example
5829
5853
  ```ts
5830
- const session = await client.live.connect({
5854
+ const session = await ai.live.connect({
5831
5855
  model: 'gemini-2.0-flash-exp',
5832
5856
  config: {
5833
5857
  responseModalities: [Modality.AUDIO],
@@ -5864,13 +5888,13 @@ function mapToHeaders(map) {
5864
5888
 
5865
5889
  /**
5866
5890
  * @license
5867
- * Copyright 2024 Google LLC
5891
+ * Copyright 2025 Google LLC
5868
5892
  * SPDX-License-Identifier: Apache-2.0
5869
5893
  */
5870
5894
  const CONTENT_TYPE_HEADER = 'Content-Type';
5871
5895
  const USER_AGENT_HEADER = 'User-Agent';
5872
5896
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
5873
- const SDK_VERSION = '0.2.0'; // x-release-please-version
5897
+ const SDK_VERSION = '0.3.1'; // x-release-please-version
5874
5898
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
5875
5899
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
5876
5900
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -6082,7 +6106,7 @@ class ApiClient {
6082
6106
  async unaryApiCall(url, requestInit, httpMethod) {
6083
6107
  return this.apiCall(url.toString(), Object.assign(Object.assign({}, requestInit), { method: httpMethod }))
6084
6108
  .then(async (response) => {
6085
- await throwErrorIfNotOK(response, url.toString());
6109
+ await throwErrorIfNotOK(response);
6086
6110
  return new HttpResponse(response);
6087
6111
  })
6088
6112
  .catch((e) => {
@@ -6097,7 +6121,7 @@ class ApiClient {
6097
6121
  async streamApiCall(url, requestInit, httpMethod) {
6098
6122
  return this.apiCall(url.toString(), Object.assign(Object.assign({}, requestInit), { method: httpMethod }))
6099
6123
  .then(async (response) => {
6100
- await throwErrorIfNotOK(response, url.toString());
6124
+ await throwErrorIfNotOK(response);
6101
6125
  return this.processStreamResponse(response);
6102
6126
  })
6103
6127
  .catch((e) => {
@@ -6242,7 +6266,7 @@ class ApiClient {
6242
6266
  return uploadUrl;
6243
6267
  }
6244
6268
  }
6245
- async function throwErrorIfNotOK(response, url, requestInit) {
6269
+ async function throwErrorIfNotOK(response) {
6246
6270
  var _a;
6247
6271
  if (response === undefined) {
6248
6272
  throw new ServerError('response is undefined');
@@ -6278,7 +6302,7 @@ async function throwErrorIfNotOK(response, url, requestInit) {
6278
6302
 
6279
6303
  /**
6280
6304
  * @license
6281
- * Copyright 2024 Google LLC
6305
+ * Copyright 2025 Google LLC
6282
6306
  * SPDX-License-Identifier: Apache-2.0
6283
6307
  */
6284
6308
  class Files extends BaseModule {
@@ -6296,7 +6320,7 @@ class Files extends BaseModule {
6296
6320
  * size of each page is 10.
6297
6321
  *
6298
6322
  * ```ts
6299
- * const listResponse = await client.files.list({config: {'pageSize': 10}});
6323
+ * const listResponse = await ai.files.list({config: {'pageSize': 10}});
6300
6324
  * for await (const file of listResponse) {
6301
6325
  * console.log(file.name);
6302
6326
  * }
@@ -6329,30 +6353,32 @@ class Files extends BaseModule {
6329
6353
  *
6330
6354
  * This section can contain multiple paragraphs and code examples.
6331
6355
  *
6332
- * @param file The string path to the file to be uploaded or a Blob object.
6333
- * @param config Optional parameters specified in the `types.UploadFileConfig`
6334
- * interface. Optional @see {@link types.UploadFileConfig}
6356
+ * @param params - Optional parameters specified in the
6357
+ * `common.UploadFileParameters` interface.
6358
+ * Optional @see {@link common.UploadFileParameters}
6335
6359
  * @return A promise that resolves to a `types.File` object.
6336
6360
  * @throws An error if called on a Vertex AI client.
6337
6361
  * @throws An error if the `mimeType` is not provided and can not be inferred,
6338
- * the `mimeType` can be provided in the `config` parameter.
6362
+ * the `mimeType` can be provided in the `params.config` parameter.
6339
6363
  * @throws An error occurs if a suitable upload location cannot be established.
6340
6364
  *
6341
6365
  * @example
6342
6366
  * The following code uploads a file to Gemini API.
6343
6367
  *
6344
6368
  * ```ts
6345
- * const file = await client.files.upload('file.txt', {
6369
+ * const file = await ai.files.upload({file: 'file.txt', config: {
6346
6370
  * mimeType: 'text/plain',
6347
- * });
6371
+ * }});
6348
6372
  * console.log(file.name);
6349
6373
  * ```
6350
6374
  */
6351
- async upload(file, config) {
6375
+ async upload(params) {
6352
6376
  if (this.apiClient.isVertexAI()) {
6353
6377
  throw new Error('Vertex AI does not support uploading files. You can share files through a GCS bucket.');
6354
6378
  }
6355
- return this.apiClient.uploadFile(file, config).then((response) => {
6379
+ return this.apiClient
6380
+ .uploadFile(params.file, params.config)
6381
+ .then((response) => {
6356
6382
  const file = fileFromMldev(this.apiClient, response);
6357
6383
  return file;
6358
6384
  });
@@ -6480,7 +6506,7 @@ class Files extends BaseModule {
6480
6506
  * const config: GetFileParameters = {
6481
6507
  * name: fileName,
6482
6508
  * };
6483
- * file = await client.files.get(config);
6509
+ * file = await ai.files.get(config);
6484
6510
  * console.log(file.name);
6485
6511
  * ```
6486
6512
  */
@@ -6904,7 +6930,7 @@ class NodeWebSocket {
6904
6930
  this.callbacks = callbacks;
6905
6931
  }
6906
6932
  connect() {
6907
- this.ws = new NodeWs__namespace.WebSocket(this.url, this.headers);
6933
+ this.ws = new NodeWs__namespace.WebSocket(this.url, { headers: this.headers });
6908
6934
  this.ws.onopen = this.callbacks.onopen;
6909
6935
  this.ws.onerror = this.callbacks.onerror;
6910
6936
  this.ws.onclose = this.callbacks.onclose;
@@ -7181,7 +7207,7 @@ class NodeUploader {
7181
7207
 
7182
7208
  /**
7183
7209
  * @license
7184
- * Copyright 2024 Google LLC
7210
+ * Copyright 2025 Google LLC
7185
7211
  * SPDX-License-Identifier: Apache-2.0
7186
7212
  */
7187
7213
  const LANGUAGE_LABEL_PREFIX = 'gl-node/';
@@ -7194,23 +7220,21 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
7194
7220
  *
7195
7221
  * The {@link GoogleGenAIOptions.vertexai} value determines which of the API services to use.
7196
7222
  *
7197
- * When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must be set,
7198
- * when using Vertex AI {@link GoogleGenAIOptions.project}
7199
- * and {@link GoogleGenAIOptions.location} must be set,
7200
- * and the {@link GoogleGenAIOptions.vertexai} must be set to `true`.
7223
+ * When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must also be set,
7224
+ * when using Vertex AI {@link GoogleGenAIOptions.project} and {@link GoogleGenAIOptions.location} must also be set.
7201
7225
  *
7202
7226
  * @example
7203
7227
  * Initializing the SDK for using the Gemini API:
7204
7228
  * ```ts
7205
7229
  * import {GoogleGenAI} from '@google/genai';
7206
- * const ai = genai.GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
7230
+ * const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
7207
7231
  * ```
7208
7232
  *
7209
7233
  * @example
7210
7234
  * Initializing the SDK for using the Vertex AI API:
7211
7235
  * ```ts
7212
7236
  * import {GoogleGenAI} from '@google/genai';
7213
- * const ai = genai.GoogleGenAI({
7237
+ * const ai = new GoogleGenAI({
7214
7238
  * vertexai: true,
7215
7239
  * project: 'PROJECT_ID',
7216
7240
  * location: 'PROJECT_LOCATION'
@@ -7220,7 +7244,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
7220
7244
  */
7221
7245
  class GoogleGenAI {
7222
7246
  constructor(options) {
7223
- var _a, _b, _c, _d, _e, _f;
7247
+ var _a, _b, _c, _d, _e;
7224
7248
  this.vertexai =
7225
7249
  (_b = (_a = options.vertexai) !== null && _a !== void 0 ? _a : getBooleanEnv('GOOGLE_GENAI_USE_VERTEXAI')) !== null && _b !== void 0 ? _b : false;
7226
7250
  // The tests currently assume that an API key is never set if vertexai is true.
@@ -7232,7 +7256,7 @@ class GoogleGenAI {
7232
7256
  this.project = (_d = options.project) !== null && _d !== void 0 ? _d : getEnv('GOOGLE_CLOUD_PROJECT');
7233
7257
  this.location = (_e = options.location) !== null && _e !== void 0 ? _e : getEnv('GOOGLE_CLOUD_LOCATION');
7234
7258
  this.apiVersion = options.apiVersion;
7235
- const auth = (_f = options.auth) !== null && _f !== void 0 ? _f : new NodeAuth({
7259
+ const auth = new NodeAuth({
7236
7260
  apiKey: this.apiKey,
7237
7261
  googleAuthOptions: options.googleAuthOptions,
7238
7262
  });