@google/genai 1.2.0 → 1.4.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 +42 -1
- package/dist/genai.d.ts +141 -24
- package/dist/index.cjs +1115 -157
- package/dist/index.mjs +1115 -158
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +1120 -158
- package/dist/node/index.mjs +1120 -159
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +141 -24
- package/dist/web/index.mjs +1115 -158
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +141 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,21 @@ The Google Gen AI SDK is designed to work with Gemini 2.0 features.
|
|
|
21
21
|
|
|
22
22
|
## Prerequisites
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
1. Node.js version 20 or later
|
|
25
|
+
|
|
26
|
+
### The following are required for Vertex AI users (excluding Vertex AI Studio)
|
|
27
|
+
1. [Select](https://console.cloud.google.com/project) or [create](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) a Google Cloud project.
|
|
28
|
+
1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
|
|
29
|
+
1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
|
|
30
|
+
1. [Configure authentication](https://cloud.google.com/docs/authentication) for your project.
|
|
31
|
+
* [Install the gcloud CLI](https://cloud.google.com/sdk/docs/install).
|
|
32
|
+
* [Initialize the gcloud CLI](https://cloud.google.com/sdk/docs/initializing).
|
|
33
|
+
* Create local authentication credentials for your user account:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
gcloud auth application-default login
|
|
37
|
+
```
|
|
38
|
+
A list of accepted authentication options are listed in [GoogleAuthOptions](https://github.com/googleapis/google-auth-library-nodejs/blob/3ae120d0a45c95e36c59c9ac8286483938781f30/src/auth/googleauth.ts#L87) interface of google-auth-library-node.js GitHub repo.
|
|
25
39
|
|
|
26
40
|
## Installation
|
|
27
41
|
|
|
@@ -98,6 +112,33 @@ const ai = new GoogleGenAI({
|
|
|
98
112
|
});
|
|
99
113
|
```
|
|
100
114
|
|
|
115
|
+
### (Optional) (NodeJS only) Using environment variables:
|
|
116
|
+
|
|
117
|
+
For NodeJS environments, you can create a client by configuring the necessary
|
|
118
|
+
environment variables. Configuration setup instructions depends on whether
|
|
119
|
+
you're using the Gemini Developer API or the Gemini API in Vertex AI.
|
|
120
|
+
|
|
121
|
+
**Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
export GOOGLE_API_KEY='your-api-key'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`,
|
|
128
|
+
`GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`, as shown below:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
export GOOGLE_GENAI_USE_VERTEXAI=true
|
|
132
|
+
export GOOGLE_CLOUD_PROJECT='your-project-id'
|
|
133
|
+
export GOOGLE_CLOUD_LOCATION='us-central1'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import {GoogleGenAI} from '@google/genai';
|
|
138
|
+
|
|
139
|
+
const ai = new GoogleGenAI();
|
|
140
|
+
```
|
|
141
|
+
|
|
101
142
|
## API Selection
|
|
102
143
|
|
|
103
144
|
By default, the SDK uses the beta API endpoints provided by Google to support
|
package/dist/genai.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
1
|
+
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
2
|
import { GoogleAuthOptions } from 'google-auth-library';
|
|
3
3
|
|
|
4
4
|
/** Marks the end of user activity.
|
|
@@ -272,6 +272,12 @@ export declare interface AuthConfigOidcConfig {
|
|
|
272
272
|
serviceAccount?: string;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
/** Config for auth_tokens.create parameters. */
|
|
276
|
+
export declare interface AuthToken {
|
|
277
|
+
/** The name of the auth token. */
|
|
278
|
+
name?: string;
|
|
279
|
+
}
|
|
280
|
+
|
|
275
281
|
/** Type of auth scheme. */
|
|
276
282
|
export declare enum AuthType {
|
|
277
283
|
AUTH_TYPE_UNSPECIFIED = "AUTH_TYPE_UNSPECIFIED",
|
|
@@ -855,7 +861,7 @@ export declare class ControlReferenceImage {
|
|
|
855
861
|
/** Configuration for the control reference image. */
|
|
856
862
|
config?: ControlReferenceConfig;
|
|
857
863
|
/** Internal method to convert to ReferenceImageAPIInternal. */
|
|
858
|
-
toReferenceImageAPI():
|
|
864
|
+
toReferenceImageAPI(): ReferenceImageAPIInternal;
|
|
859
865
|
}
|
|
860
866
|
|
|
861
867
|
/** Enum representing the control type of a control reference image. */
|
|
@@ -938,11 +944,17 @@ export declare interface CreateAuthTokenConfig {
|
|
|
938
944
|
not count as a use. */
|
|
939
945
|
uses?: number;
|
|
940
946
|
/** Configuration specific to Live API connections created using this token. */
|
|
941
|
-
|
|
947
|
+
liveConnectConstraints?: LiveConnectConstraints;
|
|
942
948
|
/** Additional fields to lock in the effective LiveConnectParameters. */
|
|
943
949
|
lockAdditionalFields?: string[];
|
|
944
950
|
}
|
|
945
951
|
|
|
952
|
+
/** Config for auth_tokens.create parameters. */
|
|
953
|
+
export declare interface CreateAuthTokenParameters {
|
|
954
|
+
/** Optional parameters for the request. */
|
|
955
|
+
config?: CreateAuthTokenConfig;
|
|
956
|
+
}
|
|
957
|
+
|
|
946
958
|
/** Optional configuration for cached content creation. */
|
|
947
959
|
export declare interface CreateCachedContentConfig {
|
|
948
960
|
/** Used to override HTTP request options. */
|
|
@@ -1837,7 +1849,11 @@ export declare enum FinishReason {
|
|
|
1837
1849
|
/**
|
|
1838
1850
|
* Token generation stopped because generated images have safety violations.
|
|
1839
1851
|
*/
|
|
1840
|
-
IMAGE_SAFETY = "IMAGE_SAFETY"
|
|
1852
|
+
IMAGE_SAFETY = "IMAGE_SAFETY",
|
|
1853
|
+
/**
|
|
1854
|
+
* The tool call generated by the model is invalid.
|
|
1855
|
+
*/
|
|
1856
|
+
UNEXPECTED_TOOL_CALL = "UNEXPECTED_TOOL_CALL"
|
|
1841
1857
|
}
|
|
1842
1858
|
|
|
1843
1859
|
/** A function call. */
|
|
@@ -2667,6 +2683,7 @@ export declare class GoogleGenAI {
|
|
|
2667
2683
|
readonly caches: Caches;
|
|
2668
2684
|
readonly files: Files;
|
|
2669
2685
|
readonly operations: Operations;
|
|
2686
|
+
readonly authTokens: Tokens;
|
|
2670
2687
|
readonly tunings: Tunings;
|
|
2671
2688
|
constructor(options: GoogleGenAIOptions);
|
|
2672
2689
|
}
|
|
@@ -3544,6 +3561,16 @@ export declare interface LiveConnectConfig {
|
|
|
3544
3561
|
proactivity?: ProactivityConfig;
|
|
3545
3562
|
}
|
|
3546
3563
|
|
|
3564
|
+
/** Config for LiveConnectConstraints for Auth Token creation. */
|
|
3565
|
+
export declare interface LiveConnectConstraints {
|
|
3566
|
+
/** ID of the model to configure in the ephemeral token for Live API.
|
|
3567
|
+
For a list of models, see `Gemini models
|
|
3568
|
+
<https://ai.google.dev/gemini-api/docs/models>`. */
|
|
3569
|
+
model?: string;
|
|
3570
|
+
/** Configuration specific to Live API connections created using this token. */
|
|
3571
|
+
config?: LiveConnectConfig;
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3547
3574
|
/** Parameters for connecting to the live API. */
|
|
3548
3575
|
export declare interface LiveConnectParameters {
|
|
3549
3576
|
/** ID of the model to use. For a list of models, see `Google models
|
|
@@ -3556,16 +3583,6 @@ export declare interface LiveConnectParameters {
|
|
|
3556
3583
|
config?: LiveConnectConfig;
|
|
3557
3584
|
}
|
|
3558
3585
|
|
|
3559
|
-
/** Config for LiveEphemeralParameters for Auth Token creation. */
|
|
3560
|
-
export declare interface LiveEphemeralParameters {
|
|
3561
|
-
/** ID of the model to configure in the ephemeral token for Live API.
|
|
3562
|
-
For a list of models, see `Gemini models
|
|
3563
|
-
<https://ai.google.dev/gemini-api/docs/models>`. */
|
|
3564
|
-
model?: string;
|
|
3565
|
-
/** Configuration specific to Live API connections created using this token. */
|
|
3566
|
-
config?: LiveConnectConfig;
|
|
3567
|
-
}
|
|
3568
|
-
|
|
3569
3586
|
/**
|
|
3570
3587
|
LiveMusic class encapsulates the configuration for live music
|
|
3571
3588
|
generation via Lyria Live models.
|
|
@@ -4059,7 +4076,7 @@ export declare class MaskReferenceImage {
|
|
|
4059
4076
|
/** Configuration for the mask reference image. */
|
|
4060
4077
|
config?: MaskReferenceConfig;
|
|
4061
4078
|
/** Internal method to convert to ReferenceImageAPIInternal. */
|
|
4062
|
-
toReferenceImageAPI():
|
|
4079
|
+
toReferenceImageAPI(): ReferenceImageAPIInternal;
|
|
4063
4080
|
}
|
|
4064
4081
|
|
|
4065
4082
|
/** Enum representing the mask mode of a mask reference image. */
|
|
@@ -4554,11 +4571,6 @@ export declare class Operations extends BaseModule {
|
|
|
4554
4571
|
private fetchPredictVideosOperationInternal;
|
|
4555
4572
|
}
|
|
4556
4573
|
|
|
4557
|
-
/**
|
|
4558
|
-
* @license
|
|
4559
|
-
* Copyright 2025 Google LLC
|
|
4560
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4561
|
-
*/
|
|
4562
4574
|
/** Required. Outcome of the code execution. */
|
|
4563
4575
|
export declare enum Outcome {
|
|
4564
4576
|
/**
|
|
@@ -4721,6 +4733,8 @@ export declare interface Part {
|
|
|
4721
4733
|
inlineData?: Blob_2;
|
|
4722
4734
|
/** Optional. URI based data. */
|
|
4723
4735
|
fileData?: FileData;
|
|
4736
|
+
/** An opaque signature for the thought so it can be reused in subsequent requests. */
|
|
4737
|
+
thoughtSignature?: string;
|
|
4724
4738
|
/** Optional. Result of executing the [ExecutableCode]. */
|
|
4725
4739
|
codeExecutionResult?: CodeExecutionResult;
|
|
4726
4740
|
/** Optional. Code generated by the model that is meant to be executed. */
|
|
@@ -4846,7 +4860,7 @@ export declare class RawReferenceImage {
|
|
|
4846
4860
|
/** The type of the reference image. Only set by the SDK. */
|
|
4847
4861
|
referenceType?: string;
|
|
4848
4862
|
/** Internal method to convert to ReferenceImageAPIInternal. */
|
|
4849
|
-
toReferenceImageAPI():
|
|
4863
|
+
toReferenceImageAPI(): ReferenceImageAPIInternal;
|
|
4850
4864
|
}
|
|
4851
4865
|
|
|
4852
4866
|
/** Marks the end of user activity.
|
|
@@ -4865,6 +4879,24 @@ export declare interface RealtimeInputConfig {
|
|
|
4865
4879
|
|
|
4866
4880
|
export declare type ReferenceImage = RawReferenceImage | MaskReferenceImage | ControlReferenceImage | StyleReferenceImage | SubjectReferenceImage;
|
|
4867
4881
|
|
|
4882
|
+
/** Private class that represents a Reference image that is sent to API. */
|
|
4883
|
+
declare interface ReferenceImageAPIInternal {
|
|
4884
|
+
/** The reference image for the editing operation. */
|
|
4885
|
+
referenceImage?: types.Image;
|
|
4886
|
+
/** The id of the reference image. */
|
|
4887
|
+
referenceId?: number;
|
|
4888
|
+
/** The type of the reference image. Only set by the SDK. */
|
|
4889
|
+
referenceType?: string;
|
|
4890
|
+
/** Configuration for the mask reference image. */
|
|
4891
|
+
maskImageConfig?: types.MaskReferenceConfig;
|
|
4892
|
+
/** Configuration for the control reference image. */
|
|
4893
|
+
controlImageConfig?: types.ControlReferenceConfig;
|
|
4894
|
+
/** Configuration for the style reference image. */
|
|
4895
|
+
styleImageConfig?: types.StyleReferenceConfig;
|
|
4896
|
+
/** Configuration for the subject reference image. */
|
|
4897
|
+
subjectImageConfig?: types.SubjectReferenceConfig;
|
|
4898
|
+
}
|
|
4899
|
+
|
|
4868
4900
|
/** Represents a recorded session. */
|
|
4869
4901
|
export declare interface ReplayFile {
|
|
4870
4902
|
replayId?: string;
|
|
@@ -5357,7 +5389,7 @@ export declare class StyleReferenceImage {
|
|
|
5357
5389
|
/** Configuration for the style reference image. */
|
|
5358
5390
|
config?: StyleReferenceConfig;
|
|
5359
5391
|
/** Internal method to convert to ReferenceImageAPIInternal. */
|
|
5360
|
-
toReferenceImageAPI():
|
|
5392
|
+
toReferenceImageAPI(): ReferenceImageAPIInternal;
|
|
5361
5393
|
}
|
|
5362
5394
|
|
|
5363
5395
|
/** Configuration for a Subject reference image. */
|
|
@@ -5385,7 +5417,7 @@ export declare class SubjectReferenceImage {
|
|
|
5385
5417
|
referenceType?: string;
|
|
5386
5418
|
/** Configuration for the subject reference image. */
|
|
5387
5419
|
config?: SubjectReferenceConfig;
|
|
5388
|
-
toReferenceImageAPI():
|
|
5420
|
+
toReferenceImageAPI(): ReferenceImageAPIInternal;
|
|
5389
5421
|
}
|
|
5390
5422
|
|
|
5391
5423
|
/** Enum representing the subject type of a subject reference image. */
|
|
@@ -5514,6 +5546,89 @@ export declare interface ThinkingConfig {
|
|
|
5514
5546
|
thinkingBudget?: number;
|
|
5515
5547
|
}
|
|
5516
5548
|
|
|
5549
|
+
export declare class Tokens extends BaseModule {
|
|
5550
|
+
private readonly apiClient;
|
|
5551
|
+
constructor(apiClient: ApiClient);
|
|
5552
|
+
/**
|
|
5553
|
+
* Creates an ephemeral auth token resource.
|
|
5554
|
+
*
|
|
5555
|
+
* @experimental
|
|
5556
|
+
*
|
|
5557
|
+
* @remarks
|
|
5558
|
+
* Ephermeral auth tokens is only supported in the Gemini Developer API.
|
|
5559
|
+
* It can be used for the session connection to the Live constrained API.
|
|
5560
|
+
*
|
|
5561
|
+
* @param params - The parameters for the create request.
|
|
5562
|
+
* @return The created auth token.
|
|
5563
|
+
*
|
|
5564
|
+
* @example
|
|
5565
|
+
* ```ts
|
|
5566
|
+
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
5567
|
+
* // when using the token in Live API sessions. Each session connection can
|
|
5568
|
+
* // use a different configuration.
|
|
5569
|
+
* const config: CreateAuthTokenConfig = {
|
|
5570
|
+
* uses: 3,
|
|
5571
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
5572
|
+
* }
|
|
5573
|
+
* const token = await ai.tokens.create(config);
|
|
5574
|
+
*
|
|
5575
|
+
* // Case 2: If LiveEphemeralParameters is set, lock all fields in
|
|
5576
|
+
* // LiveConnectConfig when using the token in Live API sessions. For
|
|
5577
|
+
* // example, changing `outputAudioTranscription` in the Live API
|
|
5578
|
+
* // connection will be ignored by the API.
|
|
5579
|
+
* const config: CreateAuthTokenConfig =
|
|
5580
|
+
* uses: 3,
|
|
5581
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
5582
|
+
* LiveEphemeralParameters: {
|
|
5583
|
+
* model: 'gemini-2.0-flash-001',
|
|
5584
|
+
* config: {
|
|
5585
|
+
* 'responseModalities': ['AUDIO'],
|
|
5586
|
+
* 'systemInstruction': 'Always answer in English.',
|
|
5587
|
+
* }
|
|
5588
|
+
* }
|
|
5589
|
+
* }
|
|
5590
|
+
* const token = await ai.tokens.create(config);
|
|
5591
|
+
*
|
|
5592
|
+
* // Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
|
|
5593
|
+
* // set, lock LiveConnectConfig with set and additional fields (e.g.
|
|
5594
|
+
* // responseModalities, systemInstruction, temperature in this example) when
|
|
5595
|
+
* // using the token in Live API sessions.
|
|
5596
|
+
* const config: CreateAuthTokenConfig =
|
|
5597
|
+
* uses: 3,
|
|
5598
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
5599
|
+
* LiveEphemeralParameters: {
|
|
5600
|
+
* model: 'gemini-2.0-flash-001',
|
|
5601
|
+
* config: {
|
|
5602
|
+
* 'responseModalities': ['AUDIO'],
|
|
5603
|
+
* 'systemInstruction': 'Always answer in English.',
|
|
5604
|
+
* }
|
|
5605
|
+
* },
|
|
5606
|
+
* lockAdditionalFields: ['temperature'],
|
|
5607
|
+
* }
|
|
5608
|
+
* const token = await ai.tokens.create(config);
|
|
5609
|
+
*
|
|
5610
|
+
* // Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
|
|
5611
|
+
* // empty array, lock LiveConnectConfig with set fields (e.g.
|
|
5612
|
+
* // responseModalities, systemInstruction in this example) when using the
|
|
5613
|
+
* // token in Live API sessions.
|
|
5614
|
+
* const config: CreateAuthTokenConfig =
|
|
5615
|
+
* uses: 3,
|
|
5616
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
5617
|
+
* LiveEphemeralParameters: {
|
|
5618
|
+
* model: 'gemini-2.0-flash-001',
|
|
5619
|
+
* config: {
|
|
5620
|
+
* 'responseModalities': ['AUDIO'],
|
|
5621
|
+
* 'systemInstruction': 'Always answer in English.',
|
|
5622
|
+
* }
|
|
5623
|
+
* },
|
|
5624
|
+
* lockAdditionalFields: [],
|
|
5625
|
+
* }
|
|
5626
|
+
* const token = await ai.tokens.create(config);
|
|
5627
|
+
* ```
|
|
5628
|
+
*/
|
|
5629
|
+
create(params: types.CreateAuthTokenParameters): Promise<types.AuthToken>;
|
|
5630
|
+
}
|
|
5631
|
+
|
|
5517
5632
|
/** Tokens info with a list of tokens and the corresponding list of token ids. */
|
|
5518
5633
|
export declare interface TokensInfo {
|
|
5519
5634
|
/** Optional. Optional fields for the role from the corresponding Content. */
|
|
@@ -6098,8 +6213,10 @@ declare namespace types {
|
|
|
6098
6213
|
LiveMusicConnectParameters,
|
|
6099
6214
|
LiveMusicSetConfigParameters,
|
|
6100
6215
|
LiveMusicSetWeightedPromptsParameters,
|
|
6101
|
-
|
|
6216
|
+
AuthToken,
|
|
6217
|
+
LiveConnectConstraints,
|
|
6102
6218
|
CreateAuthTokenConfig,
|
|
6219
|
+
CreateAuthTokenParameters,
|
|
6103
6220
|
OperationGetParameters,
|
|
6104
6221
|
BlobImageUnion,
|
|
6105
6222
|
PartUnion,
|