@google/genai 0.9.0 → 0.10.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
@@ -107,19 +107,19 @@ const ai = new GoogleGenAI({
107
107
  All API features are accessed through an instance of the `GoogleGenAI` classes.
108
108
  The submodules bundle together related API methods:
109
109
 
110
- - [`ai.models`](https://googleapis.github.io/js-genai/classes/models.Models.html):
110
+ - [`ai.models`](https://googleapis.github.io/js-genai/main/classes/models.Models.html):
111
111
  Use `models` to query models (`generateContent`, `generateImages`, ...), or
112
112
  examine their metadata.
113
- - [`ai.caches`](https://googleapis.github.io/js-genai/classes/caches.Caches.html):
113
+ - [`ai.caches`](https://googleapis.github.io/js-genai/main/classes/caches.Caches.html):
114
114
  Create and manage `caches` to reduce costs when repeatedly using the same
115
115
  large prompt prefix.
116
- - [`ai.chats`](https://googleapis.github.io/js-genai/classes/chats.Chats.html):
116
+ - [`ai.chats`](https://googleapis.github.io/js-genai/main/classes/chats.Chats.html):
117
117
  Create local stateful `chat` objects to simplify multi turn interactions.
118
- - [`ai.files`](https://googleapis.github.io/js-genai/classes/files.Files.html):
118
+ - [`ai.files`](https://googleapis.github.io/js-genai/main/classes/files.Files.html):
119
119
  Upload `files` to the API and reference them in your prompts.
120
120
  This reduces bandwidth if you use a file many times, and handles files too
121
121
  large to fit inline with your prompt.
122
- - [`ai.live`](https://googleapis.github.io/js-genai/classes/live.Live.html):
122
+ - [`ai.live`](https://googleapis.github.io/js-genai/main/classes/live.Live.html):
123
123
  Start a `live` session for real time interaction, allows text + audio + video
124
124
  input, and text or audio output.
125
125
 
@@ -212,6 +212,31 @@ async function main() {
212
212
  main();
213
213
  ```
214
214
 
215
+ ### Generate Content
216
+
217
+ #### How to structure `contents` argument for `generateContent`
218
+
219
+ The SDK allows you to specify the following types in the `contents` parameter:
220
+
221
+ #### Content
222
+
223
+ - `Content`: The SDK will wrap the singular `Content` instance in an array which
224
+ contains only the given content instance
225
+ - `Content[]`: No transformation happens
226
+
227
+ #### Part
228
+
229
+ Parts will be aggregated on a singular Content, with role 'user'.
230
+
231
+ - `Part | string`: The SDK will wrap the `string` or `Part` in a `Content`
232
+ instance with role 'user'.
233
+ - `Part[] | string[]`: The SDK will wrap the full provided list into a single
234
+ `Content` with role 'user'.
235
+
236
+ **_NOTE:_** This doesn't apply to `FunctionCall` and `FunctionResponse` parts,
237
+ if you are specifying those, you need to explicitly provide the full
238
+ `Content[]` structure making it explicit which Parts are 'spoken' by the model,
239
+ or the user. The SDK will throw an exception if you try this.
215
240
 
216
241
  ## Preview Launch
217
242
 
package/dist/genai.d.ts CHANGED
@@ -164,6 +164,14 @@ export declare interface AutomaticActivityDetection {
164
164
  declare class BaseModule {
165
165
  }
166
166
 
167
+ /**
168
+ * Parameters for setting the base URLs for the Gemini API and Vertex AI API.
169
+ */
170
+ export declare interface BaseUrlParameters {
171
+ geminiUrl?: string;
172
+ vertexUrl?: string;
173
+ }
174
+
167
175
  /** Content blob. */
168
176
  declare interface Blob_2 {
169
177
  /** Required. Raw bytes. */
@@ -173,6 +181,8 @@ declare interface Blob_2 {
173
181
  }
174
182
  export { Blob_2 as Blob }
175
183
 
184
+ export declare type BlobImageUnion = Blob_2;
185
+
176
186
  /** Output only. Blocked reason. */
177
187
  export declare enum BlockedReason {
178
188
  BLOCKED_REASON_UNSPECIFIED = "BLOCKED_REASON_UNSPECIFIED",
@@ -487,6 +497,13 @@ export declare interface CodeExecutionResult {
487
497
  export declare interface ComputeTokensConfig {
488
498
  /** Used to override HTTP request options. */
489
499
  httpOptions?: HttpOptions;
500
+ /** Abort signal which can be used to cancel the request.
501
+
502
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
503
+ operation will not cancel the request in the service. You will still
504
+ be charged usage for any applicable operations.
505
+ */
506
+ abortSignal?: AbortSignal;
490
507
  }
491
508
 
492
509
  /** Parameters for computing tokens. */
@@ -595,6 +612,13 @@ export declare enum ControlReferenceType {
595
612
  export declare interface CountTokensConfig {
596
613
  /** Used to override HTTP request options. */
597
614
  httpOptions?: HttpOptions;
615
+ /** Abort signal which can be used to cancel the request.
616
+
617
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
618
+ operation will not cancel the request in the service. You will still
619
+ be charged usage for any applicable operations.
620
+ */
621
+ abortSignal?: AbortSignal;
598
622
  /** Instructions for the model to steer it toward better performance.
599
623
  */
600
624
  systemInstruction?: ContentUnion;
@@ -631,6 +655,13 @@ export declare class CountTokensResponse {
631
655
  export declare interface CreateCachedContentConfig {
632
656
  /** Used to override HTTP request options. */
633
657
  httpOptions?: HttpOptions;
658
+ /** Abort signal which can be used to cancel the request.
659
+
660
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
661
+ operation will not cancel the request in the service. You will still
662
+ be charged usage for any applicable operations.
663
+ */
664
+ abortSignal?: AbortSignal;
634
665
  /** The TTL for this resource. The expiration time is computed: now + TTL. It is a duration string, with up to nine fractional digits, terminated by 's'. Example: "3.5s". */
635
666
  ttl?: string;
636
667
  /** Timestamp of when this resource is considered expired. Uses RFC 3339 format, Example: 2014-10-02T15:01:23Z. */
@@ -692,6 +723,13 @@ export declare interface CreateChatParameters {
692
723
  export declare interface CreateFileConfig {
693
724
  /** Used to override HTTP request options. */
694
725
  httpOptions?: HttpOptions;
726
+ /** Abort signal which can be used to cancel the request.
727
+
728
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
729
+ operation will not cancel the request in the service. You will still
730
+ be charged usage for any applicable operations.
731
+ */
732
+ abortSignal?: AbortSignal;
695
733
  }
696
734
 
697
735
  /** Generates the parameters for the private _create method. */
@@ -762,6 +800,13 @@ export declare function createUserContent(partOrString: PartListUnion | string):
762
800
  export declare interface DeleteCachedContentConfig {
763
801
  /** Used to override HTTP request options. */
764
802
  httpOptions?: HttpOptions;
803
+ /** Abort signal which can be used to cancel the request.
804
+
805
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
806
+ operation will not cancel the request in the service. You will still
807
+ be charged usage for any applicable operations.
808
+ */
809
+ abortSignal?: AbortSignal;
765
810
  }
766
811
 
767
812
  /** Parameters for caches.delete method. */
@@ -782,6 +827,13 @@ export declare class DeleteCachedContentResponse {
782
827
  export declare interface DeleteFileConfig {
783
828
  /** Used to override HTTP request options. */
784
829
  httpOptions?: HttpOptions;
830
+ /** Abort signal which can be used to cancel the request.
831
+
832
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
833
+ operation will not cancel the request in the service. You will still
834
+ be charged usage for any applicable operations.
835
+ */
836
+ abortSignal?: AbortSignal;
785
837
  }
786
838
 
787
839
  /** Generates the parameters for the get method. */
@@ -800,6 +852,13 @@ export declare class DeleteFileResponse {
800
852
  export declare interface DownloadFileConfig {
801
853
  /** Used to override HTTP request options. */
802
854
  httpOptions?: HttpOptions;
855
+ /** Abort signal which can be used to cancel the request.
856
+
857
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
858
+ operation will not cancel the request in the service. You will still
859
+ be charged usage for any applicable operations.
860
+ */
861
+ abortSignal?: AbortSignal;
803
862
  }
804
863
 
805
864
  /** Describes the options to customize dynamic retrieval. */
@@ -819,6 +878,13 @@ export declare enum DynamicRetrievalConfigMode {
819
878
  export declare interface EmbedContentConfig {
820
879
  /** Used to override HTTP request options. */
821
880
  httpOptions?: HttpOptions;
881
+ /** Abort signal which can be used to cancel the request.
882
+
883
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
884
+ operation will not cancel the request in the service. You will still
885
+ be charged usage for any applicable operations.
886
+ */
887
+ abortSignal?: AbortSignal;
822
888
  /** Type of task for which the embedding will be used.
823
889
  */
824
890
  taskType?: string;
@@ -908,6 +974,13 @@ export declare enum FeatureSelectionPreference {
908
974
  export declare interface FetchPredictOperationConfig {
909
975
  /** Used to override HTTP request options. */
910
976
  httpOptions?: HttpOptions;
977
+ /** Abort signal which can be used to cancel the request.
978
+
979
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
980
+ operation will not cancel the request in the service. You will still
981
+ be charged usage for any applicable operations.
982
+ */
983
+ abortSignal?: AbortSignal;
911
984
  }
912
985
 
913
986
  /** Parameters for the fetchPredictOperation method. */
@@ -1111,6 +1184,7 @@ export declare enum FinishReason {
1111
1184
  MAX_TOKENS = "MAX_TOKENS",
1112
1185
  SAFETY = "SAFETY",
1113
1186
  RECITATION = "RECITATION",
1187
+ LANGUAGE = "LANGUAGE",
1114
1188
  OTHER = "OTHER",
1115
1189
  BLOCKLIST = "BLOCKLIST",
1116
1190
  PROHIBITED_CONTENT = "PROHIBITED_CONTENT",
@@ -1182,6 +1256,13 @@ export declare class FunctionResponse {
1182
1256
  export declare interface GenerateContentConfig {
1183
1257
  /** Used to override HTTP request options. */
1184
1258
  httpOptions?: HttpOptions;
1259
+ /** Abort signal which can be used to cancel the request.
1260
+
1261
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1262
+ operation will not cancel the request in the service. You will still
1263
+ be charged usage for any applicable operations.
1264
+ */
1265
+ abortSignal?: AbortSignal;
1185
1266
  /** Instructions for the model to steer it toward better performance.
1186
1267
  For example, "Answer as concisely as possible" or "Don't use technical
1187
1268
  terms in your response".
@@ -1339,6 +1420,17 @@ export declare class GenerateContentResponse {
1339
1420
  * ```
1340
1421
  */
1341
1422
  get text(): string | undefined;
1423
+ /**
1424
+ * Returns the concatenation of all inline data parts from the first candidate
1425
+ * in the response.
1426
+ *
1427
+ * @remarks
1428
+ * If there are multiple candidates in the response, the inline data from the
1429
+ * first one will be returned. If there are non-inline data parts in the
1430
+ * response, the concatenation of all inline data parts will be returned, and
1431
+ * a warning will be logged.
1432
+ */
1433
+ get data(): string | undefined;
1342
1434
  /**
1343
1435
  * Returns the function calls from the first candidate in the response.
1344
1436
  *
@@ -1499,6 +1591,13 @@ export declare interface GeneratedVideo {
1499
1591
  export declare interface GenerateImagesConfig {
1500
1592
  /** Used to override HTTP request options. */
1501
1593
  httpOptions?: HttpOptions;
1594
+ /** Abort signal which can be used to cancel the request.
1595
+
1596
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1597
+ operation will not cancel the request in the service. You will still
1598
+ be charged usage for any applicable operations.
1599
+ */
1600
+ abortSignal?: AbortSignal;
1502
1601
  /** Cloud Storage URI used to store the generated images.
1503
1602
  */
1504
1603
  outputGcsUri?: string;
@@ -1580,6 +1679,13 @@ export declare class GenerateImagesResponse {
1580
1679
  export declare interface GenerateVideosConfig {
1581
1680
  /** Used to override HTTP request options. */
1582
1681
  httpOptions?: HttpOptions;
1682
+ /** Abort signal which can be used to cancel the request.
1683
+
1684
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1685
+ operation will not cancel the request in the service. You will still
1686
+ be charged usage for any applicable operations.
1687
+ */
1688
+ abortSignal?: AbortSignal;
1583
1689
  /** Number of output videos. */
1584
1690
  numberOfVideos?: number;
1585
1691
  /** The gcs bucket where to save the generated videos. */
@@ -1702,6 +1808,13 @@ export declare interface GenerationConfigRoutingConfigManualRoutingMode {
1702
1808
  export declare interface GetCachedContentConfig {
1703
1809
  /** Used to override HTTP request options. */
1704
1810
  httpOptions?: HttpOptions;
1811
+ /** Abort signal which can be used to cancel the request.
1812
+
1813
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1814
+ operation will not cancel the request in the service. You will still
1815
+ be charged usage for any applicable operations.
1816
+ */
1817
+ abortSignal?: AbortSignal;
1705
1818
  }
1706
1819
 
1707
1820
  /** Parameters for caches.get method. */
@@ -1718,6 +1831,13 @@ export declare interface GetCachedContentParameters {
1718
1831
  export declare interface GetFileConfig {
1719
1832
  /** Used to override HTTP request options. */
1720
1833
  httpOptions?: HttpOptions;
1834
+ /** Abort signal which can be used to cancel the request.
1835
+
1836
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1837
+ operation will not cancel the request in the service. You will still
1838
+ be charged usage for any applicable operations.
1839
+ */
1840
+ abortSignal?: AbortSignal;
1721
1841
  }
1722
1842
 
1723
1843
  /** Generates the parameters for the get method. */
@@ -1732,6 +1852,13 @@ export declare interface GetFileParameters {
1732
1852
  export declare interface GetModelConfig {
1733
1853
  /** Used to override HTTP request options. */
1734
1854
  httpOptions?: HttpOptions;
1855
+ /** Abort signal which can be used to cancel the request.
1856
+
1857
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1858
+ operation will not cancel the request in the service. You will still
1859
+ be charged usage for any applicable operations.
1860
+ */
1861
+ abortSignal?: AbortSignal;
1735
1862
  }
1736
1863
 
1737
1864
  export declare interface GetModelParameters {
@@ -1743,6 +1870,13 @@ export declare interface GetModelParameters {
1743
1870
  export declare interface GetOperationConfig {
1744
1871
  /** Used to override HTTP request options. */
1745
1872
  httpOptions?: HttpOptions;
1873
+ /** Abort signal which can be used to cancel the request.
1874
+
1875
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
1876
+ operation will not cancel the request in the service. You will still
1877
+ be charged usage for any applicable operations.
1878
+ */
1879
+ abortSignal?: AbortSignal;
1746
1880
  }
1747
1881
 
1748
1882
  /** Parameters for the GET method. */
@@ -2033,6 +2167,10 @@ declare interface HttpRequest {
2033
2167
  * Optional set of customizable configuration for HTTP requests.
2034
2168
  */
2035
2169
  httpOptions?: HttpOptions;
2170
+ /**
2171
+ * Optional abort signal which can be used to cancel the request.
2172
+ */
2173
+ abortSignal?: AbortSignal;
2036
2174
  }
2037
2175
 
2038
2176
  /** A wrapper class for the http response. */
@@ -2081,6 +2219,13 @@ export declare enum Language {
2081
2219
  export declare interface ListCachedContentsConfig {
2082
2220
  /** Used to override HTTP request options. */
2083
2221
  httpOptions?: HttpOptions;
2222
+ /** Abort signal which can be used to cancel the request.
2223
+
2224
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
2225
+ operation will not cancel the request in the service. You will still
2226
+ be charged usage for any applicable operations.
2227
+ */
2228
+ abortSignal?: AbortSignal;
2084
2229
  pageSize?: number;
2085
2230
  pageToken?: string;
2086
2231
  }
@@ -2103,6 +2248,13 @@ export declare class ListCachedContentsResponse {
2103
2248
  export declare interface ListFilesConfig {
2104
2249
  /** Used to override HTTP request options. */
2105
2250
  httpOptions?: HttpOptions;
2251
+ /** Abort signal which can be used to cancel the request.
2252
+
2253
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
2254
+ operation will not cancel the request in the service. You will still
2255
+ be charged usage for any applicable operations.
2256
+ */
2257
+ abortSignal?: AbortSignal;
2106
2258
  pageSize?: number;
2107
2259
  pageToken?: string;
2108
2260
  }
@@ -2247,6 +2399,22 @@ export declare interface LiveClientMessage {
2247
2399
  export declare interface LiveClientRealtimeInput {
2248
2400
  /** Inlined bytes data for media input. */
2249
2401
  mediaChunks?: Blob_2[];
2402
+ /** The realtime audio input stream. */
2403
+ audio?: Blob_2;
2404
+ /**
2405
+ Indicates that the audio stream has ended, e.g. because the microphone was
2406
+ turned off.
2407
+
2408
+ This should only be sent when automatic activity detection is enabled
2409
+ (which is the default).
2410
+
2411
+ The client can reopen the stream by sending an audio message.
2412
+ */
2413
+ audioStreamEnd?: boolean;
2414
+ /** The realtime video input stream. */
2415
+ video?: Blob_2;
2416
+ /** The realtime text input stream. */
2417
+ text?: string;
2250
2418
  /** Marks the start of user activity. */
2251
2419
  activityStart?: ActivityStart;
2252
2420
  /** Marks the end of user activity. */
@@ -2402,7 +2570,23 @@ export declare interface LiveSendClientContentParameters {
2402
2570
  /** Parameters for sending realtime input to the live API. */
2403
2571
  export declare interface LiveSendRealtimeInputParameters {
2404
2572
  /** Realtime input to send to the session. */
2405
- media: Blob_2;
2573
+ media?: BlobImageUnion;
2574
+ /** The realtime audio input stream. */
2575
+ audio?: Blob_2;
2576
+ /**
2577
+ Indicates that the audio stream has ended, e.g. because the microphone was
2578
+ turned off.
2579
+
2580
+ This should only be sent when automatic activity detection is enabled
2581
+ (which is the default).
2582
+
2583
+ The client can reopen the stream by sending an audio message.
2584
+ */
2585
+ audioStreamEnd?: boolean;
2586
+ /** The realtime video input stream. */
2587
+ video?: BlobImageUnion;
2588
+ /** The realtime text input stream. */
2589
+ text?: string;
2406
2590
  /** Marks the start of user activity. */
2407
2591
  activityStart?: ActivityStart;
2408
2592
  /** Marks the end of user activity. */
@@ -3351,7 +3535,6 @@ export declare class Session {
3351
3535
  private readonly apiClient;
3352
3536
  constructor(conn: WebSocket_2, apiClient: ApiClient);
3353
3537
  private tLiveClientContent;
3354
- private tLiveClientRealtimeInput;
3355
3538
  private tLiveClienttToolResponse;
3356
3539
  /**
3357
3540
  Send a message over the established connection.
@@ -3481,6 +3664,28 @@ export declare interface SessionResumptionConfig {
3481
3664
  transparent?: boolean;
3482
3665
  }
3483
3666
 
3667
+ /**
3668
+ * Overrides the base URLs for the Gemini API and Vertex AI API.
3669
+ *
3670
+ * @remarks This function should be called before initializing the SDK. If the
3671
+ * base URLs are set after initializing the SDK, the base URLs will not be
3672
+ * updated. Base URLs provided in the HttpOptions will also take precedence over
3673
+ * URLs set here.
3674
+ *
3675
+ * @example
3676
+ * ```ts
3677
+ * import {GoogleGenAI, setDefaultBaseUrls} from '@google/genai';
3678
+ * // Override the base URL for the Gemini API.
3679
+ * setDefaultBaseUrls({geminiUrl:'https://gemini.google.com'});
3680
+ *
3681
+ * // Override the base URL for the Vertex AI API.
3682
+ * setDefaultBaseUrls({vertexUrl: 'https://vertexai.googleapis.com'});
3683
+ *
3684
+ * const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
3685
+ * ```
3686
+ */
3687
+ export declare function setDefaultBaseUrls(baseUrlParams: BaseUrlParameters): void;
3688
+
3484
3689
  /** Context window will be truncated by keeping only suffix of it.
3485
3690
 
3486
3691
  Context window will always be cut at start of USER role turn. System
@@ -3909,6 +4114,7 @@ declare namespace types {
3909
4114
  LiveSendRealtimeInputParameters,
3910
4115
  LiveSendToolResponseParameters,
3911
4116
  OperationGetParameters,
4117
+ BlobImageUnion,
3912
4118
  PartUnion,
3913
4119
  PartListUnion,
3914
4120
  ContentUnion,
@@ -3923,6 +4129,13 @@ declare namespace types {
3923
4129
  export declare interface UpdateCachedContentConfig {
3924
4130
  /** Used to override HTTP request options. */
3925
4131
  httpOptions?: HttpOptions;
4132
+ /** Abort signal which can be used to cancel the request.
4133
+
4134
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
4135
+ operation will not cancel the request in the service. You will still
4136
+ be charged usage for any applicable operations.
4137
+ */
4138
+ abortSignal?: AbortSignal;
3926
4139
  /** The TTL for this resource. The expiration time is computed: now + TTL. It is a duration string, with up to nine fractional digits, terminated by 's'. Example: "3.5s". */
3927
4140
  ttl?: string;
3928
4141
  /** Timestamp of when this resource is considered expired. Uses RFC 3339 format, Example: 2014-10-02T15:01:23Z. */
@@ -3965,6 +4178,13 @@ declare interface Uploader {
3965
4178
  export declare interface UploadFileConfig {
3966
4179
  /** Used to override HTTP request options. */
3967
4180
  httpOptions?: HttpOptions;
4181
+ /** Abort signal which can be used to cancel the request.
4182
+
4183
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
4184
+ operation will not cancel the request in the service. You will still
4185
+ be charged usage for any applicable operations.
4186
+ */
4187
+ abortSignal?: AbortSignal;
3968
4188
  /** The name of the file in the destination (e.g., 'files/sample-image'. If not provided one will be generated. */
3969
4189
  name?: string;
3970
4190
  /** mime_type: The MIME type of the file. If not provided, it will be inferred from the file extension. */
@@ -3990,6 +4210,13 @@ export declare interface UploadFileParameters {
3990
4210
  export declare interface UpscaleImageConfig {
3991
4211
  /** Used to override HTTP request options. */
3992
4212
  httpOptions?: HttpOptions;
4213
+ /** Abort signal which can be used to cancel the request.
4214
+
4215
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
4216
+ operation will not cancel the request in the service. You will still
4217
+ be charged usage for any applicable operations.
4218
+ */
4219
+ abortSignal?: AbortSignal;
3993
4220
  /** Whether to include a reason for filtered-out images in the
3994
4221
  response. */
3995
4222
  includeRaiReason?: boolean;