@google/genai 1.9.0 → 1.11.0

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.
package/README.md CHANGED
@@ -218,10 +218,10 @@ main();
218
218
 
219
219
  ### Function Calling
220
220
 
221
- To let Gemini to interact with external systems, you can provide provide
221
+ To let Gemini to interact with external systems, you can provide
222
222
  `functionDeclaration` objects as `tools`. To use these tools it's a 4 step
223
223
 
224
- 1. **Declare the function name, description, and parameters**
224
+ 1. **Declare the function name, description, and parametersJsonSchema**
225
225
  2. **Call `generateContent` with function calling enabled**
226
226
  3. **Use the returned `FunctionCall` parameters to call your actual function**
227
227
  3. **Send the result back to the model (with history, easier in `ai.chat`)
@@ -234,19 +234,14 @@ const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
234
234
  async function main() {
235
235
  const controlLightDeclaration: FunctionDeclaration = {
236
236
  name: 'controlLight',
237
- parameters: {
238
- type: Type.OBJECT,
239
- description: 'Set the brightness and color temperature of a room light.',
240
- properties: {
237
+ parametersJsonSchema: {
238
+ type: 'object',
239
+ properties:{
241
240
  brightness: {
242
- type: Type.NUMBER,
243
- description:
244
- 'Light level from 0 to 100. Zero is off and 100 is full brightness.',
241
+ type:'number',
245
242
  },
246
243
  colorTemperature: {
247
- type: Type.STRING,
248
- description:
249
- 'Color temperature of the light fixture which can be `daylight`, `cool`, or `warm`.',
244
+ type:'string',
250
245
  },
251
246
  },
252
247
  required: ['brightness', 'colorTemperature'],
package/dist/genai.d.ts CHANGED
@@ -560,6 +560,8 @@ export declare interface BatchJobDestination {
560
560
  inlinedResponses?: InlinedResponse[];
561
561
  }
562
562
 
563
+ export declare type BatchJobDestinationUnion = BatchJobDestination | string;
564
+
563
565
  /** Config for `src` parameter. */
564
566
  export declare interface BatchJobSource {
565
567
  /** Storage format of the input files. Must be one of:
@@ -1229,7 +1231,7 @@ export declare interface CreateBatchJobConfig {
1229
1231
  /** GCS or BigQuery URI prefix for the output predictions. Example:
1230
1232
  "gs://path/to/output/data" or "bq://projectId.bqDatasetId.bqTableId".
1231
1233
  */
1232
- dest?: string;
1234
+ dest?: BatchJobDestinationUnion;
1233
1235
  }
1234
1236
 
1235
1237
  /** Config for batches.create parameters. */
@@ -1745,6 +1747,9 @@ export declare interface EditImageConfig {
1745
1747
  only).
1746
1748
  */
1747
1749
  outputCompressionQuality?: number;
1750
+ /** Whether to add a watermark to the generated images.
1751
+ */
1752
+ addWatermark?: boolean;
1748
1753
  /** Describes the editing mode for the request. */
1749
1754
  editMode?: EditMode;
1750
1755
  /** The number of sampling steps. A higher value has better image
@@ -2480,6 +2485,8 @@ export declare interface GenerateContentParameters {
2480
2485
 
2481
2486
  /** Response message for PredictionService.GenerateContent. */
2482
2487
  export declare class GenerateContentResponse {
2488
+ /** Used to retain the full HTTP response. */
2489
+ sdkHttpResponse?: HttpResponse;
2483
2490
  /** Response variations returned by the model.
2484
2491
  */
2485
2492
  candidates?: Candidate[];
@@ -2748,6 +2755,10 @@ export declare interface GenerateImagesConfig {
2748
2755
  /** Whether to add a watermark to the generated images.
2749
2756
  */
2750
2757
  addWatermark?: boolean;
2758
+ /** The size of the largest dimension of the generated image.
2759
+ Supported sizes are 1K and 2K (not supported for Imagen 3 models).
2760
+ */
2761
+ imageSize?: string;
2751
2762
  /** Whether to use the prompt rewriting logic.
2752
2763
  */
2753
2764
  enhancePrompt?: boolean;
@@ -2800,7 +2811,7 @@ export declare interface GenerateVideosConfig {
2800
2811
  seed?: number;
2801
2812
  /** The aspect ratio for the generated video. 16:9 (landscape) and 9:16 (portrait) are supported. */
2802
2813
  aspectRatio?: string;
2803
- /** The resolution for the generated video. 1280x720, 1920x1080 are supported. */
2814
+ /** The resolution for the generated video. 720p and 1080p are supported. */
2804
2815
  resolution?: string;
2805
2816
  /** Whether allow to generate person videos, and restrict to specific ages. Supported values are: dont_allow, allow_adult. */
2806
2817
  personGeneration?: string;
@@ -2818,8 +2829,8 @@ export declare interface GenerateVideosConfig {
2818
2829
  compressionQuality?: VideoCompressionQuality;
2819
2830
  }
2820
2831
 
2821
- /** A video generation operation. */
2822
- export declare interface GenerateVideosOperation {
2832
+ /** A video generation long-running operation. */
2833
+ export declare class GenerateVideosOperation implements Operation<GenerateVideosResponse> {
2823
2834
  /** The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`. */
2824
2835
  name?: string;
2825
2836
  /** Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any. */
@@ -2828,8 +2839,13 @@ export declare interface GenerateVideosOperation {
2828
2839
  done?: boolean;
2829
2840
  /** The error result of the operation in case of failure or cancellation. */
2830
2841
  error?: Record<string, unknown>;
2831
- /** The generated videos. */
2842
+ /** The response if the operation is successful. */
2832
2843
  response?: GenerateVideosResponse;
2844
+ /**
2845
+ * Instantiates an Operation of the same type as the one being called with the fields set from the API response.
2846
+ * @internal
2847
+ */
2848
+ _fromAPIResponse({ apiResponse, isVertexAI, }: OperationFromAPIResponseParameters): Operation<GenerateVideosResponse>;
2833
2849
  }
2834
2850
 
2835
2851
  /** Class that represents the parameters for generating videos. */
@@ -3415,7 +3431,10 @@ export declare interface HttpOptions {
3415
3431
  headers?: Record<string, string>;
3416
3432
  /** Timeout for the request in milliseconds. */
3417
3433
  timeout?: number;
3418
- /** Extra parameters to add to the request body. */
3434
+ /** Extra parameters to add to the request body.
3435
+ The structure must match the backend API's request structure.
3436
+ - VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
3437
+ - GeminiAPI backend API docs: https://ai.google.dev/api/rest */
3419
3438
  extraBody?: Record<string, unknown>;
3420
3439
  }
3421
3440
 
@@ -3680,6 +3699,8 @@ export declare interface ListBatchJobsParameters {
3680
3699
 
3681
3700
  /** Config for batches.list return value. */
3682
3701
  export declare class ListBatchJobsResponse {
3702
+ /** Used to retain the full HTTP response. */
3703
+ sdkHttpResponse?: HttpResponse;
3683
3704
  nextPageToken?: string;
3684
3705
  batchJobs?: BatchJob[];
3685
3706
  }
@@ -3707,6 +3728,8 @@ export declare interface ListCachedContentsParameters {
3707
3728
  }
3708
3729
 
3709
3730
  export declare class ListCachedContentsResponse {
3731
+ /** Used to retain the full HTTP response. */
3732
+ sdkHttpResponse?: HttpResponse;
3710
3733
  nextPageToken?: string;
3711
3734
  /** List of cached contents.
3712
3735
  */
@@ -3736,6 +3759,8 @@ export declare interface ListFilesParameters {
3736
3759
 
3737
3760
  /** Response for the list files method. */
3738
3761
  export declare class ListFilesResponse {
3762
+ /** Used to retain the full HTTP response. */
3763
+ sdkHttpResponse?: HttpResponse;
3739
3764
  /** A token to retrieve next page of results. */
3740
3765
  nextPageToken?: string;
3741
3766
  /** The list of files. */
@@ -3764,6 +3789,8 @@ export declare interface ListModelsParameters {
3764
3789
  }
3765
3790
 
3766
3791
  export declare class ListModelsResponse {
3792
+ /** Used to retain the full HTTP response. */
3793
+ sdkHttpResponse?: HttpResponse;
3767
3794
  nextPageToken?: string;
3768
3795
  models?: Model[];
3769
3796
  }
@@ -3791,6 +3818,8 @@ export declare interface ListTuningJobsParameters {
3791
3818
 
3792
3819
  /** Response for the list tuning jobs method. */
3793
3820
  export declare class ListTuningJobsResponse {
3821
+ /** Used to retain the full HTTP response. */
3822
+ sdkHttpResponse?: HttpResponse;
3794
3823
  /** A token to retrieve the next page of results. Pass to ListTuningJobsRequest.page_token to obtain that page. */
3795
3824
  nextPageToken?: string;
3796
3825
  /** List of TuningJobs in the requested page. */
@@ -4849,7 +4878,7 @@ export declare class Models extends BaseModule {
4849
4878
  * modify the original params. Also sets the MCP usage header if there are
4850
4879
  * MCP tools in the parameters.
4851
4880
  */
4852
- private processParamsForMcpUsage;
4881
+ private processParamsMaybeAddMcpUsage;
4853
4882
  private initAfcToolsMap;
4854
4883
  private processAfcStream;
4855
4884
  /**
@@ -4915,6 +4944,30 @@ export declare class Models extends BaseModule {
4915
4944
  * ```
4916
4945
  */
4917
4946
  upscaleImage: (params: types.UpscaleImageParameters) => Promise<types.UpscaleImageResponse>;
4947
+ /**
4948
+ * Generates videos based on a text description and configuration.
4949
+ *
4950
+ * @param params - The parameters for generating videos.
4951
+ * @return A Promise<GenerateVideosOperation> which allows you to track the progress and eventually retrieve the generated videos using the operations.get method.
4952
+ *
4953
+ * @example
4954
+ * ```ts
4955
+ * const operation = await ai.models.generateVideos({
4956
+ * model: 'veo-2.0-generate-001',
4957
+ * prompt: 'A neon hologram of a cat driving at top speed',
4958
+ * config: {
4959
+ * numberOfVideos: 1
4960
+ * });
4961
+ *
4962
+ * while (!operation.done) {
4963
+ * await new Promise(resolve => setTimeout(resolve, 10000));
4964
+ * operation = await ai.operations.getVideosOperation({operation: operation});
4965
+ * }
4966
+ *
4967
+ * console.log(operation.response?.generatedVideos?.[0]?.video?.uri);
4968
+ * ```
4969
+ */
4970
+ generateVideos: (params: types.GenerateVideosParameters) => Promise<types.GenerateVideosOperation>;
4918
4971
  private generateContentInternal;
4919
4972
  private generateContentStreamInternal;
4920
4973
  /**
@@ -5060,7 +5113,7 @@ export declare class Models extends BaseModule {
5060
5113
  * console.log(operation.response?.generatedVideos?.[0]?.video?.uri);
5061
5114
  * ```
5062
5115
  */
5063
- generateVideos(params: types.GenerateVideosParameters): Promise<types.GenerateVideosOperation>;
5116
+ private generateVideosInternal;
5064
5117
  }
5065
5118
 
5066
5119
  /** Config for model selection. */
@@ -5076,7 +5129,7 @@ export declare interface MultiSpeakerVoiceConfig {
5076
5129
  }
5077
5130
 
5078
5131
  /** A long-running operation. */
5079
- export declare interface Operation {
5132
+ export declare interface Operation<T> {
5080
5133
  /** The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`. */
5081
5134
  name?: string;
5082
5135
  /** Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any. */
@@ -5085,12 +5138,27 @@ export declare interface Operation {
5085
5138
  done?: boolean;
5086
5139
  /** The error result of the operation in case of failure or cancellation. */
5087
5140
  error?: Record<string, unknown>;
5141
+ /** The response if the operation is successful. */
5142
+ response?: T;
5143
+ /**
5144
+ * Instantiates an Operation of the same type as the one being called with the fields set from the API response.
5145
+ * @internal
5146
+ */
5147
+ _fromAPIResponse({ apiResponse, isVertexAI, }: OperationFromAPIResponseParameters): Operation<T>;
5148
+ }
5149
+
5150
+ /** Parameters of the fromAPIResponse method of the Operation class. */
5151
+ export declare interface OperationFromAPIResponseParameters {
5152
+ /** The API response to be converted to an Operation. */
5153
+ apiResponse: Record<string, unknown>;
5154
+ /** Whether the API response is from Vertex AI. */
5155
+ isVertexAI: boolean;
5088
5156
  }
5089
5157
 
5090
5158
  /** Parameters for the get method of the operations module. */
5091
- export declare interface OperationGetParameters {
5159
+ export declare interface OperationGetParameters<T, U extends Operation<T>> {
5092
5160
  /** The operation to be retrieved. */
5093
- operation: GenerateVideosOperation;
5161
+ operation: U;
5094
5162
  /** Used to override the default configuration. */
5095
5163
  config?: GetOperationConfig;
5096
5164
  }
@@ -5104,7 +5172,14 @@ export declare class Operations extends BaseModule {
5104
5172
  * @param parameters The parameters for the get operation request.
5105
5173
  * @return The updated Operation object, with the latest status or result.
5106
5174
  */
5107
- getVideosOperation(parameters: types.OperationGetParameters): Promise<types.GenerateVideosOperation>;
5175
+ getVideosOperation(parameters: types.OperationGetParameters<types.GenerateVideosResponse, types.GenerateVideosOperation>): Promise<types.GenerateVideosOperation>;
5176
+ /**
5177
+ * Gets the status of a long-running operation.
5178
+ *
5179
+ * @param parameters The parameters for the get operation request.
5180
+ * @return The updated Operation object, with the latest status or result.
5181
+ */
5182
+ get<T, U extends types.Operation<T>>(parameters: types.OperationGetParameters<T, U>): Promise<types.Operation<T>>;
5108
5183
  private getVideosOperationInternal;
5109
5184
  private fetchPredictVideosOperationInternal;
5110
5185
  }
@@ -5129,14 +5204,6 @@ export declare enum Outcome {
5129
5204
  OUTCOME_DEADLINE_EXCEEDED = "OUTCOME_DEADLINE_EXCEEDED"
5130
5205
  }
5131
5206
 
5132
- /**
5133
- * @license
5134
- * Copyright 2025 Google LLC
5135
- * SPDX-License-Identifier: Apache-2.0
5136
- */
5137
- /**
5138
- * Pagers for the GenAI List APIs.
5139
- */
5140
5207
  export declare enum PagedItem {
5141
5208
  PAGED_ITEM_BATCH_JOBS = "batchJobs",
5142
5209
  PAGED_ITEM_MODELS = "models",
@@ -5154,6 +5221,7 @@ declare interface PagedItemConfig {
5154
5221
 
5155
5222
  declare interface PagedItemResponse<T> {
5156
5223
  nextPageToken?: string;
5224
+ sdkHttpResponse?: types.HttpResponse;
5157
5225
  batchJobs?: T[];
5158
5226
  models?: T[];
5159
5227
  tuningJobs?: T[];
@@ -5169,6 +5237,7 @@ export declare class Pager<T> implements AsyncIterable<T> {
5169
5237
  private pageInternal;
5170
5238
  private paramsInternal;
5171
5239
  private pageInternalSize;
5240
+ private sdkHttpResponseInternal?;
5172
5241
  protected requestInternal: (params: PagedItemConfig) => Promise<PagedItemResponse<T>>;
5173
5242
  protected idxInternal: number;
5174
5243
  constructor(name: PagedItem, request: (params: PagedItemConfig) => Promise<PagedItemResponse<T>>, response: PagedItemResponse<T>, params: PagedItemConfig);
@@ -5193,6 +5262,10 @@ export declare class Pager<T> implements AsyncIterable<T> {
5193
5262
  * The number of items in the page is less than or equal to the page length.
5194
5263
  */
5195
5264
  get pageSize(): number;
5265
+ /**
5266
+ * Returns the headers of the API response.
5267
+ */
5268
+ get sdkHttpResponse(): types.HttpResponse | undefined;
5196
5269
  /**
5197
5270
  * Returns the parameters when making the API request for the next page.
5198
5271
  *
@@ -6386,6 +6459,18 @@ export declare interface TuningJob {
6386
6459
  tunedModelDisplayName?: string;
6387
6460
  }
6388
6461
 
6462
+ /** A long-running operation. */
6463
+ export declare interface TuningOperation {
6464
+ /** The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`. */
6465
+ name?: string;
6466
+ /** Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any. */
6467
+ metadata?: Record<string, unknown>;
6468
+ /** If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available. */
6469
+ done?: boolean;
6470
+ /** The error result of the operation in case of failure or cancellation. */
6471
+ error?: Record<string, unknown>;
6472
+ }
6473
+
6389
6474
  declare class Tunings extends BaseModule {
6390
6475
  private readonly apiClient;
6391
6476
  constructor(apiClient: ApiClient);
@@ -6674,7 +6759,6 @@ declare namespace types {
6674
6759
  GenerateVideosParameters,
6675
6760
  GeneratedVideo,
6676
6761
  GenerateVideosResponse,
6677
- GenerateVideosOperation,
6678
6762
  GetTuningJobConfig,
6679
6763
  GetTuningJobParameters,
6680
6764
  TunedModelCheckpoint,
@@ -6703,7 +6787,7 @@ declare namespace types {
6703
6787
  TuningValidationDataset,
6704
6788
  CreateTuningJobConfig,
6705
6789
  CreateTuningJobParameters,
6706
- Operation,
6790
+ TuningOperation,
6707
6791
  CreateCachedContentConfig,
6708
6792
  CreateCachedContentParameters,
6709
6793
  CachedContentUsageMetadata,
@@ -6778,6 +6862,10 @@ declare namespace types {
6778
6862
  LiveServerGoAway,
6779
6863
  LiveServerSessionResumptionUpdate,
6780
6864
  LiveServerMessage,
6865
+ OperationGetParameters,
6866
+ OperationFromAPIResponseParameters,
6867
+ Operation,
6868
+ GenerateVideosOperation,
6781
6869
  AutomaticActivityDetection,
6782
6870
  RealtimeInputConfig,
6783
6871
  SessionResumptionConfig,
@@ -6821,7 +6909,6 @@ declare namespace types {
6821
6909
  LiveConnectConstraints,
6822
6910
  CreateAuthTokenConfig,
6823
6911
  CreateAuthTokenParameters,
6824
- OperationGetParameters,
6825
6912
  BlobImageUnion,
6826
6913
  PartUnion,
6827
6914
  PartListUnion,
@@ -6832,7 +6919,8 @@ declare namespace types {
6832
6919
  ToolUnion,
6833
6920
  ToolListUnion,
6834
6921
  DownloadableFileUnion,
6835
- BatchJobSourceUnion
6922
+ BatchJobSourceUnion,
6923
+ BatchJobDestinationUnion
6836
6924
  }
6837
6925
  }
6838
6926