@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.
@@ -99,7 +99,7 @@ declare interface ApiClientInitOptions {
99
99
 
100
100
  /**
101
101
  * @license
102
- * Copyright 2024 Google LLC
102
+ * Copyright 2025 Google LLC
103
103
  * SPDX-License-Identifier: Apache-2.0
104
104
  */
105
105
  /**
@@ -114,11 +114,6 @@ declare interface Auth {
114
114
  addAuthHeaders(headers: Headers): Promise<void>;
115
115
  }
116
116
 
117
- /**
118
- * @license
119
- * Copyright 2024 Google LLC
120
- * SPDX-License-Identifier: Apache-2.0
121
- */
122
117
  declare class BaseModule {
123
118
  }
124
119
 
@@ -182,7 +177,7 @@ export declare class Caches extends BaseModule {
182
177
  *
183
178
  * @example
184
179
  * ```ts
185
- * const cachedContents = await client.caches.list({config: {'pageSize': 2}});
180
+ * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
186
181
  * for (const cachedContent of cachedContents) {
187
182
  * console.log(cachedContent);
188
183
  * }
@@ -198,7 +193,7 @@ export declare class Caches extends BaseModule {
198
193
  * @example
199
194
  * ```ts
200
195
  * const contents = ...; // Initialize the content to cache.
201
- * const response = await client.caches.create({
196
+ * const response = await ai.caches.create({
202
197
  * model: 'gemini-2.0-flash',
203
198
  * config: {
204
199
  * 'contents': contents,
@@ -218,7 +213,7 @@ export declare class Caches extends BaseModule {
218
213
  *
219
214
  * @example
220
215
  * ```ts
221
- * await client.caches.get({name: 'gemini-1.5-flash'});
216
+ * await ai.caches.get({name: 'gemini-1.5-flash'});
222
217
  * ```
223
218
  */
224
219
  get(params: types.GetCachedContentParameters): Promise<types.CachedContent>;
@@ -230,7 +225,7 @@ export declare class Caches extends BaseModule {
230
225
  *
231
226
  * @example
232
227
  * ```ts
233
- * await client.caches.delete({name: 'gemini-1.5-flash'});
228
+ * await ai.caches.delete({name: 'gemini-1.5-flash'});
234
229
  * ```
235
230
  */
236
231
  delete(params: types.DeleteCachedContentParameters): Promise<types.DeleteCachedContentResponse>;
@@ -242,7 +237,7 @@ export declare class Caches extends BaseModule {
242
237
  *
243
238
  * @example
244
239
  * ```ts
245
- * const response = await client.caches.update({
240
+ * const response = await ai.caches.update({
246
241
  * name: 'gemini-1.5-flash',
247
242
  * config: {'ttl': '7600s'}
248
243
  * });
@@ -281,8 +276,11 @@ export declare interface Candidate {
281
276
  }
282
277
 
283
278
  /**
284
- * Chat session that enables sending messages and stores the chat history so
285
- * far.
279
+ * Chat session that enables sending messages to the model with previous
280
+ * conversation context.
281
+ *
282
+ * @remarks
283
+ * The session maintains all the turns between user and model.
286
284
  */
287
285
  export declare class Chat {
288
286
  private readonly apiClient;
@@ -302,6 +300,15 @@ export declare class Chat {
302
300
  * @see {@link Chat#sendMessageStream} for streaming method.
303
301
  * @param params - parameters for sending messages within a chat session.
304
302
  * @returns The model's response.
303
+ *
304
+ * @example
305
+ * ```ts
306
+ * const chat = ai.chats.create({model: 'gemini-2.0-flash'});
307
+ * const response = await chat.sendMessage({
308
+ * message: 'Why is the sky blue?'
309
+ * });
310
+ * console.log(response.text);
311
+ * ```
305
312
  */
306
313
  sendMessage(params: types.SendMessageParameters): Promise<types.GenerateContentResponse>;
307
314
  /**
@@ -314,6 +321,17 @@ export declare class Chat {
314
321
  * @see {@link Chat#sendMessage} for non-streaming method.
315
322
  * @param params - parameters for sending the message.
316
323
  * @return The model's response.
324
+ *
325
+ * @example
326
+ * ```ts
327
+ * const chat = ai.chats.create({model: 'gemini-2.0-flash'});
328
+ * const response = await chat.sendMessageStream({
329
+ * message: 'Why is the sky blue?'
330
+ * });
331
+ * for await (const chunk of response) {
332
+ * console.log(chunk.text);
333
+ * }
334
+ * ```
317
335
  */
318
336
  sendMessageStream(params: types.SendMessageParameters): Promise<AsyncGenerator<types.GenerateContentResponse>>;
319
337
  /**
@@ -354,8 +372,24 @@ export declare class Chats {
354
372
  /**
355
373
  * Creates a new chat session.
356
374
  *
375
+ * @remarks
376
+ * The config in the params will be used for all requests within the chat
377
+ * session unless overridden by a per-request `config` in
378
+ * {@link ./types.SendMessageParameters}.
379
+ *
357
380
  * @param params - Parameters for creating a chat session.
358
381
  * @returns A new chat session.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * const chat = ai.chats.create({
386
+ * model: 'gemini-2.0-flash'
387
+ * config: {
388
+ * temperature: 0.5,
389
+ * maxOutputTokens: 1024,
390
+ * }
391
+ * });
392
+ * ```
359
393
  */
360
394
  create(params: types.CreateChatParameters): Chat;
361
395
  }
@@ -393,6 +427,16 @@ export declare interface CodeExecutionResult {
393
427
  output?: string;
394
428
  }
395
429
 
430
+ declare namespace common {
431
+ export {
432
+ formatMap,
433
+ setValueByPath,
434
+ getValueByPath,
435
+ BaseModule,
436
+ UploadFileParameters
437
+ }
438
+ }
439
+
396
440
  /** Optional parameters for computing tokens. */
397
441
  export declare interface ComputeTokensConfig {
398
442
  /** Used to override HTTP request options. */
@@ -830,7 +874,7 @@ declare class Files extends BaseModule {
830
874
  * size of each page is 10.
831
875
  *
832
876
  * ```ts
833
- * const listResponse = await client.files.list({config: {'pageSize': 10}});
877
+ * const listResponse = await ai.files.list({config: {'pageSize': 10}});
834
878
  * for await (const file of listResponse) {
835
879
  * console.log(file.name);
836
880
  * }
@@ -860,26 +904,26 @@ declare class Files extends BaseModule {
860
904
  *
861
905
  * This section can contain multiple paragraphs and code examples.
862
906
  *
863
- * @param file The string path to the file to be uploaded or a Blob object.
864
- * @param config Optional parameters specified in the `types.UploadFileConfig`
865
- * interface. Optional @see {@link types.UploadFileConfig}
907
+ * @param params - Optional parameters specified in the
908
+ * `common.UploadFileParameters` interface.
909
+ * Optional @see {@link common.UploadFileParameters}
866
910
  * @return A promise that resolves to a `types.File` object.
867
911
  * @throws An error if called on a Vertex AI client.
868
912
  * @throws An error if the `mimeType` is not provided and can not be inferred,
869
- * the `mimeType` can be provided in the `config` parameter.
913
+ * the `mimeType` can be provided in the `params.config` parameter.
870
914
  * @throws An error occurs if a suitable upload location cannot be established.
871
915
  *
872
916
  * @example
873
917
  * The following code uploads a file to Gemini API.
874
918
  *
875
919
  * ```ts
876
- * const file = await client.files.upload('file.txt', {
920
+ * const file = await ai.files.upload({file: 'file.txt', config: {
877
921
  * mimeType: 'text/plain',
878
- * });
922
+ * }});
879
923
  * console.log(file.name);
880
924
  * ```
881
925
  */
882
- upload(file: string | Blob, config?: types.UploadFileConfig): Promise<types.File>;
926
+ upload(params: common.UploadFileParameters): Promise<types.File>;
883
927
  private listInternal;
884
928
  private createInternal;
885
929
  /**
@@ -893,7 +937,7 @@ declare class Files extends BaseModule {
893
937
  * const config: GetFileParameters = {
894
938
  * name: fileName,
895
939
  * };
896
- * file = await client.files.get(config);
940
+ * file = await ai.files.get(config);
897
941
  * console.log(file.name);
898
942
  * ```
899
943
  */
@@ -953,6 +997,8 @@ export declare enum FinishReason {
953
997
  MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL"
954
998
  }
955
999
 
1000
+ declare function formatMap(templateString: string, valueMap: Record<string, unknown>): string;
1001
+
956
1002
  /** A function call. */
957
1003
  export declare interface FunctionCall {
958
1004
  /** The unique id of the function call. If populated, the client to execute the
@@ -1461,6 +1507,8 @@ export declare interface GetFileParameters {
1461
1507
  config?: GetFileConfig;
1462
1508
  }
1463
1509
 
1510
+ declare function getValueByPath(data: unknown, keys: string[]): unknown;
1511
+
1464
1512
  /**
1465
1513
  * The Google GenAI SDK.
1466
1514
  *
@@ -1470,23 +1518,21 @@ export declare interface GetFileParameters {
1470
1518
  *
1471
1519
  * The {@link GoogleGenAIOptions.vertexai} value determines which of the API services to use.
1472
1520
  *
1473
- * When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must be set,
1474
- * when using Vertex AI {@link GoogleGenAIOptions.project}
1475
- * and {@link GoogleGenAIOptions.location} must be set,
1476
- * and the {@link GoogleGenAIOptions.vertexai} must be set to `true`.
1521
+ * When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must also be set,
1522
+ * when using Vertex AI {@link GoogleGenAIOptions.project} and {@link GoogleGenAIOptions.location} must also be set.
1477
1523
  *
1478
1524
  * @example
1479
1525
  * Initializing the SDK for using the Gemini API:
1480
1526
  * ```ts
1481
1527
  * import {GoogleGenAI} from '@google/genai';
1482
- * const ai = genai.GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
1528
+ * const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
1483
1529
  * ```
1484
1530
  *
1485
1531
  * @example
1486
1532
  * Initializing the SDK for using the Vertex AI API:
1487
1533
  * ```ts
1488
1534
  * import {GoogleGenAI} from '@google/genai';
1489
- * const ai = genai.GoogleGenAI({
1535
+ * const ai = new GoogleGenAI({
1490
1536
  * vertexai: true,
1491
1537
  * project: 'PROJECT_ID',
1492
1538
  * location: 'PROJECT_LOCATION'
@@ -1569,13 +1615,6 @@ export declare interface GoogleGenAIOptions {
1569
1615
  * Optional. A set of customizable configuration for HTTP requests.
1570
1616
  */
1571
1617
  httpOptions?: HttpOptions;
1572
- /**
1573
- * The object used for adding authentication headers to API requests.
1574
- *
1575
- * @remarks
1576
- * Only used for internal testing, will be removed in the future.
1577
- */
1578
- auth?: Auth;
1579
1618
  }
1580
1619
 
1581
1620
  /** Tool to support Google Search in Model. Powered by Google. */
@@ -1846,20 +1885,14 @@ export declare class Live {
1846
1885
  Establishes a connection to the specified model with the given
1847
1886
  configuration and returns a Session object representing that connection.
1848
1887
 
1849
- > [!CAUTION] This SDK does not yet support the live API for **Google Vertex AI**.
1850
-
1851
1888
  @experimental
1852
1889
 
1853
- @param model - Model to use for the Live session.
1854
- @param config - Configuration parameters for the Live session.
1855
- @param callbacks - Optional callbacks for websocket events. If not
1856
- provided, default no-op callbacks will be used. Generally, prefer to
1857
- provide explicit callbacks to allow for proper handling of websocket
1858
- events (e.g. connection errors).
1890
+ @param params - The parameters for establishing a connection to the model.
1891
+ @return A live session.
1859
1892
 
1860
1893
  @example
1861
1894
  ```ts
1862
- const session = await client.live.connect({
1895
+ const session = await ai.live.connect({
1863
1896
  model: 'gemini-2.0-flash-exp',
1864
1897
  config: {
1865
1898
  responseModalities: [Modality.AUDIO],
@@ -1886,10 +1919,10 @@ export declare class Live {
1886
1919
 
1887
1920
  /** Callbacks for the live API. */
1888
1921
  export declare interface LiveCallbacks {
1889
- onopen: (() => void) | null;
1922
+ onopen?: (() => void) | null;
1890
1923
  onmessage: (e: LiveServerMessage) => void;
1891
- onerror: ((e: ErrorEvent) => void) | null;
1892
- onclose: ((e: CloseEvent) => void) | null;
1924
+ onerror?: ((e: ErrorEvent) => void) | null;
1925
+ onclose?: ((e: CloseEvent) => void) | null;
1893
1926
  }
1894
1927
 
1895
1928
  /** Incremental update of the current conversation delivered from the client.
@@ -2184,14 +2217,12 @@ export declare class Models extends BaseModule {
2184
2217
  *
2185
2218
  * Some models support multimodal input and output.
2186
2219
  *
2187
- * @param model - The model to use for generating content.
2188
- * @param contents - The input contents to use for generating content.
2189
- * @param [config] - The configuration for generating content.
2220
+ * @param params - The parameters for generating content.
2190
2221
  * @return The response from generating content.
2191
2222
  *
2192
2223
  * @example
2193
2224
  * ```ts
2194
- * const response = await client.models.generateContent({
2225
+ * const response = await ai.models.generateContent({
2195
2226
  * model: 'gemini-2.0-flash',
2196
2227
  * contents: 'why is the sky blue?',
2197
2228
  * config: {
@@ -2226,14 +2257,12 @@ export declare class Models extends BaseModule {
2226
2257
  *
2227
2258
  * Some models support multimodal input and output.
2228
2259
  *
2229
- * @param model - The model to use for generating content.
2230
- * @param contents - The input contents to use for generating content.
2231
- * @param [config] - The configuration for generating content.
2260
+ * @param params - The parameters for generating content with streaming response.
2232
2261
  * @return The response from generating content.
2233
2262
  *
2234
2263
  * @example
2235
2264
  * ```ts
2236
- * const response = await client.models.generateContentStream({
2265
+ * const response = await ai.models.generateContentStream({
2237
2266
  * model: 'gemini-2.0-flash',
2238
2267
  * contents: 'why is the sky blue?',
2239
2268
  * config: {
@@ -2251,14 +2280,12 @@ export declare class Models extends BaseModule {
2251
2280
  /**
2252
2281
  * Calculates embeddings for the given contents. Only text is supported.
2253
2282
  *
2254
- * @param model - The model to use.
2255
- * @param contents - The contents to embed.
2256
- * @param [config] - The config for embedding contents.
2283
+ * @param params - The parameters for embedding contents.
2257
2284
  * @return The response from the API.
2258
2285
  *
2259
2286
  * @example
2260
2287
  * ```ts
2261
- * const response = await client.models.embedContent({
2288
+ * const response = await ai.models.embedContent({
2262
2289
  * model: 'text-embedding-004',
2263
2290
  * contents: [
2264
2291
  * 'What is your name?',
@@ -2275,14 +2302,12 @@ export declare class Models extends BaseModule {
2275
2302
  /**
2276
2303
  * Generates an image based on a text description and configuration.
2277
2304
  *
2278
- * @param model - The model to use.
2279
- * @param prompt - A text description of the image to generate.
2280
- * @param [config] - The config for image generation.
2305
+ * @param params - The parameters for generating images.
2281
2306
  * @return The response from the API.
2282
2307
  *
2283
2308
  * @example
2284
2309
  * ```ts
2285
- * const response = await client.models.generateImages({
2310
+ * const response = await ai.models.generateImages({
2286
2311
  * model: 'imagen-3.0-generate-002',
2287
2312
  * prompt: 'Robot holding a red skateboard',
2288
2313
  * config: {
@@ -2298,14 +2323,12 @@ export declare class Models extends BaseModule {
2298
2323
  * Counts the number of tokens in the given contents. Multimodal input is
2299
2324
  * supported for Gemini models.
2300
2325
  *
2301
- * @param model - The model to use for counting tokens.
2302
- * @param contents - The contents to count tokens for.
2303
- * @param [config] - The config for counting tokens.
2326
+ * @param params - The parameters for counting tokens.
2304
2327
  * @return The response from the API.
2305
2328
  *
2306
2329
  * @example
2307
2330
  * ```ts
2308
- * const response = await client.models.countTokens({
2331
+ * const response = await ai.models.countTokens({
2309
2332
  * model: 'gemini-2.0-flash',
2310
2333
  * contents: 'The quick brown fox jumps over the lazy dog.'
2311
2334
  * });
@@ -2319,14 +2342,12 @@ export declare class Models extends BaseModule {
2319
2342
  *
2320
2343
  * This method is not supported by the Gemini Developer API.
2321
2344
  *
2322
- * @param model - The model to use.
2323
- * @param contents - The content to compute tokens for.
2324
- * @param [config] - The config for computing tokens.
2345
+ * @param params - The parameters for computing tokens.
2325
2346
  * @return The response from the API.
2326
2347
  *
2327
2348
  * @example
2328
2349
  * ```ts
2329
- * const response = await client.models.computeTokens({
2350
+ * const response = await ai.models.computeTokens({
2330
2351
  * model: 'gemini-2.0-flash',
2331
2352
  * contents: 'What is your name?'
2332
2353
  * });
@@ -2338,7 +2359,7 @@ export declare class Models extends BaseModule {
2338
2359
 
2339
2360
  /**
2340
2361
  * @license
2341
- * Copyright 2024 Google LLC
2362
+ * Copyright 2025 Google LLC
2342
2363
  * SPDX-License-Identifier: Apache-2.0
2343
2364
  */
2344
2365
  export declare enum Outcome {
@@ -2350,7 +2371,7 @@ export declare enum Outcome {
2350
2371
 
2351
2372
  /**
2352
2373
  * @license
2353
- * Copyright 2024 Google LLC
2374
+ * Copyright 2025 Google LLC
2354
2375
  * SPDX-License-Identifier: Apache-2.0
2355
2376
  */
2356
2377
  /**
@@ -2364,6 +2385,22 @@ declare enum PagedItem {
2364
2385
  PAGED_ITEM_CACHED_CONTENTS = "cachedContents"
2365
2386
  }
2366
2387
 
2388
+ declare interface PagedItemConfig {
2389
+ config?: {
2390
+ pageToken?: string;
2391
+ pageSize?: number;
2392
+ };
2393
+ }
2394
+
2395
+ declare interface PagedItemResponse<T> {
2396
+ nextPageToken?: string;
2397
+ batchJobs?: T[];
2398
+ models?: T[];
2399
+ tuningJobs?: T[];
2400
+ files?: T[];
2401
+ cachedContents?: T[];
2402
+ }
2403
+
2367
2404
  /**
2368
2405
  * Pager class for iterating through paginated results.
2369
2406
  */
@@ -2372,9 +2409,9 @@ declare class Pager<T> implements AsyncIterable<T> {
2372
2409
  private pageInternal;
2373
2410
  private paramsInternal;
2374
2411
  private pageInternalSize;
2375
- protected requestInternal: (params: any) => any;
2412
+ protected requestInternal: (params: PagedItemConfig) => Promise<PagedItemResponse<T>>;
2376
2413
  protected idxInternal: number;
2377
- constructor(name: PagedItem, request: (params: any) => any, response: any, params: any);
2414
+ constructor(name: PagedItem, request: (params: PagedItemConfig) => Promise<PagedItemResponse<T>>, response: PagedItemResponse<T>, params: PagedItemConfig);
2378
2415
  private init;
2379
2416
  private initNextPage;
2380
2417
  /**
@@ -2404,7 +2441,7 @@ declare class Pager<T> implements AsyncIterable<T> {
2404
2441
  * used to customize the API request. For example, the `pageToken` parameter
2405
2442
  * contains the token to request the next page.
2406
2443
  */
2407
- get params(): any;
2444
+ get params(): PagedItemConfig;
2408
2445
  /**
2409
2446
  * Returns the total number of items in the current page.
2410
2447
  */
@@ -2796,7 +2833,7 @@ export declare class Session {
2796
2833
 
2797
2834
  @example
2798
2835
  ```ts
2799
- const session = await client.live.connect({
2836
+ const session = await ai.live.connect({
2800
2837
  model: 'gemini-2.0-flash-exp',
2801
2838
  config: {
2802
2839
  responseModalities: [Modality.AUDIO],
@@ -2831,6 +2868,8 @@ export declare class SessionSendToolResponseParameters {
2831
2868
  functionResponses: FunctionResponse | FunctionResponse[];
2832
2869
  }
2833
2870
 
2871
+ declare function setValueByPath(data: Record<string, unknown>, keys: string[], value: unknown): void;
2872
+
2834
2873
  /** The speech generation configuration. */
2835
2874
  export declare interface SpeechConfig {
2836
2875
  /** The configuration for the speaker to use.
@@ -3225,6 +3264,14 @@ export declare interface UploadFileConfig {
3225
3264
  displayName?: string;
3226
3265
  }
3227
3266
 
3267
+ /** Parameters for the upload file method. */
3268
+ declare interface UploadFileParameters {
3269
+ /** The string path to the file to be uploaded or a Blob object. */
3270
+ file: string | Blob;
3271
+ /** Configuration that contains optional parameters. */
3272
+ config?: UploadFileConfig;
3273
+ }
3274
+
3228
3275
  /** Configuration for upscaling an image.
3229
3276
 
3230
3277
  For more information on this configuration, refer to