@google/genai 1.33.0 → 1.34.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.
@@ -817,21 +817,29 @@ exports.PhishBlockThreshold = void 0;
817
817
  */
818
818
  PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
819
819
  })(exports.PhishBlockThreshold || (exports.PhishBlockThreshold = {}));
820
- /** The level of thoughts tokens that the model should generate. */
820
+ /** The number of thoughts tokens that the model should generate. */
821
821
  exports.ThinkingLevel = void 0;
822
822
  (function (ThinkingLevel) {
823
823
  /**
824
- * Default value.
824
+ * Unspecified thinking level.
825
825
  */
826
826
  ThinkingLevel["THINKING_LEVEL_UNSPECIFIED"] = "THINKING_LEVEL_UNSPECIFIED";
827
827
  /**
828
828
  * Low thinking level.
829
829
  */
830
830
  ThinkingLevel["LOW"] = "LOW";
831
+ /**
832
+ * Medium thinking level.
833
+ */
834
+ ThinkingLevel["MEDIUM"] = "MEDIUM";
831
835
  /**
832
836
  * High thinking level.
833
837
  */
834
838
  ThinkingLevel["HIGH"] = "HIGH";
839
+ /**
840
+ * MINIMAL thinking level.
841
+ */
842
+ ThinkingLevel["MINIMAL"] = "MINIMAL";
835
843
  })(exports.ThinkingLevel || (exports.ThinkingLevel = {}));
836
844
  /** Harm category. */
837
845
  exports.HarmCategory = void 0;
@@ -1302,6 +1310,10 @@ exports.PartMediaResolutionLevel = void 0;
1302
1310
  * Media resolution set to high.
1303
1311
  */
1304
1312
  PartMediaResolutionLevel["MEDIA_RESOLUTION_HIGH"] = "MEDIA_RESOLUTION_HIGH";
1313
+ /**
1314
+ * Media resolution set to ultra high.
1315
+ */
1316
+ PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1305
1317
  })(exports.PartMediaResolutionLevel || (exports.PartMediaResolutionLevel = {}));
1306
1318
  /** Options for feature selection preference. */
1307
1319
  exports.FeatureSelectionPreference = void 0;
@@ -7277,7 +7289,7 @@ function generationConfigToVertex$1(fromObject) {
7277
7289
  }
7278
7290
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
7279
7291
  if (fromSpeechConfig != null) {
7280
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex$1(fromSpeechConfig));
7292
+ setValueByPath(toObject, ['speechConfig'], fromSpeechConfig);
7281
7293
  }
7282
7294
  const fromStopSequences = getValueByPath(fromObject, [
7283
7295
  'stopSequences',
@@ -7493,7 +7505,7 @@ function liveConnectConfigToVertex(fromObject, parentObject) {
7493
7505
  }
7494
7506
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
7495
7507
  if (parentObject !== undefined && fromSpeechConfig != null) {
7496
- setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], speechConfigToVertex$1(tLiveSpeechConfig(fromSpeechConfig)));
7508
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
7497
7509
  }
7498
7510
  const fromThinkingConfig = getValueByPath(fromObject, [
7499
7511
  'thinkingConfig',
@@ -7818,21 +7830,6 @@ function sessionResumptionConfigToMldev$1(fromObject) {
7818
7830
  }
7819
7831
  return toObject;
7820
7832
  }
7821
- function speechConfigToVertex$1(fromObject) {
7822
- const toObject = {};
7823
- const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
7824
- if (fromVoiceConfig != null) {
7825
- setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
7826
- }
7827
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7828
- if (fromLanguageCode != null) {
7829
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7830
- }
7831
- if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
7832
- throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
7833
- }
7834
- return toObject;
7835
- }
7836
7833
  function toolToMldev$2(fromObject) {
7837
7834
  const toObject = {};
7838
7835
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -9075,7 +9072,7 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
9075
9072
  }
9076
9073
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
9077
9074
  if (fromSpeechConfig != null) {
9078
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex(tSpeechConfig(fromSpeechConfig)));
9075
+ setValueByPath(toObject, ['speechConfig'], tSpeechConfig(fromSpeechConfig));
9079
9076
  }
9080
9077
  const fromAudioTimestamp = getValueByPath(fromObject, [
9081
9078
  'audioTimestamp',
@@ -10021,7 +10018,7 @@ function generationConfigToVertex(fromObject) {
10021
10018
  }
10022
10019
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
10023
10020
  if (fromSpeechConfig != null) {
10024
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex(fromSpeechConfig));
10021
+ setValueByPath(toObject, ['speechConfig'], fromSpeechConfig);
10025
10022
  }
10026
10023
  const fromStopSequences = getValueByPath(fromObject, [
10027
10024
  'stopSequences',
@@ -10823,21 +10820,6 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
10823
10820
  }
10824
10821
  return toObject;
10825
10822
  }
10826
- function speechConfigToVertex(fromObject) {
10827
- const toObject = {};
10828
- const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
10829
- if (fromVoiceConfig != null) {
10830
- setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
10831
- }
10832
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10833
- if (fromLanguageCode != null) {
10834
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10835
- }
10836
- if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
10837
- throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
10838
- }
10839
- return toObject;
10840
- }
10841
10823
  function toolConfigToMldev(fromObject) {
10842
10824
  const toObject = {};
10843
10825
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -11519,7 +11501,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11519
11501
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11520
11502
  const USER_AGENT_HEADER = 'User-Agent';
11521
11503
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11522
- const SDK_VERSION = '1.33.0'; // x-release-please-version
11504
+ const SDK_VERSION = '1.34.0'; // x-release-please-version
11523
11505
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11524
11506
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11525
11507
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11593,6 +11575,11 @@ class ApiClient {
11593
11575
  getLocation() {
11594
11576
  return this.clientOptions.location;
11595
11577
  }
11578
+ async getAuthHeaders() {
11579
+ const headers = new Headers();
11580
+ await this.clientOptions.auth.addAuthHeaders(headers);
11581
+ return headers;
11582
+ }
11596
11583
  getApiVersion() {
11597
11584
  if (this.clientOptions.httpOptions &&
11598
11585
  this.clientOptions.httpOptions.apiVersion !== undefined) {
@@ -17465,7 +17452,7 @@ class BaseGeminiNextGenAPIClient {
17465
17452
  */
17466
17453
  constructor(_b) {
17467
17454
  var _c, _d, _e, _f, _g, _h, _j;
17468
- var _k = _b === void 0 ? {} : _b, { baseURL = readEnv('GEMINI_NEXT_GEN_API_BASE_URL'), apiKey = (_c = readEnv('GEMINI_API_KEY')) !== null && _c !== void 0 ? _c : null, apiVersion = 'v1beta' } = _k, opts = __rest(_k, ["baseURL", "apiKey", "apiVersion"]);
17455
+ var { baseURL = readEnv('GEMINI_NEXT_GEN_API_BASE_URL'), apiKey = (_c = readEnv('GEMINI_API_KEY')) !== null && _c !== void 0 ? _c : null, apiVersion = 'v1beta' } = _b, opts = __rest(_b, ["baseURL", "apiKey", "apiVersion"]);
17469
17456
  const options = Object.assign(Object.assign({ apiKey,
17470
17457
  apiVersion }, opts), { baseURL: baseURL || `https://generativelanguage.googleapis.com` });
17471
17458
  this.baseURL = options.baseURL;
@@ -17483,6 +17470,7 @@ class BaseGeminiNextGenAPIClient {
17483
17470
  this._options = options;
17484
17471
  this.apiKey = apiKey;
17485
17472
  this.apiVersion = apiVersion;
17473
+ this.clientAdapter = options.clientAdapter;
17486
17474
  }
17487
17475
  /**
17488
17476
  * Create a new client instance re-using the same options given to the current client with optional overriding.
@@ -17501,6 +17489,10 @@ class BaseGeminiNextGenAPIClient {
17501
17489
  return this._options.defaultQuery;
17502
17490
  }
17503
17491
  validateHeaders({ values, nulls }) {
17492
+ // The headers object handles case insensitivity.
17493
+ if (values.has('authorization') || values.has('x-goog-api-key')) {
17494
+ return;
17495
+ }
17504
17496
  if (this.apiKey && values.get('x-goog-api-key')) {
17505
17497
  return;
17506
17498
  }
@@ -17510,10 +17502,17 @@ class BaseGeminiNextGenAPIClient {
17510
17502
  throw new Error('Could not resolve authentication method. Expected the apiKey to be set. Or for the "x-goog-api-key" headers to be explicitly omitted');
17511
17503
  }
17512
17504
  async authHeaders(opts) {
17513
- if (this.apiKey == null) {
17505
+ const existingHeaders = buildHeaders([opts.headers]);
17506
+ if (existingHeaders.values.has('authorization') || existingHeaders.values.has('x-goog-api-key')) {
17514
17507
  return undefined;
17515
17508
  }
17516
- return buildHeaders([{ 'x-goog-api-key': this.apiKey }]);
17509
+ if (this.apiKey) {
17510
+ return buildHeaders([{ 'x-goog-api-key': this.apiKey }]);
17511
+ }
17512
+ if (this.clientAdapter.isVertexAI()) {
17513
+ return buildHeaders([await this.clientAdapter.getAuthHeaders()]);
17514
+ }
17515
+ return undefined;
17517
17516
  }
17518
17517
  /**
17519
17518
  * Basic re-implementation of `qs.stringify` for primitive types.
@@ -17557,8 +17556,16 @@ class BaseGeminiNextGenAPIClient {
17557
17556
  }
17558
17557
  /**
17559
17558
  * Used as a callback for mutating the given `FinalRequestOptions` object.
17559
+
17560
17560
  */
17561
- async prepareOptions(options) { }
17561
+ async prepareOptions(options) {
17562
+ if (this.clientAdapter &&
17563
+ this.clientAdapter.isVertexAI() &&
17564
+ !options.path.startsWith(`/${this.apiVersion}/projects/`)) {
17565
+ const oldPath = options.path.slice(this.apiVersion.length + 1);
17566
+ options.path = `/${this.apiVersion}/projects/${this.clientAdapter.getProject()}/locations/${this.clientAdapter.getLocation()}${oldPath}`;
17567
+ }
17568
+ }
17562
17569
  /**
17563
17570
  * Used as a callback for mutating the given `RequestInit` object.
17564
17571
  *
@@ -17800,13 +17807,14 @@ class BaseGeminiNextGenAPIClient {
17800
17807
  options.idempotencyKey = this.defaultIdempotencyKey();
17801
17808
  idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
17802
17809
  }
17803
- const headers = buildHeaders([
17810
+ const authHeaders = await this.authHeaders(options);
17811
+ let headers = buildHeaders([
17804
17812
  idempotencyHeaders,
17805
17813
  Object.assign(Object.assign({ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'X-Stainless-Retry-Count': String(retryCount) }, (options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {})), getPlatformHeaders()),
17806
- await this.authHeaders(options),
17807
17814
  this._options.defaultHeaders,
17808
17815
  bodyHeaders,
17809
17816
  options.headers,
17817
+ authHeaders,
17810
17818
  ]);
17811
17819
  this.validateHeaders(headers);
17812
17820
  return headers.values;
@@ -19472,9 +19480,6 @@ class GoogleGenAI {
19472
19480
  return this._interactions;
19473
19481
  }
19474
19482
  console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
19475
- if (this.vertexai) {
19476
- throw new Error('This version of the GenAI SDK does not support Vertex AI API for interactions.');
19477
- }
19478
19483
  const httpOpts = this.httpOptions;
19479
19484
  // Unsupported Options Warnings
19480
19485
  if (httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.extraBody) {
@@ -19483,6 +19488,8 @@ class GoogleGenAI {
19483
19488
  const nextGenClient = new GeminiNextGenAPIClient({
19484
19489
  baseURL: this.apiClient.getBaseUrl(),
19485
19490
  apiKey: this.apiKey,
19491
+ apiVersion: this.apiClient.getApiVersion(),
19492
+ clientAdapter: this.apiClient,
19486
19493
  defaultHeaders: this.apiClient.getDefaultHeaders(),
19487
19494
  timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
19488
19495
  });
@@ -795,21 +795,29 @@ var PhishBlockThreshold;
795
795
  */
796
796
  PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
797
797
  })(PhishBlockThreshold || (PhishBlockThreshold = {}));
798
- /** The level of thoughts tokens that the model should generate. */
798
+ /** The number of thoughts tokens that the model should generate. */
799
799
  var ThinkingLevel;
800
800
  (function (ThinkingLevel) {
801
801
  /**
802
- * Default value.
802
+ * Unspecified thinking level.
803
803
  */
804
804
  ThinkingLevel["THINKING_LEVEL_UNSPECIFIED"] = "THINKING_LEVEL_UNSPECIFIED";
805
805
  /**
806
806
  * Low thinking level.
807
807
  */
808
808
  ThinkingLevel["LOW"] = "LOW";
809
+ /**
810
+ * Medium thinking level.
811
+ */
812
+ ThinkingLevel["MEDIUM"] = "MEDIUM";
809
813
  /**
810
814
  * High thinking level.
811
815
  */
812
816
  ThinkingLevel["HIGH"] = "HIGH";
817
+ /**
818
+ * MINIMAL thinking level.
819
+ */
820
+ ThinkingLevel["MINIMAL"] = "MINIMAL";
813
821
  })(ThinkingLevel || (ThinkingLevel = {}));
814
822
  /** Harm category. */
815
823
  var HarmCategory;
@@ -1280,6 +1288,10 @@ var PartMediaResolutionLevel;
1280
1288
  * Media resolution set to high.
1281
1289
  */
1282
1290
  PartMediaResolutionLevel["MEDIA_RESOLUTION_HIGH"] = "MEDIA_RESOLUTION_HIGH";
1291
+ /**
1292
+ * Media resolution set to ultra high.
1293
+ */
1294
+ PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1283
1295
  })(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
1284
1296
  /** Options for feature selection preference. */
1285
1297
  var FeatureSelectionPreference;
@@ -7255,7 +7267,7 @@ function generationConfigToVertex$1(fromObject) {
7255
7267
  }
7256
7268
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
7257
7269
  if (fromSpeechConfig != null) {
7258
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex$1(fromSpeechConfig));
7270
+ setValueByPath(toObject, ['speechConfig'], fromSpeechConfig);
7259
7271
  }
7260
7272
  const fromStopSequences = getValueByPath(fromObject, [
7261
7273
  'stopSequences',
@@ -7471,7 +7483,7 @@ function liveConnectConfigToVertex(fromObject, parentObject) {
7471
7483
  }
7472
7484
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
7473
7485
  if (parentObject !== undefined && fromSpeechConfig != null) {
7474
- setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], speechConfigToVertex$1(tLiveSpeechConfig(fromSpeechConfig)));
7486
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
7475
7487
  }
7476
7488
  const fromThinkingConfig = getValueByPath(fromObject, [
7477
7489
  'thinkingConfig',
@@ -7796,21 +7808,6 @@ function sessionResumptionConfigToMldev$1(fromObject) {
7796
7808
  }
7797
7809
  return toObject;
7798
7810
  }
7799
- function speechConfigToVertex$1(fromObject) {
7800
- const toObject = {};
7801
- const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
7802
- if (fromVoiceConfig != null) {
7803
- setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
7804
- }
7805
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7806
- if (fromLanguageCode != null) {
7807
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7808
- }
7809
- if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
7810
- throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
7811
- }
7812
- return toObject;
7813
- }
7814
7811
  function toolToMldev$2(fromObject) {
7815
7812
  const toObject = {};
7816
7813
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -9053,7 +9050,7 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
9053
9050
  }
9054
9051
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
9055
9052
  if (fromSpeechConfig != null) {
9056
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex(tSpeechConfig(fromSpeechConfig)));
9053
+ setValueByPath(toObject, ['speechConfig'], tSpeechConfig(fromSpeechConfig));
9057
9054
  }
9058
9055
  const fromAudioTimestamp = getValueByPath(fromObject, [
9059
9056
  'audioTimestamp',
@@ -9999,7 +9996,7 @@ function generationConfigToVertex(fromObject) {
9999
9996
  }
10000
9997
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
10001
9998
  if (fromSpeechConfig != null) {
10002
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex(fromSpeechConfig));
9999
+ setValueByPath(toObject, ['speechConfig'], fromSpeechConfig);
10003
10000
  }
10004
10001
  const fromStopSequences = getValueByPath(fromObject, [
10005
10002
  'stopSequences',
@@ -10801,21 +10798,6 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
10801
10798
  }
10802
10799
  return toObject;
10803
10800
  }
10804
- function speechConfigToVertex(fromObject) {
10805
- const toObject = {};
10806
- const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
10807
- if (fromVoiceConfig != null) {
10808
- setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
10809
- }
10810
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10811
- if (fromLanguageCode != null) {
10812
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10813
- }
10814
- if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
10815
- throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
10816
- }
10817
- return toObject;
10818
- }
10819
10801
  function toolConfigToMldev(fromObject) {
10820
10802
  const toObject = {};
10821
10803
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -11497,7 +11479,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11497
11479
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11498
11480
  const USER_AGENT_HEADER = 'User-Agent';
11499
11481
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11500
- const SDK_VERSION = '1.33.0'; // x-release-please-version
11482
+ const SDK_VERSION = '1.34.0'; // x-release-please-version
11501
11483
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11502
11484
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11503
11485
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11571,6 +11553,11 @@ class ApiClient {
11571
11553
  getLocation() {
11572
11554
  return this.clientOptions.location;
11573
11555
  }
11556
+ async getAuthHeaders() {
11557
+ const headers = new Headers();
11558
+ await this.clientOptions.auth.addAuthHeaders(headers);
11559
+ return headers;
11560
+ }
11574
11561
  getApiVersion() {
11575
11562
  if (this.clientOptions.httpOptions &&
11576
11563
  this.clientOptions.httpOptions.apiVersion !== undefined) {
@@ -17443,7 +17430,7 @@ class BaseGeminiNextGenAPIClient {
17443
17430
  */
17444
17431
  constructor(_b) {
17445
17432
  var _c, _d, _e, _f, _g, _h, _j;
17446
- var _k = _b === void 0 ? {} : _b, { baseURL = readEnv('GEMINI_NEXT_GEN_API_BASE_URL'), apiKey = (_c = readEnv('GEMINI_API_KEY')) !== null && _c !== void 0 ? _c : null, apiVersion = 'v1beta' } = _k, opts = __rest(_k, ["baseURL", "apiKey", "apiVersion"]);
17433
+ var { baseURL = readEnv('GEMINI_NEXT_GEN_API_BASE_URL'), apiKey = (_c = readEnv('GEMINI_API_KEY')) !== null && _c !== void 0 ? _c : null, apiVersion = 'v1beta' } = _b, opts = __rest(_b, ["baseURL", "apiKey", "apiVersion"]);
17447
17434
  const options = Object.assign(Object.assign({ apiKey,
17448
17435
  apiVersion }, opts), { baseURL: baseURL || `https://generativelanguage.googleapis.com` });
17449
17436
  this.baseURL = options.baseURL;
@@ -17461,6 +17448,7 @@ class BaseGeminiNextGenAPIClient {
17461
17448
  this._options = options;
17462
17449
  this.apiKey = apiKey;
17463
17450
  this.apiVersion = apiVersion;
17451
+ this.clientAdapter = options.clientAdapter;
17464
17452
  }
17465
17453
  /**
17466
17454
  * Create a new client instance re-using the same options given to the current client with optional overriding.
@@ -17479,6 +17467,10 @@ class BaseGeminiNextGenAPIClient {
17479
17467
  return this._options.defaultQuery;
17480
17468
  }
17481
17469
  validateHeaders({ values, nulls }) {
17470
+ // The headers object handles case insensitivity.
17471
+ if (values.has('authorization') || values.has('x-goog-api-key')) {
17472
+ return;
17473
+ }
17482
17474
  if (this.apiKey && values.get('x-goog-api-key')) {
17483
17475
  return;
17484
17476
  }
@@ -17488,10 +17480,17 @@ class BaseGeminiNextGenAPIClient {
17488
17480
  throw new Error('Could not resolve authentication method. Expected the apiKey to be set. Or for the "x-goog-api-key" headers to be explicitly omitted');
17489
17481
  }
17490
17482
  async authHeaders(opts) {
17491
- if (this.apiKey == null) {
17483
+ const existingHeaders = buildHeaders([opts.headers]);
17484
+ if (existingHeaders.values.has('authorization') || existingHeaders.values.has('x-goog-api-key')) {
17492
17485
  return undefined;
17493
17486
  }
17494
- return buildHeaders([{ 'x-goog-api-key': this.apiKey }]);
17487
+ if (this.apiKey) {
17488
+ return buildHeaders([{ 'x-goog-api-key': this.apiKey }]);
17489
+ }
17490
+ if (this.clientAdapter.isVertexAI()) {
17491
+ return buildHeaders([await this.clientAdapter.getAuthHeaders()]);
17492
+ }
17493
+ return undefined;
17495
17494
  }
17496
17495
  /**
17497
17496
  * Basic re-implementation of `qs.stringify` for primitive types.
@@ -17535,8 +17534,16 @@ class BaseGeminiNextGenAPIClient {
17535
17534
  }
17536
17535
  /**
17537
17536
  * Used as a callback for mutating the given `FinalRequestOptions` object.
17537
+
17538
17538
  */
17539
- async prepareOptions(options) { }
17539
+ async prepareOptions(options) {
17540
+ if (this.clientAdapter &&
17541
+ this.clientAdapter.isVertexAI() &&
17542
+ !options.path.startsWith(`/${this.apiVersion}/projects/`)) {
17543
+ const oldPath = options.path.slice(this.apiVersion.length + 1);
17544
+ options.path = `/${this.apiVersion}/projects/${this.clientAdapter.getProject()}/locations/${this.clientAdapter.getLocation()}${oldPath}`;
17545
+ }
17546
+ }
17540
17547
  /**
17541
17548
  * Used as a callback for mutating the given `RequestInit` object.
17542
17549
  *
@@ -17778,13 +17785,14 @@ class BaseGeminiNextGenAPIClient {
17778
17785
  options.idempotencyKey = this.defaultIdempotencyKey();
17779
17786
  idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
17780
17787
  }
17781
- const headers = buildHeaders([
17788
+ const authHeaders = await this.authHeaders(options);
17789
+ let headers = buildHeaders([
17782
17790
  idempotencyHeaders,
17783
17791
  Object.assign(Object.assign({ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'X-Stainless-Retry-Count': String(retryCount) }, (options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {})), getPlatformHeaders()),
17784
- await this.authHeaders(options),
17785
17792
  this._options.defaultHeaders,
17786
17793
  bodyHeaders,
17787
17794
  options.headers,
17795
+ authHeaders,
17788
17796
  ]);
17789
17797
  this.validateHeaders(headers);
17790
17798
  return headers.values;
@@ -19450,9 +19458,6 @@ class GoogleGenAI {
19450
19458
  return this._interactions;
19451
19459
  }
19452
19460
  console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
19453
- if (this.vertexai) {
19454
- throw new Error('This version of the GenAI SDK does not support Vertex AI API for interactions.');
19455
- }
19456
19461
  const httpOpts = this.httpOptions;
19457
19462
  // Unsupported Options Warnings
19458
19463
  if (httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.extraBody) {
@@ -19461,6 +19466,8 @@ class GoogleGenAI {
19461
19466
  const nextGenClient = new GeminiNextGenAPIClient({
19462
19467
  baseURL: this.apiClient.getBaseUrl(),
19463
19468
  apiKey: this.apiKey,
19469
+ apiVersion: this.apiClient.getApiVersion(),
19470
+ clientAdapter: this.apiClient,
19464
19471
  defaultHeaders: this.apiClient.getDefaultHeaders(),
19465
19472
  timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
19466
19473
  });