@google/genai 1.14.0 → 1.16.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
@@ -339,6 +339,30 @@ if you are specifying those, you need to explicitly provide the full
339
339
  `Content[]` structure making it explicit which Parts are 'spoken' by the model,
340
340
  or the user. The SDK will throw an exception if you try this.
341
341
 
342
+ ## Error Handling
343
+
344
+ To handle errors raised by the API, the SDK provides this [ApiError](https://github.com/googleapis/js-genai/blob/main/src/errors.ts) class.
345
+
346
+ ```typescript
347
+ import {GoogleGenAI} from '@google/genai';
348
+ const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
349
+
350
+ const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY});
351
+
352
+ async function main() {
353
+ await ai.models.generateContent({
354
+ model: 'non-existent-model',
355
+ contents: 'Write a 100-word poem.',
356
+ }).catch((e) => {
357
+ console.error('error name: ', e.name);
358
+ console.error('error message: ', e.message);
359
+ console.error('error status: ', e.status);
360
+ });
361
+ }
362
+
363
+ main();
364
+ ```
365
+
342
366
  ## How is this different from the other Google AI SDKs
343
367
  This SDK (`@google/genai`) is Google Deepmind’s "vanilla" SDK for its generative
344
368
  AI offerings, and is where Google Deepmind adds new AI features.
package/dist/genai.d.ts CHANGED
@@ -817,6 +817,27 @@ export declare interface CancelBatchJobParameters {
817
817
  config?: CancelBatchJobConfig;
818
818
  }
819
819
 
820
+ /** Optional parameters for tunings.cancel method. */
821
+ export declare interface CancelTuningJobConfig {
822
+ /** Used to override HTTP request options. */
823
+ httpOptions?: HttpOptions;
824
+ /** Abort signal which can be used to cancel the request.
825
+
826
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
827
+ operation will not cancel the request in the service. You will still
828
+ be charged usage for any applicable operations.
829
+ */
830
+ abortSignal?: AbortSignal;
831
+ }
832
+
833
+ /** Parameters for the cancel method. */
834
+ export declare interface CancelTuningJobParameters {
835
+ /** The resource name of the tuning job. */
836
+ name: string;
837
+ /** Optional parameters for the request. */
838
+ config?: CancelTuningJobConfig;
839
+ }
840
+
820
841
  /** A response candidate generated from the model. */
821
842
  export declare interface Candidate {
822
843
  /** Contains the multi-part content of the response.
@@ -1561,6 +1582,8 @@ export declare interface DeleteCachedContentParameters {
1561
1582
 
1562
1583
  /** Empty response for caches.delete method. */
1563
1584
  export declare class DeleteCachedContentResponse {
1585
+ /** Used to retain the full HTTP response. */
1586
+ sdkHttpResponse?: HttpResponse;
1564
1587
  }
1565
1588
 
1566
1589
  /** Used to override the default configuration. */
@@ -1586,6 +1609,8 @@ export declare interface DeleteFileParameters {
1586
1609
 
1587
1610
  /** Response for the delete file method. */
1588
1611
  export declare class DeleteFileResponse {
1612
+ /** Used to retain the full HTTP response. */
1613
+ sdkHttpResponse?: HttpResponse;
1589
1614
  }
1590
1615
 
1591
1616
  /** Configuration for deleting a tuned model. */
@@ -1609,6 +1634,8 @@ export declare interface DeleteModelParameters {
1609
1634
  }
1610
1635
 
1611
1636
  export declare class DeleteModelResponse {
1637
+ /** Used to retain the full HTTP response. */
1638
+ sdkHttpResponse?: HttpResponse;
1612
1639
  }
1613
1640
 
1614
1641
  /** The return value of delete operation. */
@@ -1885,6 +1912,14 @@ export declare interface EnterpriseWebSearch {
1885
1912
  excludeDomains?: string[];
1886
1913
  }
1887
1914
 
1915
+ /** An entity representing the segmented area. */
1916
+ export declare interface EntityLabel {
1917
+ /** The label of the segmented entity. */
1918
+ label?: string;
1919
+ /** The confidence score of the detected label. */
1920
+ score?: number;
1921
+ }
1922
+
1888
1923
  /** The environment being operated. */
1889
1924
  export declare enum Environment {
1890
1925
  /**
@@ -2260,7 +2295,11 @@ export declare enum FunctionCallingConfigMode {
2260
2295
  /**
2261
2296
  * Model will not predict any function calls. Model behavior is same as when not passing any function declarations.
2262
2297
  */
2263
- NONE = "NONE"
2298
+ NONE = "NONE",
2299
+ /**
2300
+ * Model decides to predict either a function call or a natural language response, but will validate function calls with constrained decoding. If "allowed_function_names" are set, the predicted function call will be limited to any one of "allowed_function_names", else the predicted function call will be any one of the provided "function_declarations".
2301
+ */
2302
+ VALIDATED = "VALIDATED"
2264
2303
  }
2265
2304
 
2266
2305
  /** Defines a function that the model can generate JSON inputs for.
@@ -2702,6 +2741,14 @@ export declare interface GeneratedImage {
2702
2741
  enhancedPrompt?: string;
2703
2742
  }
2704
2743
 
2744
+ /** A generated image mask. */
2745
+ export declare interface GeneratedImageMask {
2746
+ /** The generated image mask. */
2747
+ mask?: Image_2;
2748
+ /** The detected entities on the segmented area. */
2749
+ labels?: EntityLabel[];
2750
+ }
2751
+
2705
2752
  /** A generated video. */
2706
2753
  export declare interface GeneratedVideo {
2707
2754
  /** The output video */
@@ -2840,11 +2887,17 @@ export declare interface GenerateVideosConfig {
2840
2887
  generateAudio?: boolean;
2841
2888
  /** Image to use as the last frame of generated videos. Only supported for image to video use cases. */
2842
2889
  lastFrame?: Image_2;
2890
+ /** The images to use as the references to generate the videos.
2891
+ If this field is provided, the text prompt field must also be provided.
2892
+ The image, video, or last_frame field are not supported. Each image must
2893
+ be associated with a type. Veo 2 supports up to 3 asset images *or* 1
2894
+ style image. */
2895
+ referenceImages?: VideoGenerationReferenceImage[];
2843
2896
  /** Compression quality of the generated videos. */
2844
2897
  compressionQuality?: VideoCompressionQuality;
2845
2898
  }
2846
2899
 
2847
- /** A video generation long-running operation. */
2900
+ /** A video generation operation. */
2848
2901
  export declare class GenerateVideosOperation implements Operation<GenerateVideosResponse> {
2849
2902
  /** 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}`. */
2850
2903
  name?: string;
@@ -2854,7 +2907,7 @@ export declare class GenerateVideosOperation implements Operation<GenerateVideos
2854
2907
  done?: boolean;
2855
2908
  /** The error result of the operation in case of failure or cancellation. */
2856
2909
  error?: Record<string, unknown>;
2857
- /** The response if the operation is successful. */
2910
+ /** The generated videos. */
2858
2911
  response?: GenerateVideosResponse;
2859
2912
  /** The full HTTP response. */
2860
2913
  sdkHttpResponse?: HttpResponse;
@@ -2878,6 +2931,8 @@ export declare interface GenerateVideosParameters {
2878
2931
  /** The input video for video extension use cases.
2879
2932
  Optional if prompt or image is provided. */
2880
2933
  video?: Video;
2934
+ /** A set of source input(s) for video generation. */
2935
+ source?: GenerateVideosSource;
2881
2936
  /** Configuration for generating videos. */
2882
2937
  config?: GenerateVideosConfig;
2883
2938
  }
@@ -2892,6 +2947,19 @@ export declare class GenerateVideosResponse {
2892
2947
  raiMediaFilteredReasons?: string[];
2893
2948
  }
2894
2949
 
2950
+ /** A set of source input(s) for video generation. */
2951
+ export declare interface GenerateVideosSource {
2952
+ /** The text prompt for generating the videos.
2953
+ Optional if image or video is provided. */
2954
+ prompt?: string;
2955
+ /** The input image for generating the videos.
2956
+ Optional if prompt or video is provided. */
2957
+ image?: Image_2;
2958
+ /** The input video for video extension use cases.
2959
+ Optional if prompt or image is provided. */
2960
+ video?: Video;
2961
+ }
2962
+
2895
2963
  /** Generation config. */
2896
2964
  export declare interface GenerationConfig {
2897
2965
  /** Optional. Config for model selection. */
@@ -3075,7 +3143,6 @@ export declare interface GetOperationParameters {
3075
3143
  config?: GetOperationConfig;
3076
3144
  }
3077
3145
 
3078
- /** Optional parameters for tunings.get method. */
3079
3146
  export declare interface GetTuningJobConfig {
3080
3147
  /** Used to override HTTP request options. */
3081
3148
  httpOptions?: HttpOptions;
@@ -4630,6 +4697,7 @@ export declare interface LiveServerSessionResumptionUpdate {
4630
4697
  lastConsumedClientMessageIndex?: string;
4631
4698
  }
4632
4699
 
4700
+ /** Sent in response to a `LiveGenerateContentSetup` message from the client. */
4633
4701
  export declare interface LiveServerSetupComplete {
4634
4702
  /** The session id of the live session. */
4635
4703
  sessionId?: string;
@@ -5028,7 +5096,9 @@ export declare class Models extends BaseModule {
5028
5096
  * ```ts
5029
5097
  * const operation = await ai.models.generateVideos({
5030
5098
  * model: 'veo-2.0-generate-001',
5031
- * prompt: 'A neon hologram of a cat driving at top speed',
5099
+ * source: {
5100
+ * prompt: 'A neon hologram of a cat driving at top speed',
5101
+ * },
5032
5102
  * config: {
5033
5103
  * numberOfVideos: 1
5034
5104
  * });
@@ -5127,6 +5197,27 @@ export declare class Models extends BaseModule {
5127
5197
  * ```
5128
5198
  */
5129
5199
  recontextImage(params: types.RecontextImageParameters): Promise<types.RecontextImageResponse>;
5200
+ /**
5201
+ * Segments an image, creating a mask of a specified area.
5202
+ *
5203
+ * @param params - The parameters for segmenting an image.
5204
+ * @return The response from the API.
5205
+ *
5206
+ * @example
5207
+ * ```ts
5208
+ * const response = await ai.models.segmentImage({
5209
+ * model: 'image-segmentation-001',
5210
+ * source: {
5211
+ * image: image,
5212
+ * },
5213
+ * config: {
5214
+ * mode: 'foreground',
5215
+ * },
5216
+ * });
5217
+ * console.log(response?.generatedMasks?.[0]?.mask?.imageBytes);
5218
+ * ```
5219
+ */
5220
+ segmentImage(params: types.SegmentImageParameters): Promise<types.SegmentImageResponse>;
5130
5221
  /**
5131
5222
  * Fetches information about a model by name.
5132
5223
  *
@@ -5293,10 +5384,10 @@ export declare interface OperationFromAPIResponseParameters {
5293
5384
 
5294
5385
  /** Parameters for the get method of the operations module. */
5295
5386
  export declare interface OperationGetParameters<T, U extends Operation<T>> {
5296
- /** The operation to be retrieved. */
5297
- operation: U;
5298
5387
  /** Used to override the default configuration. */
5299
5388
  config?: GetOperationConfig;
5389
+ /** The operation to be retrieved. */
5390
+ operation: U;
5300
5391
  }
5301
5392
 
5302
5393
  export declare class Operations extends BaseModule {
@@ -5695,6 +5786,8 @@ export declare interface RecontextImageConfig {
5695
5786
  /** Whether allow to generate person images, and restrict to specific
5696
5787
  ages. */
5697
5788
  personGeneration?: PersonGeneration;
5789
+ /** Whether to add a SynthID watermark to the generated images. */
5790
+ addWatermark?: boolean;
5698
5791
  /** MIME type of the generated image. */
5699
5792
  outputMimeType?: string;
5700
5793
  /** Compression quality of the generated image (for ``image/jpeg``
@@ -5969,6 +6062,12 @@ export declare interface Schema {
5969
6062
 
5970
6063
  export declare type SchemaUnion = Schema | unknown;
5971
6064
 
6065
+ /** An image mask representing a brush scribble. */
6066
+ export declare interface ScribbleImage {
6067
+ /** The brush scribble to guide segmentation. Valid for the interactive mode. */
6068
+ image?: Image_2;
6069
+ }
6070
+
5972
6071
  /** Google search entry point. */
5973
6072
  export declare interface SearchEntryPoint {
5974
6073
  /** Optional. Web content snippet that can be embedded in a web page or an app webview. */
@@ -5990,6 +6089,75 @@ export declare interface Segment {
5990
6089
  text?: string;
5991
6090
  }
5992
6091
 
6092
+ /** Configuration for segmenting an image. */
6093
+ export declare interface SegmentImageConfig {
6094
+ /** Used to override HTTP request options. */
6095
+ httpOptions?: HttpOptions;
6096
+ /** Abort signal which can be used to cancel the request.
6097
+
6098
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
6099
+ operation will not cancel the request in the service. You will still
6100
+ be charged usage for any applicable operations.
6101
+ */
6102
+ abortSignal?: AbortSignal;
6103
+ /** The segmentation mode to use. */
6104
+ mode?: SegmentMode;
6105
+ /** The maximum number of predictions to return up to, by top
6106
+ confidence score. */
6107
+ maxPredictions?: number;
6108
+ /** The confidence score threshold for the detections as a decimal
6109
+ value. Only predictions with a confidence score higher than this
6110
+ threshold will be returned. */
6111
+ confidenceThreshold?: number;
6112
+ /** A decimal value representing how much dilation to apply to the
6113
+ masks. 0 for no dilation. 1.0 means the masked area covers the whole
6114
+ image. */
6115
+ maskDilation?: number;
6116
+ /** The binary color threshold to apply to the masks. The threshold
6117
+ can be set to a decimal value between 0 and 255 non-inclusive.
6118
+ Set to -1 for no binary color thresholding. */
6119
+ binaryColorThreshold?: number;
6120
+ }
6121
+
6122
+ /** The parameters for segmenting an image. */
6123
+ export declare interface SegmentImageParameters {
6124
+ /** ID of the model to use. For a list of models, see `Google models
6125
+ <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models>`_. */
6126
+ model: string;
6127
+ /** A set of source input(s) for image segmentation. */
6128
+ source: SegmentImageSource;
6129
+ /** Configuration for image segmentation. */
6130
+ config?: SegmentImageConfig;
6131
+ }
6132
+
6133
+ /** The output images response. */
6134
+ export declare class SegmentImageResponse {
6135
+ /** List of generated image masks.
6136
+ */
6137
+ generatedMasks?: GeneratedImageMask[];
6138
+ }
6139
+
6140
+ /** A set of source input(s) for image segmentation. */
6141
+ export declare interface SegmentImageSource {
6142
+ /** A text prompt for guiding the model during image segmentation.
6143
+ Required for prompt mode and semantic mode, disallowed for other modes. */
6144
+ prompt?: string;
6145
+ /** The image to be segmented. */
6146
+ image?: Image_2;
6147
+ /** The brush scribble to guide segmentation.
6148
+ Required for the interactive mode, disallowed for other modes. */
6149
+ scribbleImage?: ScribbleImage;
6150
+ }
6151
+
6152
+ /** Enum that represents the segmentation mode. */
6153
+ export declare enum SegmentMode {
6154
+ FOREGROUND = "FOREGROUND",
6155
+ BACKGROUND = "BACKGROUND",
6156
+ PROMPT = "PROMPT",
6157
+ SEMANTIC = "SEMANTIC",
6158
+ INTERACTIVE = "INTERACTIVE"
6159
+ }
6160
+
5993
6161
  /** Parameters for sending a message within a chat session.
5994
6162
 
5995
6163
  These parameters are used with the `chat.sendMessage()` method.
@@ -6504,7 +6672,7 @@ export declare class Tokens extends BaseModule {
6504
6672
 
6505
6673
  /** Tokens info with a list of tokens and the corresponding list of token ids. */
6506
6674
  export declare interface TokensInfo {
6507
- /** Optional. Optional fields for the role from the corresponding Content. */
6675
+ /** Optional fields for the role from the corresponding Content. */
6508
6676
  role?: string;
6509
6677
  /** A list of token ids from the input. */
6510
6678
  tokenIds?: string[];
@@ -6771,6 +6939,18 @@ declare class Tunings extends BaseModule {
6771
6939
  tune: (params: types.CreateTuningJobParameters) => Promise<types.TuningJob>;
6772
6940
  private getInternal;
6773
6941
  private listInternal;
6942
+ /**
6943
+ * Cancels a tuning job.
6944
+ *
6945
+ * @param params - The parameters for the cancel request.
6946
+ * @return The empty response returned by the API.
6947
+ *
6948
+ * @example
6949
+ * ```ts
6950
+ * await ai.tunings.cancel({name: '...'}); // The server-generated resource name.
6951
+ * ```
6952
+ */
6953
+ cancel(params: types.CancelTuningJobParameters): Promise<void>;
6774
6954
  private tuneInternal;
6775
6955
  private tuneMldevInternal;
6776
6956
  }
@@ -6877,6 +7057,8 @@ declare namespace types {
6877
7057
  ControlReferenceType,
6878
7058
  SubjectReferenceType,
6879
7059
  EditMode,
7060
+ SegmentMode,
7061
+ VideoGenerationReferenceType,
6880
7062
  VideoCompressionQuality,
6881
7063
  FileState,
6882
7064
  FileSource,
@@ -7007,6 +7189,13 @@ declare namespace types {
7007
7189
  RecontextImageConfig,
7008
7190
  RecontextImageParameters,
7009
7191
  RecontextImageResponse,
7192
+ ScribbleImage,
7193
+ SegmentImageSource,
7194
+ SegmentImageConfig,
7195
+ SegmentImageParameters,
7196
+ EntityLabel,
7197
+ GeneratedImageMask,
7198
+ SegmentImageResponse,
7010
7199
  GetModelConfig,
7011
7200
  GetModelParameters,
7012
7201
  Endpoint,
@@ -7031,10 +7220,14 @@ declare namespace types {
7031
7220
  TokensInfo,
7032
7221
  ComputeTokensResponse,
7033
7222
  Video,
7223
+ GenerateVideosSource,
7224
+ VideoGenerationReferenceImage,
7034
7225
  GenerateVideosConfig,
7035
7226
  GenerateVideosParameters,
7036
7227
  GeneratedVideo,
7037
7228
  GenerateVideosResponse,
7229
+ Operation,
7230
+ GenerateVideosOperation,
7038
7231
  GetTuningJobConfig,
7039
7232
  GetTuningJobParameters,
7040
7233
  TunedModelCheckpoint,
@@ -7060,6 +7253,8 @@ declare namespace types {
7060
7253
  ListTuningJobsConfig,
7061
7254
  ListTuningJobsParameters,
7062
7255
  ListTuningJobsResponse,
7256
+ CancelTuningJobConfig,
7257
+ CancelTuningJobParameters,
7063
7258
  TuningExample,
7064
7259
  TuningDataset,
7065
7260
  TuningValidationDataset,
@@ -7140,10 +7335,7 @@ declare namespace types {
7140
7335
  LiveServerGoAway,
7141
7336
  LiveServerSessionResumptionUpdate,
7142
7337
  LiveServerMessage,
7143
- OperationGetParameters,
7144
7338
  OperationFromAPIResponseParameters,
7145
- Operation,
7146
- GenerateVideosOperation,
7147
7339
  AutomaticActivityDetection,
7148
7340
  RealtimeInputConfig,
7149
7341
  SessionResumptionConfig,
@@ -7187,6 +7379,7 @@ declare namespace types {
7187
7379
  LiveConnectConstraints,
7188
7380
  CreateAuthTokenConfig,
7189
7381
  CreateAuthTokenParameters,
7382
+ OperationGetParameters,
7190
7383
  CreateTuningJobParameters,
7191
7384
  BlobImageUnion,
7192
7385
  PartUnion,
@@ -7317,6 +7510,8 @@ export declare interface UpscaleImageConfig {
7317
7510
  be charged usage for any applicable operations.
7318
7511
  */
7319
7512
  abortSignal?: AbortSignal;
7513
+ /** Cloud Storage URI used to store the generated images. */
7514
+ outputGcsUri?: string;
7320
7515
  /** Whether to include a reason for filtered-out images in the
7321
7516
  response. */
7322
7517
  includeRaiReason?: boolean;
@@ -7495,6 +7690,31 @@ export declare enum VideoCompressionQuality {
7495
7690
  LOSSLESS = "LOSSLESS"
7496
7691
  }
7497
7692
 
7693
+ /** A reference image for video generation. */
7694
+ export declare interface VideoGenerationReferenceImage {
7695
+ /** The reference image.
7696
+ */
7697
+ image?: Image_2;
7698
+ /** The type of the reference image, which defines how the reference
7699
+ image will be used to generate the video. */
7700
+ referenceType?: VideoGenerationReferenceType;
7701
+ }
7702
+
7703
+ /** Enum for the reference type of a video generation reference image. */
7704
+ export declare enum VideoGenerationReferenceType {
7705
+ /**
7706
+ * A reference image that provides assets to the generated video,
7707
+ such as the scene, an object, a character, etc.
7708
+ */
7709
+ ASSET = "ASSET",
7710
+ /**
7711
+ * A reference image that provides aesthetics including colors,
7712
+ lighting, texture, etc., to be used as the style of the generated video,
7713
+ such as 'anime', 'photography', 'origami', etc.
7714
+ */
7715
+ STYLE = "STYLE"
7716
+ }
7717
+
7498
7718
  /** Describes how the video in the Part should be used by the model. */
7499
7719
  export declare interface VideoMetadata {
7500
7720
  /** The frame rate of the video sent to the model. If not specified, the