@google/genai 1.37.0 → 1.38.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/dist/genai.d.ts CHANGED
@@ -121,25 +121,12 @@ export declare interface ApiAuthApiKeyConfig {
121
121
  */
122
122
  declare class ApiClient implements GeminiNextGenAPIClientAdapter {
123
123
  readonly clientOptions: ApiClientInitOptions;
124
+ private readonly customBaseUrl?;
124
125
  constructor(opts: ApiClientInitOptions);
125
- /**
126
- * Determines the base URL for Vertex AI based on project and location.
127
- * Uses the global endpoint if location is 'global' or if project/location
128
- * are not specified (implying API key usage).
129
- * @private
130
- */
131
- private baseUrlFromProjectLocation;
132
- /**
133
- * Normalizes authentication parameters for Vertex AI.
134
- * If project and location are provided, API key is cleared.
135
- * If project and location are not provided (implying API key usage),
136
- * project and location are cleared.
137
- * @private
138
- */
139
- private normalizeAuthParameters;
140
126
  isVertexAI(): boolean;
141
127
  getProject(): string | undefined;
142
128
  getLocation(): string | undefined;
129
+ getCustomBaseUrl(): string | undefined;
143
130
  getAuthHeaders(): Promise<Headers>;
144
131
  getApiVersion(): string;
145
132
  getBaseUrl(): string;
@@ -597,7 +584,7 @@ declare interface BaseCreateAgentInteractionParams {
597
584
  */
598
585
  agent_config?: DynamicAgentConfig | DeepResearchAgentConfig;
599
586
  /**
600
- * Body param: Whether to run the model interaction in the background.
587
+ * Body param: Input only. Whether to run the model interaction in the background.
601
588
  */
602
589
  background?: boolean;
603
590
  /**
@@ -649,7 +636,7 @@ declare interface BaseCreateModelInteractionParams {
649
636
  */
650
637
  api_version?: string;
651
638
  /**
652
- * Body param: Whether to run the model interaction in the background.
639
+ * Body param: Input only. Whether to run the model interaction in the background.
653
640
  */
654
641
  background?: boolean;
655
642
  /**
@@ -4115,6 +4102,10 @@ export declare interface GenerateContentConfig {
4115
4102
  models. This field is not supported in Vertex AI.
4116
4103
  */
4117
4104
  enableEnhancedCivicAnswers?: boolean;
4105
+ /** Settings for prompt and response sanitization using the Model Armor
4106
+ service. If supplied, safety_settings must not be supplied.
4107
+ */
4108
+ modelArmorConfig?: ModelArmorConfig;
4118
4109
  }
4119
4110
 
4120
4111
  /** Config for models.generate_content parameters. */
@@ -5369,6 +5360,8 @@ declare type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
5369
5360
  export declare interface HttpOptions {
5370
5361
  /** The base URL for the AI platform service endpoint. */
5371
5362
  baseUrl?: string;
5363
+ /** The resource scope used to constructing the resource name when base_url is set */
5364
+ baseUrlResourceScope?: ResourceScope;
5372
5365
  /** Specifies the version of the API to use. */
5373
5366
  apiVersion?: string;
5374
5367
  /** Additional HTTP headers to be sent with the request. */
@@ -7217,6 +7210,14 @@ export declare interface Model {
7217
7210
  */
7218
7211
  declare type Model_2 = 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-native-audio-dialog' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-pro-preview' | 'gemini-3-flash-preview' | (string & {});
7219
7212
 
7213
+ /** Configuration for Model Armor integrations of prompt and responses. This data type is not supported in Gemini API. */
7214
+ export declare interface ModelArmorConfig {
7215
+ /** Optional. The name of the Model Armor template to use for prompt sanitization. */
7216
+ promptTemplateName?: string;
7217
+ /** Optional. The name of the Model Armor template to use for response sanitization. */
7218
+ responseTemplateName?: string;
7219
+ }
7220
+
7220
7221
  export declare class Models extends BaseModule {
7221
7222
  private readonly apiClient;
7222
7223
  constructor(apiClient: ApiClient);
@@ -8413,6 +8414,18 @@ declare type RequestOptions = {
8413
8414
  __streamClass?: typeof Stream;
8414
8415
  };
8415
8416
 
8417
+ /** Resource scope. */
8418
+ export declare enum ResourceScope {
8419
+ /**
8420
+ * When setting base_url, this value configures resource scope to be the collection.
8421
+ The resource name will not include api version, project, or location.
8422
+ For example, if base_url is set to "https://aiplatform.googleapis.com",
8423
+ then the resource name for a Model would be
8424
+ "https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview
8425
+ */
8426
+ COLLECTION = "COLLECTION"
8427
+ }
8428
+
8416
8429
  /** Defines a retrieval tool that model can call to access external knowledge. This data type is not supported in Gemini API. */
8417
8430
  export declare interface Retrieval {
8418
8431
  /** Optional. Deprecated. This option is no longer supported. */
@@ -9867,6 +9880,7 @@ declare namespace types {
9867
9880
  JobState,
9868
9881
  TuningTask,
9869
9882
  PartMediaResolutionLevel,
9883
+ ResourceScope,
9870
9884
  FeatureSelectionPreference,
9871
9885
  Environment,
9872
9886
  SafetyFilterLevel,
@@ -9963,6 +9977,7 @@ declare namespace types {
9963
9977
  GenerationConfigRoutingConfigManualRoutingMode,
9964
9978
  GenerationConfigRoutingConfig,
9965
9979
  SafetySetting,
9980
+ ModelArmorConfig,
9966
9981
  GenerateContentConfig,
9967
9982
  GenerateContentParameters,
9968
9983
  HttpResponse,
package/dist/index.cjs CHANGED
@@ -1296,6 +1296,18 @@ exports.PartMediaResolutionLevel = void 0;
1296
1296
  */
1297
1297
  PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1298
1298
  })(exports.PartMediaResolutionLevel || (exports.PartMediaResolutionLevel = {}));
1299
+ /** Resource scope. */
1300
+ exports.ResourceScope = void 0;
1301
+ (function (ResourceScope) {
1302
+ /**
1303
+ * When setting base_url, this value configures resource scope to be the collection.
1304
+ The resource name will not include api version, project, or location.
1305
+ For example, if base_url is set to "https://aiplatform.googleapis.com",
1306
+ then the resource name for a Model would be
1307
+ "https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview
1308
+ */
1309
+ ResourceScope["COLLECTION"] = "COLLECTION";
1310
+ })(exports.ResourceScope || (exports.ResourceScope = {}));
1299
1311
  /** Options for feature selection preference. */
1300
1312
  exports.FeatureSelectionPreference = void 0;
1301
1313
  (function (FeatureSelectionPreference) {
@@ -4132,6 +4144,9 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4132
4144
  if (fromEnableEnhancedCivicAnswers != null) {
4133
4145
  setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4134
4146
  }
4147
+ if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
4148
+ throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
4149
+ }
4135
4150
  return toObject;
4136
4151
  }
4137
4152
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6905,7 +6920,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6905
6920
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6906
6921
  const USER_AGENT_HEADER = 'User-Agent';
6907
6922
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6908
- const SDK_VERSION = '1.37.0'; // x-release-please-version
6923
+ const SDK_VERSION = '1.38.0'; // x-release-please-version
6909
6924
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6910
6925
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6911
6926
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -6915,19 +6930,57 @@ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
6915
6930
  */
6916
6931
  class ApiClient {
6917
6932
  constructor(opts) {
6918
- var _a, _b;
6919
- this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
6933
+ var _a, _b, _c;
6934
+ this.clientOptions = Object.assign({}, opts);
6935
+ this.customBaseUrl = (_a = opts.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
6936
+ if (this.clientOptions.vertexai) {
6937
+ if (this.clientOptions.project && this.clientOptions.location) {
6938
+ this.clientOptions.apiKey = undefined;
6939
+ }
6940
+ else if (this.clientOptions.apiKey) {
6941
+ this.clientOptions.project = undefined;
6942
+ this.clientOptions.location = undefined;
6943
+ }
6944
+ }
6920
6945
  const initHttpOptions = {};
6921
6946
  if (this.clientOptions.vertexai) {
6947
+ if (!this.clientOptions.location &&
6948
+ !this.clientOptions.apiKey &&
6949
+ !this.customBaseUrl) {
6950
+ this.clientOptions.location = 'global';
6951
+ }
6952
+ const hasSufficientAuth = (this.clientOptions.project && this.clientOptions.location) ||
6953
+ this.clientOptions.apiKey;
6954
+ if (!hasSufficientAuth && !this.customBaseUrl) {
6955
+ throw new Error('Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.');
6956
+ }
6957
+ const hasConstructorAuth = (opts.project && opts.location) || !!opts.apiKey;
6958
+ if (this.customBaseUrl && !hasConstructorAuth) {
6959
+ initHttpOptions.baseUrl = this.customBaseUrl;
6960
+ this.clientOptions.project = undefined;
6961
+ this.clientOptions.location = undefined;
6962
+ }
6963
+ else if (this.clientOptions.apiKey ||
6964
+ this.clientOptions.location === 'global') {
6965
+ // Vertex Express or global endpoint case.
6966
+ initHttpOptions.baseUrl = 'https://aiplatform.googleapis.com/';
6967
+ }
6968
+ else if (this.clientOptions.project && this.clientOptions.location) {
6969
+ initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
6970
+ }
6922
6971
  initHttpOptions.apiVersion =
6923
- (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
6924
- initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
6925
- this.normalizeAuthParameters();
6972
+ (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : VERTEX_AI_API_DEFAULT_VERSION;
6926
6973
  }
6927
6974
  else {
6928
6975
  // Gemini API
6976
+ if (!this.clientOptions.apiKey) {
6977
+ throw new ApiError({
6978
+ message: 'API key must be set when using the Gemini API.',
6979
+ status: 403,
6980
+ });
6981
+ }
6929
6982
  initHttpOptions.apiVersion =
6930
- (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
6983
+ (_c = this.clientOptions.apiVersion) !== null && _c !== void 0 ? _c : GOOGLE_AI_API_DEFAULT_VERSION;
6931
6984
  initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
6932
6985
  }
6933
6986
  initHttpOptions.headers = this.getDefaultHeaders();
@@ -6936,39 +6989,6 @@ class ApiClient {
6936
6989
  this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
6937
6990
  }
6938
6991
  }
6939
- /**
6940
- * Determines the base URL for Vertex AI based on project and location.
6941
- * Uses the global endpoint if location is 'global' or if project/location
6942
- * are not specified (implying API key usage).
6943
- * @private
6944
- */
6945
- baseUrlFromProjectLocation() {
6946
- if (this.clientOptions.project &&
6947
- this.clientOptions.location &&
6948
- this.clientOptions.location !== 'global') {
6949
- // Regional endpoint
6950
- return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
6951
- }
6952
- // Global endpoint (covers 'global' location and API key usage)
6953
- return `https://aiplatform.googleapis.com/`;
6954
- }
6955
- /**
6956
- * Normalizes authentication parameters for Vertex AI.
6957
- * If project and location are provided, API key is cleared.
6958
- * If project and location are not provided (implying API key usage),
6959
- * project and location are cleared.
6960
- * @private
6961
- */
6962
- normalizeAuthParameters() {
6963
- if (this.clientOptions.project && this.clientOptions.location) {
6964
- // Using project/location for auth, clear potential API key
6965
- this.clientOptions.apiKey = undefined;
6966
- return;
6967
- }
6968
- // Using API key for auth (or no auth provided yet), clear project/location
6969
- this.clientOptions.project = undefined;
6970
- this.clientOptions.location = undefined;
6971
- }
6972
6992
  isVertexAI() {
6973
6993
  var _a;
6974
6994
  return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
@@ -6979,6 +6999,9 @@ class ApiClient {
6979
6999
  getLocation() {
6980
7000
  return this.clientOptions.location;
6981
7001
  }
7002
+ getCustomBaseUrl() {
7003
+ return this.customBaseUrl;
7004
+ }
6982
7005
  async getAuthHeaders() {
6983
7006
  const headers = new Headers();
6984
7007
  await this.clientOptions.auth.addAuthHeaders(headers);
@@ -7056,7 +7079,11 @@ class ApiClient {
7056
7079
  const url = new URL(`${urlElement.join('/')}`);
7057
7080
  return url;
7058
7081
  }
7059
- shouldPrependVertexProjectPath(request) {
7082
+ shouldPrependVertexProjectPath(request, httpOptions) {
7083
+ if (httpOptions.baseUrl &&
7084
+ httpOptions.baseUrlResourceScope === exports.ResourceScope.COLLECTION) {
7085
+ return false;
7086
+ }
7060
7087
  if (this.clientOptions.apiKey) {
7061
7088
  return false;
7062
7089
  }
@@ -7082,7 +7109,7 @@ class ApiClient {
7082
7109
  if (request.httpOptions) {
7083
7110
  patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
7084
7111
  }
7085
- const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
7112
+ const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
7086
7113
  const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
7087
7114
  if (request.queryParams) {
7088
7115
  for (const [key, value] of Object.entries(request.queryParams)) {
@@ -7125,7 +7152,7 @@ class ApiClient {
7125
7152
  if (request.httpOptions) {
7126
7153
  patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
7127
7154
  }
7128
- const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
7155
+ const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
7129
7156
  const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
7130
7157
  if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
7131
7158
  url.searchParams.set('alt', 'sse');
@@ -12395,6 +12422,9 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
12395
12422
  if (fromEnableEnhancedCivicAnswers != null) {
12396
12423
  setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
12397
12424
  }
12425
+ if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
12426
+ throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
12427
+ }
12398
12428
  return toObject;
12399
12429
  }
12400
12430
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -12563,6 +12593,12 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
12563
12593
  undefined) {
12564
12594
  throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
12565
12595
  }
12596
+ const fromModelArmorConfig = getValueByPath(fromObject, [
12597
+ 'modelArmorConfig',
12598
+ ]);
12599
+ if (parentObject !== undefined && fromModelArmorConfig != null) {
12600
+ setValueByPath(parentObject, ['modelArmorConfig'], fromModelArmorConfig);
12601
+ }
12566
12602
  return toObject;
12567
12603
  }
12568
12604
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -15257,8 +15293,19 @@ class Live {
15257
15293
  }
15258
15294
  const headers = mapToHeaders(clientHeaders);
15259
15295
  if (this.apiClient.isVertexAI()) {
15260
- url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
15261
- await this.auth.addAuthHeaders(headers, url);
15296
+ const project = this.apiClient.getProject();
15297
+ const location = this.apiClient.getLocation();
15298
+ const apiKey = this.apiClient.getApiKey();
15299
+ const hasStandardAuth = (!!project && !!location) || !!apiKey;
15300
+ if (this.apiClient.getCustomBaseUrl() && !hasStandardAuth) {
15301
+ // Custom base URL without standard auth (e.g., proxy).
15302
+ url = websocketBaseUrl;
15303
+ // Auth headers are assumed to be in `clientHeaders` from httpOptions.
15304
+ }
15305
+ else {
15306
+ url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
15307
+ await this.auth.addAuthHeaders(headers, url);
15308
+ }
15262
15309
  }
15263
15310
  else {
15264
15311
  const apiKey = this.apiClient.getApiKey();
@@ -15304,8 +15351,10 @@ class Live {
15304
15351
  transformedModel.startsWith('publishers/')) {
15305
15352
  const project = this.apiClient.getProject();
15306
15353
  const location = this.apiClient.getLocation();
15307
- transformedModel =
15308
- `projects/${project}/locations/${location}/` + transformedModel;
15354
+ if (project && location) {
15355
+ transformedModel =
15356
+ `projects/${project}/locations/${location}/` + transformedModel;
15357
+ }
15309
15358
  }
15310
15359
  let clientMessage = {};
15311
15360
  if (this.apiClient.isVertexAI() &&
package/dist/index.mjs CHANGED
@@ -1294,6 +1294,18 @@ var PartMediaResolutionLevel;
1294
1294
  */
1295
1295
  PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1296
1296
  })(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
1297
+ /** Resource scope. */
1298
+ var ResourceScope;
1299
+ (function (ResourceScope) {
1300
+ /**
1301
+ * When setting base_url, this value configures resource scope to be the collection.
1302
+ The resource name will not include api version, project, or location.
1303
+ For example, if base_url is set to "https://aiplatform.googleapis.com",
1304
+ then the resource name for a Model would be
1305
+ "https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview
1306
+ */
1307
+ ResourceScope["COLLECTION"] = "COLLECTION";
1308
+ })(ResourceScope || (ResourceScope = {}));
1297
1309
  /** Options for feature selection preference. */
1298
1310
  var FeatureSelectionPreference;
1299
1311
  (function (FeatureSelectionPreference) {
@@ -4130,6 +4142,9 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4130
4142
  if (fromEnableEnhancedCivicAnswers != null) {
4131
4143
  setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4132
4144
  }
4145
+ if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
4146
+ throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
4147
+ }
4133
4148
  return toObject;
4134
4149
  }
4135
4150
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6903,7 +6918,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6903
6918
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6904
6919
  const USER_AGENT_HEADER = 'User-Agent';
6905
6920
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6906
- const SDK_VERSION = '1.37.0'; // x-release-please-version
6921
+ const SDK_VERSION = '1.38.0'; // x-release-please-version
6907
6922
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6908
6923
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6909
6924
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -6913,19 +6928,57 @@ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
6913
6928
  */
6914
6929
  class ApiClient {
6915
6930
  constructor(opts) {
6916
- var _a, _b;
6917
- this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
6931
+ var _a, _b, _c;
6932
+ this.clientOptions = Object.assign({}, opts);
6933
+ this.customBaseUrl = (_a = opts.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
6934
+ if (this.clientOptions.vertexai) {
6935
+ if (this.clientOptions.project && this.clientOptions.location) {
6936
+ this.clientOptions.apiKey = undefined;
6937
+ }
6938
+ else if (this.clientOptions.apiKey) {
6939
+ this.clientOptions.project = undefined;
6940
+ this.clientOptions.location = undefined;
6941
+ }
6942
+ }
6918
6943
  const initHttpOptions = {};
6919
6944
  if (this.clientOptions.vertexai) {
6945
+ if (!this.clientOptions.location &&
6946
+ !this.clientOptions.apiKey &&
6947
+ !this.customBaseUrl) {
6948
+ this.clientOptions.location = 'global';
6949
+ }
6950
+ const hasSufficientAuth = (this.clientOptions.project && this.clientOptions.location) ||
6951
+ this.clientOptions.apiKey;
6952
+ if (!hasSufficientAuth && !this.customBaseUrl) {
6953
+ throw new Error('Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.');
6954
+ }
6955
+ const hasConstructorAuth = (opts.project && opts.location) || !!opts.apiKey;
6956
+ if (this.customBaseUrl && !hasConstructorAuth) {
6957
+ initHttpOptions.baseUrl = this.customBaseUrl;
6958
+ this.clientOptions.project = undefined;
6959
+ this.clientOptions.location = undefined;
6960
+ }
6961
+ else if (this.clientOptions.apiKey ||
6962
+ this.clientOptions.location === 'global') {
6963
+ // Vertex Express or global endpoint case.
6964
+ initHttpOptions.baseUrl = 'https://aiplatform.googleapis.com/';
6965
+ }
6966
+ else if (this.clientOptions.project && this.clientOptions.location) {
6967
+ initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
6968
+ }
6920
6969
  initHttpOptions.apiVersion =
6921
- (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
6922
- initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
6923
- this.normalizeAuthParameters();
6970
+ (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : VERTEX_AI_API_DEFAULT_VERSION;
6924
6971
  }
6925
6972
  else {
6926
6973
  // Gemini API
6974
+ if (!this.clientOptions.apiKey) {
6975
+ throw new ApiError({
6976
+ message: 'API key must be set when using the Gemini API.',
6977
+ status: 403,
6978
+ });
6979
+ }
6927
6980
  initHttpOptions.apiVersion =
6928
- (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
6981
+ (_c = this.clientOptions.apiVersion) !== null && _c !== void 0 ? _c : GOOGLE_AI_API_DEFAULT_VERSION;
6929
6982
  initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
6930
6983
  }
6931
6984
  initHttpOptions.headers = this.getDefaultHeaders();
@@ -6934,39 +6987,6 @@ class ApiClient {
6934
6987
  this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
6935
6988
  }
6936
6989
  }
6937
- /**
6938
- * Determines the base URL for Vertex AI based on project and location.
6939
- * Uses the global endpoint if location is 'global' or if project/location
6940
- * are not specified (implying API key usage).
6941
- * @private
6942
- */
6943
- baseUrlFromProjectLocation() {
6944
- if (this.clientOptions.project &&
6945
- this.clientOptions.location &&
6946
- this.clientOptions.location !== 'global') {
6947
- // Regional endpoint
6948
- return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
6949
- }
6950
- // Global endpoint (covers 'global' location and API key usage)
6951
- return `https://aiplatform.googleapis.com/`;
6952
- }
6953
- /**
6954
- * Normalizes authentication parameters for Vertex AI.
6955
- * If project and location are provided, API key is cleared.
6956
- * If project and location are not provided (implying API key usage),
6957
- * project and location are cleared.
6958
- * @private
6959
- */
6960
- normalizeAuthParameters() {
6961
- if (this.clientOptions.project && this.clientOptions.location) {
6962
- // Using project/location for auth, clear potential API key
6963
- this.clientOptions.apiKey = undefined;
6964
- return;
6965
- }
6966
- // Using API key for auth (or no auth provided yet), clear project/location
6967
- this.clientOptions.project = undefined;
6968
- this.clientOptions.location = undefined;
6969
- }
6970
6990
  isVertexAI() {
6971
6991
  var _a;
6972
6992
  return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
@@ -6977,6 +6997,9 @@ class ApiClient {
6977
6997
  getLocation() {
6978
6998
  return this.clientOptions.location;
6979
6999
  }
7000
+ getCustomBaseUrl() {
7001
+ return this.customBaseUrl;
7002
+ }
6980
7003
  async getAuthHeaders() {
6981
7004
  const headers = new Headers();
6982
7005
  await this.clientOptions.auth.addAuthHeaders(headers);
@@ -7054,7 +7077,11 @@ class ApiClient {
7054
7077
  const url = new URL(`${urlElement.join('/')}`);
7055
7078
  return url;
7056
7079
  }
7057
- shouldPrependVertexProjectPath(request) {
7080
+ shouldPrependVertexProjectPath(request, httpOptions) {
7081
+ if (httpOptions.baseUrl &&
7082
+ httpOptions.baseUrlResourceScope === ResourceScope.COLLECTION) {
7083
+ return false;
7084
+ }
7058
7085
  if (this.clientOptions.apiKey) {
7059
7086
  return false;
7060
7087
  }
@@ -7080,7 +7107,7 @@ class ApiClient {
7080
7107
  if (request.httpOptions) {
7081
7108
  patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
7082
7109
  }
7083
- const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
7110
+ const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
7084
7111
  const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
7085
7112
  if (request.queryParams) {
7086
7113
  for (const [key, value] of Object.entries(request.queryParams)) {
@@ -7123,7 +7150,7 @@ class ApiClient {
7123
7150
  if (request.httpOptions) {
7124
7151
  patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
7125
7152
  }
7126
- const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
7153
+ const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
7127
7154
  const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
7128
7155
  if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
7129
7156
  url.searchParams.set('alt', 'sse');
@@ -12393,6 +12420,9 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
12393
12420
  if (fromEnableEnhancedCivicAnswers != null) {
12394
12421
  setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
12395
12422
  }
12423
+ if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
12424
+ throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
12425
+ }
12396
12426
  return toObject;
12397
12427
  }
12398
12428
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -12561,6 +12591,12 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
12561
12591
  undefined) {
12562
12592
  throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
12563
12593
  }
12594
+ const fromModelArmorConfig = getValueByPath(fromObject, [
12595
+ 'modelArmorConfig',
12596
+ ]);
12597
+ if (parentObject !== undefined && fromModelArmorConfig != null) {
12598
+ setValueByPath(parentObject, ['modelArmorConfig'], fromModelArmorConfig);
12599
+ }
12564
12600
  return toObject;
12565
12601
  }
12566
12602
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -15255,8 +15291,19 @@ class Live {
15255
15291
  }
15256
15292
  const headers = mapToHeaders(clientHeaders);
15257
15293
  if (this.apiClient.isVertexAI()) {
15258
- url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
15259
- await this.auth.addAuthHeaders(headers, url);
15294
+ const project = this.apiClient.getProject();
15295
+ const location = this.apiClient.getLocation();
15296
+ const apiKey = this.apiClient.getApiKey();
15297
+ const hasStandardAuth = (!!project && !!location) || !!apiKey;
15298
+ if (this.apiClient.getCustomBaseUrl() && !hasStandardAuth) {
15299
+ // Custom base URL without standard auth (e.g., proxy).
15300
+ url = websocketBaseUrl;
15301
+ // Auth headers are assumed to be in `clientHeaders` from httpOptions.
15302
+ }
15303
+ else {
15304
+ url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
15305
+ await this.auth.addAuthHeaders(headers, url);
15306
+ }
15260
15307
  }
15261
15308
  else {
15262
15309
  const apiKey = this.apiClient.getApiKey();
@@ -15302,8 +15349,10 @@ class Live {
15302
15349
  transformedModel.startsWith('publishers/')) {
15303
15350
  const project = this.apiClient.getProject();
15304
15351
  const location = this.apiClient.getLocation();
15305
- transformedModel =
15306
- `projects/${project}/locations/${location}/` + transformedModel;
15352
+ if (project && location) {
15353
+ transformedModel =
15354
+ `projects/${project}/locations/${location}/` + transformedModel;
15355
+ }
15307
15356
  }
15308
15357
  let clientMessage = {};
15309
15358
  if (this.apiClient.isVertexAI() &&
@@ -19188,5 +19237,5 @@ class GoogleGenAI {
19188
19237
  }
19189
19238
  }
19190
19239
 
19191
- export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
19240
+ export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, ResourceScope, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
19192
19241
  //# sourceMappingURL=index.mjs.map