@ai-sdk/gateway 2.0.181 → 2.0.182

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/index.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  import { APICallError } from "@ai-sdk/provider";
10
10
 
11
11
  // src/errors/create-gateway-error.ts
12
- import { z as z3 } from "zod/v4";
12
+ import { z as z4 } from "zod/v4";
13
13
 
14
14
  // src/errors/gateway-error.ts
15
15
  var marker = "vercel.ai.gateway.error";
@@ -238,12 +238,51 @@ var GatewayInternalServerError = class extends (_b7 = GatewayError, _a7 = symbol
238
238
  }
239
239
  };
240
240
 
241
- // src/errors/gateway-response-error.ts
242
- var name7 = "GatewayResponseError";
241
+ // src/errors/gateway-access-policy-denied-error.ts
242
+ import { z as z3 } from "zod/v4";
243
+ import { lazyValidator as lazyValidator3, zodSchema as zodSchema3 } from "@ai-sdk/provider-utils";
244
+ var name7 = "GatewayAccessPolicyDeniedError";
243
245
  var marker8 = `vercel.ai.gateway.error.${name7}`;
244
246
  var symbol8 = Symbol.for(marker8);
247
+ var accessPolicyDeniedParamSchema = lazyValidator3(
248
+ () => zodSchema3(
249
+ z3.object({
250
+ policyIds: z3.optional(z3.array(z3.string())),
251
+ removedModels: z3.optional(z3.array(z3.string())),
252
+ removedProviders: z3.optional(z3.array(z3.string()))
253
+ })
254
+ )
255
+ );
245
256
  var _a8, _b8;
246
- var GatewayResponseError = class extends (_b8 = GatewayError, _a8 = symbol8, _b8) {
257
+ var GatewayAccessPolicyDeniedError = class extends (_b8 = GatewayError, _a8 = symbol8, _b8) {
258
+ constructor({
259
+ message = "Access policy denied",
260
+ statusCode = 403,
261
+ cause,
262
+ policyIds,
263
+ removedModels,
264
+ removedProviders
265
+ } = {}) {
266
+ super({ message, statusCode, cause });
267
+ this[_a8] = true;
268
+ // used in isInstance
269
+ this.name = name7;
270
+ this.type = "access_policy_denied";
271
+ this.policyIds = policyIds;
272
+ this.removedModels = removedModels;
273
+ this.removedProviders = removedProviders;
274
+ }
275
+ static isInstance(error) {
276
+ return GatewayError.hasMarker(error) && symbol8 in error;
277
+ }
278
+ };
279
+
280
+ // src/errors/gateway-response-error.ts
281
+ var name8 = "GatewayResponseError";
282
+ var marker9 = `vercel.ai.gateway.error.${name8}`;
283
+ var symbol9 = Symbol.for(marker9);
284
+ var _a9, _b9;
285
+ var GatewayResponseError = class extends (_b9 = GatewayError, _a9 = symbol9, _b9) {
247
286
  constructor({
248
287
  message = "Invalid response from Gateway",
249
288
  statusCode = 502,
@@ -253,23 +292,23 @@ var GatewayResponseError = class extends (_b8 = GatewayError, _a8 = symbol8, _b8
253
292
  isRetryable
254
293
  } = {}) {
255
294
  super({ message, statusCode, cause, isRetryable });
256
- this[_a8] = true;
295
+ this[_a9] = true;
257
296
  // used in isInstance
258
- this.name = name7;
297
+ this.name = name8;
259
298
  this.type = "response_error";
260
299
  this.response = response;
261
300
  this.validationError = validationError;
262
301
  }
263
302
  static isInstance(error) {
264
- return GatewayError.hasMarker(error) && symbol8 in error;
303
+ return GatewayError.hasMarker(error) && symbol9 in error;
265
304
  }
266
305
  };
267
306
 
268
307
  // src/errors/create-gateway-error.ts
269
308
  import {
270
- lazyValidator as lazyValidator3,
309
+ lazyValidator as lazyValidator4,
271
310
  safeValidateTypes,
272
- zodSchema as zodSchema3
311
+ zodSchema as zodSchema4
273
312
  } from "@ai-sdk/provider-utils";
274
313
  async function createGatewayErrorFromResponse({
275
314
  response,
@@ -334,18 +373,33 @@ async function createGatewayErrorFromResponse({
334
373
  ruleId: ruleResult.success ? ruleResult.value.ruleId : void 0
335
374
  });
336
375
  }
376
+ case "access_policy_denied": {
377
+ const paramResult = await safeValidateTypes({
378
+ value: validatedResponse.error.param,
379
+ schema: accessPolicyDeniedParamSchema
380
+ });
381
+ const param = paramResult.success ? paramResult.value : void 0;
382
+ return new GatewayAccessPolicyDeniedError({
383
+ message,
384
+ statusCode,
385
+ cause,
386
+ policyIds: param == null ? void 0 : param.policyIds,
387
+ removedModels: param == null ? void 0 : param.removedModels,
388
+ removedProviders: param == null ? void 0 : param.removedProviders
389
+ });
390
+ }
337
391
  default:
338
392
  return new GatewayInternalServerError({ message, statusCode, cause });
339
393
  }
340
394
  }
341
- var gatewayErrorResponseSchema = lazyValidator3(
342
- () => zodSchema3(
343
- z3.object({
344
- error: z3.object({
345
- message: z3.string(),
346
- type: z3.string().nullish(),
347
- param: z3.unknown().nullish(),
348
- code: z3.union([z3.string(), z3.number()]).nullish()
395
+ var gatewayErrorResponseSchema = lazyValidator4(
396
+ () => zodSchema4(
397
+ z4.object({
398
+ error: z4.object({
399
+ message: z4.string(),
400
+ type: z4.string().nullish(),
401
+ param: z4.unknown().nullish(),
402
+ code: z4.union([z4.string(), z4.number()]).nullish()
349
403
  })
350
404
  })
351
405
  )
@@ -367,24 +421,24 @@ function extractApiCallResponse(error) {
367
421
  }
368
422
 
369
423
  // src/errors/gateway-timeout-error.ts
370
- var name8 = "GatewayTimeoutError";
371
- var marker9 = `vercel.ai.gateway.error.${name8}`;
372
- var symbol9 = Symbol.for(marker9);
373
- var _a9, _b9;
374
- var GatewayTimeoutError = class _GatewayTimeoutError extends (_b9 = GatewayError, _a9 = symbol9, _b9) {
424
+ var name9 = "GatewayTimeoutError";
425
+ var marker10 = `vercel.ai.gateway.error.${name9}`;
426
+ var symbol10 = Symbol.for(marker10);
427
+ var _a10, _b10;
428
+ var GatewayTimeoutError = class _GatewayTimeoutError extends (_b10 = GatewayError, _a10 = symbol10, _b10) {
375
429
  constructor({
376
430
  message = "Request timed out",
377
431
  statusCode = 408,
378
432
  cause
379
433
  } = {}) {
380
434
  super({ message, statusCode, cause });
381
- this[_a9] = true;
435
+ this[_a10] = true;
382
436
  // used in isInstance
383
- this.name = name8;
437
+ this.name = name9;
384
438
  this.type = "timeout_error";
385
439
  }
386
440
  static isInstance(error) {
387
- return GatewayError.hasMarker(error) && symbol9 in error;
441
+ return GatewayError.hasMarker(error) && symbol10 in error;
388
442
  }
389
443
  /**
390
444
  * Creates a helpful timeout error message with troubleshooting guidance
@@ -422,7 +476,7 @@ function isTimeoutError(error) {
422
476
  return false;
423
477
  }
424
478
  async function asGatewayError(error, authMethod) {
425
- var _a10;
479
+ var _a11;
426
480
  if ((error instanceof Error || typeof DOMException === "function" && error instanceof DOMException) && (error.name === "AbortError" || error.name === "TimeoutError")) {
427
481
  throw error;
428
482
  }
@@ -444,7 +498,7 @@ async function asGatewayError(error, authMethod) {
444
498
  }
445
499
  return await createGatewayErrorFromResponse({
446
500
  response: extractApiCallResponse(error),
447
- statusCode: (_a10 = error.statusCode) != null ? _a10 : 500,
501
+ statusCode: (_a11 = error.statusCode) != null ? _a11 : 500,
448
502
  defaultMessage: "Gateway request failed",
449
503
  cause: error,
450
504
  authMethod,
@@ -461,11 +515,11 @@ async function asGatewayError(error, authMethod) {
461
515
  }
462
516
 
463
517
  // src/errors/parse-auth-method.ts
464
- import { z as z4 } from "zod/v4";
518
+ import { z as z5 } from "zod/v4";
465
519
  import {
466
- lazyValidator as lazyValidator4,
520
+ lazyValidator as lazyValidator5,
467
521
  safeValidateTypes as safeValidateTypes2,
468
- zodSchema as zodSchema4
522
+ zodSchema as zodSchema5
469
523
  } from "@ai-sdk/provider-utils";
470
524
  var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
471
525
  async function parseAuthMethod(headers) {
@@ -475,8 +529,8 @@ async function parseAuthMethod(headers) {
475
529
  });
476
530
  return result.success ? result.value : void 0;
477
531
  }
478
- var gatewayAuthMethodSchema = lazyValidator4(
479
- () => zodSchema4(z4.union([z4.literal("api-key"), z4.literal("oidc")]))
532
+ var gatewayAuthMethodSchema = lazyValidator5(
533
+ () => zodSchema5(z5.union([z5.literal("api-key"), z5.literal("oidc")]))
480
534
  );
481
535
 
482
536
  // src/gateway-fetch-metadata.ts
@@ -485,11 +539,11 @@ import {
485
539
  createJsonResponseHandler,
486
540
  getErrorMessage,
487
541
  getFromApi,
488
- lazyValidator as lazyValidator5,
542
+ lazyValidator as lazyValidator6,
489
543
  resolve,
490
- zodSchema as zodSchema5
544
+ zodSchema as zodSchema6
491
545
  } from "@ai-sdk/provider-utils";
492
- import { z as z5 } from "zod/v4";
546
+ import { z as z6 } from "zod/v4";
493
547
 
494
548
  // src/gateway-model-entry.ts
495
549
  var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
@@ -508,10 +562,10 @@ var GatewayFetchMetadata = class {
508
562
  gatewayAvailableModelsResponseSchema
509
563
  ),
510
564
  failedResponseHandler: createJsonErrorResponseHandler({
511
- errorSchema: z5.any(),
565
+ errorSchema: z6.any(),
512
566
  errorToMessage: (data) => {
513
- var _a10;
514
- return (_a10 = getErrorMessage(data)) != null ? _a10 : "unknown error";
567
+ var _a11;
568
+ return (_a11 = getErrorMessage(data)) != null ? _a11 : "unknown error";
515
569
  }
516
570
  }),
517
571
  fetch: this.config.fetch
@@ -531,10 +585,10 @@ var GatewayFetchMetadata = class {
531
585
  gatewayCreditsResponseSchema
532
586
  ),
533
587
  failedResponseHandler: createJsonErrorResponseHandler({
534
- errorSchema: z5.any(),
588
+ errorSchema: z6.any(),
535
589
  errorToMessage: (data) => {
536
- var _a10;
537
- return (_a10 = getErrorMessage(data)) != null ? _a10 : "unknown error";
590
+ var _a11;
591
+ return (_a11 = getErrorMessage(data)) != null ? _a11 : "unknown error";
538
592
  }
539
593
  }),
540
594
  fetch: this.config.fetch
@@ -545,19 +599,19 @@ var GatewayFetchMetadata = class {
545
599
  }
546
600
  }
547
601
  };
548
- var gatewayAvailableModelsResponseSchema = lazyValidator5(
549
- () => zodSchema5(
550
- z5.object({
551
- models: z5.array(
552
- z5.object({
553
- id: z5.string(),
554
- name: z5.string(),
555
- description: z5.string().nullish(),
556
- pricing: z5.object({
557
- input: z5.string(),
558
- output: z5.string(),
559
- input_cache_read: z5.string().nullish(),
560
- input_cache_write: z5.string().nullish()
602
+ var gatewayAvailableModelsResponseSchema = lazyValidator6(
603
+ () => zodSchema6(
604
+ z6.object({
605
+ models: z6.array(
606
+ z6.object({
607
+ id: z6.string(),
608
+ name: z6.string(),
609
+ description: z6.string().nullish(),
610
+ pricing: z6.object({
611
+ input: z6.string(),
612
+ output: z6.string(),
613
+ input_cache_read: z6.string().nullish(),
614
+ input_cache_write: z6.string().nullish()
561
615
  }).transform(
562
616
  ({ input, output, input_cache_read, input_cache_write }) => ({
563
617
  input,
@@ -566,12 +620,12 @@ var gatewayAvailableModelsResponseSchema = lazyValidator5(
566
620
  ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
567
621
  })
568
622
  ).nullish(),
569
- specification: z5.object({
570
- specificationVersion: z5.literal("v2"),
571
- provider: z5.string(),
572
- modelId: z5.string()
623
+ specification: z6.object({
624
+ specificationVersion: z6.literal("v2"),
625
+ provider: z6.string(),
626
+ modelId: z6.string()
573
627
  }),
574
- modelType: z5.string().nullish()
628
+ modelType: z6.string().nullish()
575
629
  })
576
630
  ).transform(
577
631
  (models) => models.filter(
@@ -581,11 +635,11 @@ var gatewayAvailableModelsResponseSchema = lazyValidator5(
581
635
  })
582
636
  )
583
637
  );
584
- var gatewayCreditsResponseSchema = lazyValidator5(
585
- () => zodSchema5(
586
- z5.object({
587
- balance: z5.string(),
588
- total_used: z5.string()
638
+ var gatewayCreditsResponseSchema = lazyValidator6(
639
+ () => zodSchema6(
640
+ z6.object({
641
+ balance: z6.string(),
642
+ total_used: z6.string()
589
643
  }).transform(({ balance, total_used }) => ({
590
644
  balance,
591
645
  totalUsed: total_used
@@ -601,9 +655,9 @@ import {
601
655
  getFromApi as getFromApi2,
602
656
  lazySchema,
603
657
  resolve as resolve2,
604
- zodSchema as zodSchema6
658
+ zodSchema as zodSchema7
605
659
  } from "@ai-sdk/provider-utils";
606
- import { z as z6 } from "zod/v4";
660
+ import { z as z7 } from "zod/v4";
607
661
  var GatewaySpendReport = class {
608
662
  constructor(config) {
609
663
  this.config = config;
@@ -642,10 +696,10 @@ var GatewaySpendReport = class {
642
696
  gatewaySpendReportResponseSchema
643
697
  ),
644
698
  failedResponseHandler: createJsonErrorResponseHandler2({
645
- errorSchema: z6.any(),
699
+ errorSchema: z7.any(),
646
700
  errorToMessage: (data) => {
647
- var _a10;
648
- return (_a10 = getErrorMessage2(data)) != null ? _a10 : "unknown error";
701
+ var _a11;
702
+ return (_a11 = getErrorMessage2(data)) != null ? _a11 : "unknown error";
649
703
  }
650
704
  }),
651
705
  fetch: this.config.fetch
@@ -657,25 +711,25 @@ var GatewaySpendReport = class {
657
711
  }
658
712
  };
659
713
  var gatewaySpendReportResponseSchema = lazySchema(
660
- () => zodSchema6(
661
- z6.object({
662
- results: z6.array(
663
- z6.object({
664
- day: z6.string().optional(),
665
- hour: z6.string().optional(),
666
- user: z6.string().optional(),
667
- model: z6.string().optional(),
668
- tag: z6.string().optional(),
669
- provider: z6.string().optional(),
670
- credential_type: z6.enum(["byok", "system"]).optional(),
671
- total_cost: z6.number(),
672
- market_cost: z6.number().optional(),
673
- input_tokens: z6.number().optional(),
674
- output_tokens: z6.number().optional(),
675
- cached_input_tokens: z6.number().optional(),
676
- cache_creation_input_tokens: z6.number().optional(),
677
- reasoning_tokens: z6.number().optional(),
678
- request_count: z6.number().optional()
714
+ () => zodSchema7(
715
+ z7.object({
716
+ results: z7.array(
717
+ z7.object({
718
+ day: z7.string().optional(),
719
+ hour: z7.string().optional(),
720
+ user: z7.string().optional(),
721
+ model: z7.string().optional(),
722
+ tag: z7.string().optional(),
723
+ provider: z7.string().optional(),
724
+ credential_type: z7.enum(["byok", "system"]).optional(),
725
+ total_cost: z7.number(),
726
+ market_cost: z7.number().optional(),
727
+ input_tokens: z7.number().optional(),
728
+ output_tokens: z7.number().optional(),
729
+ cached_input_tokens: z7.number().optional(),
730
+ cache_creation_input_tokens: z7.number().optional(),
731
+ reasoning_tokens: z7.number().optional(),
732
+ request_count: z7.number().optional()
679
733
  }).transform(
680
734
  ({
681
735
  credential_type,
@@ -714,9 +768,9 @@ import {
714
768
  getFromApi as getFromApi3,
715
769
  lazySchema as lazySchema2,
716
770
  resolve as resolve3,
717
- zodSchema as zodSchema7
771
+ zodSchema as zodSchema8
718
772
  } from "@ai-sdk/provider-utils";
719
- import { z as z7 } from "zod/v4";
773
+ import { z as z8 } from "zod/v4";
720
774
  var GatewayGenerationInfoFetcher = class {
721
775
  constructor(config) {
722
776
  this.config = config;
@@ -731,10 +785,10 @@ var GatewayGenerationInfoFetcher = class {
731
785
  gatewayGenerationInfoResponseSchema
732
786
  ),
733
787
  failedResponseHandler: createJsonErrorResponseHandler3({
734
- errorSchema: z7.any(),
788
+ errorSchema: z8.any(),
735
789
  errorToMessage: (data) => {
736
- var _a10;
737
- return (_a10 = getErrorMessage3(data)) != null ? _a10 : "unknown error";
790
+ var _a11;
791
+ return (_a11 = getErrorMessage3(data)) != null ? _a11 : "unknown error";
738
792
  }
739
793
  }),
740
794
  fetch: this.config.fetch
@@ -746,27 +800,27 @@ var GatewayGenerationInfoFetcher = class {
746
800
  }
747
801
  };
748
802
  var gatewayGenerationInfoResponseSchema = lazySchema2(
749
- () => zodSchema7(
750
- z7.object({
751
- data: z7.object({
752
- id: z7.string(),
753
- total_cost: z7.number(),
754
- upstream_inference_cost: z7.number(),
755
- usage: z7.number(),
756
- created_at: z7.string(),
757
- model: z7.string(),
758
- is_byok: z7.boolean(),
759
- provider_name: z7.string(),
760
- streamed: z7.boolean(),
761
- finish_reason: z7.string(),
762
- latency: z7.number(),
763
- generation_time: z7.number(),
764
- native_tokens_prompt: z7.number(),
765
- native_tokens_completion: z7.number(),
766
- native_tokens_reasoning: z7.number(),
767
- native_tokens_cached: z7.number(),
768
- native_tokens_cache_creation: z7.number(),
769
- billable_web_search_calls: z7.number()
803
+ () => zodSchema8(
804
+ z8.object({
805
+ data: z8.object({
806
+ id: z8.string(),
807
+ total_cost: z8.number(),
808
+ upstream_inference_cost: z8.number(),
809
+ usage: z8.number(),
810
+ created_at: z8.string(),
811
+ model: z8.string(),
812
+ is_byok: z8.boolean(),
813
+ provider_name: z8.string(),
814
+ streamed: z8.boolean(),
815
+ finish_reason: z8.string(),
816
+ latency: z8.number(),
817
+ generation_time: z8.number(),
818
+ native_tokens_prompt: z8.number(),
819
+ native_tokens_completion: z8.number(),
820
+ native_tokens_reasoning: z8.number(),
821
+ native_tokens_cached: z8.number(),
822
+ native_tokens_cache_creation: z8.number(),
823
+ billable_web_search_calls: z8.number()
770
824
  }).transform(
771
825
  ({
772
826
  total_cost,
@@ -814,7 +868,7 @@ import {
814
868
  postJsonToApi,
815
869
  resolve as resolve4
816
870
  } from "@ai-sdk/provider-utils";
817
- import { z as z8 } from "zod/v4";
871
+ import { z as z9 } from "zod/v4";
818
872
  var GatewayLanguageModel = class {
819
873
  constructor(modelId, config) {
820
874
  this.modelId = modelId;
@@ -833,7 +887,7 @@ var GatewayLanguageModel = class {
833
887
  };
834
888
  }
835
889
  async doGenerate(options) {
836
- var _a10;
890
+ var _a11;
837
891
  const { args, warnings } = await this.getArgs(options);
838
892
  const { abortSignal } = options;
839
893
  const resolvedHeaders = await resolve4(this.config.headers());
@@ -851,12 +905,12 @@ var GatewayLanguageModel = class {
851
905
  await resolve4(this.config.o11yHeaders)
852
906
  ),
853
907
  body: args,
854
- successfulResponseHandler: createJsonResponseHandler4(z8.any()),
908
+ successfulResponseHandler: createJsonResponseHandler4(z9.any()),
855
909
  failedResponseHandler: createJsonErrorResponseHandler4({
856
- errorSchema: z8.any(),
910
+ errorSchema: z9.any(),
857
911
  errorToMessage: (data) => {
858
- var _a11;
859
- return (_a11 = getErrorMessage4(data)) != null ? _a11 : "unknown error";
912
+ var _a12;
913
+ return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
860
914
  }
861
915
  }),
862
916
  ...abortSignal && { abortSignal },
@@ -866,7 +920,7 @@ var GatewayLanguageModel = class {
866
920
  ...responseBody,
867
921
  request: { body: args },
868
922
  response: { headers: responseHeaders, body: rawResponse },
869
- warnings: [...(_a10 = responseBody.warnings) != null ? _a10 : [], ...warnings]
923
+ warnings: [...(_a11 = responseBody.warnings) != null ? _a11 : [], ...warnings]
870
924
  };
871
925
  } catch (error) {
872
926
  throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
@@ -886,12 +940,12 @@ var GatewayLanguageModel = class {
886
940
  await resolve4(this.config.o11yHeaders)
887
941
  ),
888
942
  body: args,
889
- successfulResponseHandler: createEventSourceResponseHandler(z8.any()),
943
+ successfulResponseHandler: createEventSourceResponseHandler(z9.any()),
890
944
  failedResponseHandler: createJsonErrorResponseHandler4({
891
- errorSchema: z8.any(),
945
+ errorSchema: z9.any(),
892
946
  errorToMessage: (data) => {
893
- var _a10;
894
- return (_a10 = getErrorMessage4(data)) != null ? _a10 : "unknown error";
947
+ var _a11;
948
+ return (_a11 = getErrorMessage4(data)) != null ? _a11 : "unknown error";
895
949
  }
896
950
  }),
897
951
  ...abortSignal && { abortSignal },
@@ -974,12 +1028,12 @@ import {
974
1028
  createJsonErrorResponseHandler as createJsonErrorResponseHandler5,
975
1029
  createJsonResponseHandler as createJsonResponseHandler5,
976
1030
  getErrorMessage as getErrorMessage5,
977
- lazyValidator as lazyValidator6,
1031
+ lazyValidator as lazyValidator7,
978
1032
  postJsonToApi as postJsonToApi2,
979
1033
  resolve as resolve5,
980
- zodSchema as zodSchema8
1034
+ zodSchema as zodSchema9
981
1035
  } from "@ai-sdk/provider-utils";
982
- import { z as z9 } from "zod/v4";
1036
+ import { z as z10 } from "zod/v4";
983
1037
  var GatewayEmbeddingModel = class {
984
1038
  constructor(modelId, config) {
985
1039
  this.modelId = modelId;
@@ -997,7 +1051,7 @@ var GatewayEmbeddingModel = class {
997
1051
  abortSignal,
998
1052
  providerOptions
999
1053
  }) {
1000
- var _a10;
1054
+ var _a11;
1001
1055
  const resolvedHeaders = await resolve5(this.config.headers());
1002
1056
  try {
1003
1057
  const {
@@ -1020,10 +1074,10 @@ var GatewayEmbeddingModel = class {
1020
1074
  gatewayEmbeddingResponseSchema
1021
1075
  ),
1022
1076
  failedResponseHandler: createJsonErrorResponseHandler5({
1023
- errorSchema: z9.any(),
1077
+ errorSchema: z10.any(),
1024
1078
  errorToMessage: (data) => {
1025
- var _a11;
1026
- return (_a11 = getErrorMessage5(data)) != null ? _a11 : "unknown error";
1079
+ var _a12;
1080
+ return (_a12 = getErrorMessage5(data)) != null ? _a12 : "unknown error";
1027
1081
  }
1028
1082
  }),
1029
1083
  ...abortSignal && { abortSignal },
@@ -1031,7 +1085,7 @@ var GatewayEmbeddingModel = class {
1031
1085
  });
1032
1086
  return {
1033
1087
  embeddings: responseBody.embeddings,
1034
- usage: (_a10 = responseBody.usage) != null ? _a10 : void 0,
1088
+ usage: (_a11 = responseBody.usage) != null ? _a11 : void 0,
1035
1089
  providerMetadata: responseBody.providerMetadata,
1036
1090
  response: { headers: responseHeaders, body: rawValue }
1037
1091
  };
@@ -1049,12 +1103,12 @@ var GatewayEmbeddingModel = class {
1049
1103
  };
1050
1104
  }
1051
1105
  };
1052
- var gatewayEmbeddingResponseSchema = lazyValidator6(
1053
- () => zodSchema8(
1054
- z9.object({
1055
- embeddings: z9.array(z9.array(z9.number())),
1056
- usage: z9.object({ tokens: z9.number() }).nullish(),
1057
- providerMetadata: z9.record(z9.string(), z9.record(z9.string(), z9.unknown())).optional()
1106
+ var gatewayEmbeddingResponseSchema = lazyValidator7(
1107
+ () => zodSchema9(
1108
+ z10.object({
1109
+ embeddings: z10.array(z10.array(z10.number())),
1110
+ usage: z10.object({ tokens: z10.number() }).nullish(),
1111
+ providerMetadata: z10.record(z10.string(), z10.record(z10.string(), z10.unknown())).optional()
1058
1112
  })
1059
1113
  )
1060
1114
  );
@@ -1062,7 +1116,7 @@ var gatewayEmbeddingResponseSchema = lazyValidator6(
1062
1116
  // src/gateway-image-model.ts
1063
1117
  import {
1064
1118
  lazySchema as lazySchema3,
1065
- zodSchema as zodSchema9,
1119
+ zodSchema as zodSchema10,
1066
1120
  combineHeaders as combineHeaders3,
1067
1121
  createJsonErrorResponseHandler as createJsonErrorResponseHandler6,
1068
1122
  createJsonResponseHandler as createJsonResponseHandler6,
@@ -1070,7 +1124,7 @@ import {
1070
1124
  postJsonToApi as postJsonToApi3,
1071
1125
  resolve as resolve6
1072
1126
  } from "@ai-sdk/provider-utils";
1073
- import { z as z10 } from "zod/v4";
1127
+ import { z as z11 } from "zod/v4";
1074
1128
  var GatewayImageModel = class {
1075
1129
  constructor(modelId, config) {
1076
1130
  this.modelId = modelId;
@@ -1092,7 +1146,7 @@ var GatewayImageModel = class {
1092
1146
  headers,
1093
1147
  abortSignal
1094
1148
  }) {
1095
- var _a10, _b10, _c, _d;
1149
+ var _a11, _b11, _c, _d;
1096
1150
  const resolvedHeaders = await resolve6(this.config.headers());
1097
1151
  try {
1098
1152
  const {
@@ -1119,10 +1173,10 @@ var GatewayImageModel = class {
1119
1173
  gatewayImageResponseSchema
1120
1174
  ),
1121
1175
  failedResponseHandler: createJsonErrorResponseHandler6({
1122
- errorSchema: z10.any(),
1176
+ errorSchema: z11.any(),
1123
1177
  errorToMessage: (data) => {
1124
- var _a11;
1125
- return (_a11 = getErrorMessage6(data)) != null ? _a11 : "unknown error";
1178
+ var _a12;
1179
+ return (_a12 = getErrorMessage6(data)) != null ? _a12 : "unknown error";
1126
1180
  }
1127
1181
  }),
1128
1182
  ...abortSignal && { abortSignal },
@@ -1134,7 +1188,7 @@ var GatewayImageModel = class {
1134
1188
  ...responseBody.isRetryable != null && {
1135
1189
  isRetryable: responseBody.isRetryable
1136
1190
  },
1137
- warnings: (_a10 = responseBody.warnings) != null ? _a10 : [],
1191
+ warnings: (_a11 = responseBody.warnings) != null ? _a11 : [],
1138
1192
  providerMetadata: responseBody.providerMetadata,
1139
1193
  response: {
1140
1194
  timestamp: /* @__PURE__ */ new Date(),
@@ -1143,7 +1197,7 @@ var GatewayImageModel = class {
1143
1197
  },
1144
1198
  ...responseBody.usage != null && {
1145
1199
  usage: {
1146
- inputTokens: (_b10 = responseBody.usage.inputTokens) != null ? _b10 : void 0,
1200
+ inputTokens: (_b11 = responseBody.usage.inputTokens) != null ? _b11 : void 0,
1147
1201
  outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
1148
1202
  totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
1149
1203
  }
@@ -1163,27 +1217,27 @@ var GatewayImageModel = class {
1163
1217
  };
1164
1218
  }
1165
1219
  };
1166
- var providerMetadataEntrySchema = () => z10.object({
1167
- images: z10.array(z10.unknown()).optional()
1168
- }).catchall(z10.unknown());
1169
- var gatewayImageUsageSchema = () => z10.object({
1170
- inputTokens: z10.number().nullish(),
1171
- outputTokens: z10.number().nullish(),
1172
- totalTokens: z10.number().nullish()
1220
+ var providerMetadataEntrySchema = () => z11.object({
1221
+ images: z11.array(z11.unknown()).optional()
1222
+ }).catchall(z11.unknown());
1223
+ var gatewayImageUsageSchema = () => z11.object({
1224
+ inputTokens: z11.number().nullish(),
1225
+ outputTokens: z11.number().nullish(),
1226
+ totalTokens: z11.number().nullish()
1173
1227
  });
1174
1228
  var gatewayImageResponseSchema = lazySchema3(
1175
- () => zodSchema9(
1176
- z10.object({
1177
- images: z10.array(z10.string()),
1229
+ () => zodSchema10(
1230
+ z11.object({
1231
+ images: z11.array(z11.string()),
1178
1232
  // Always base64 strings over the wire
1179
- isRetryable: z10.boolean().optional(),
1180
- warnings: z10.array(
1181
- z10.object({
1182
- type: z10.literal("other"),
1183
- message: z10.string()
1233
+ isRetryable: z11.boolean().optional(),
1234
+ warnings: z11.array(
1235
+ z11.object({
1236
+ type: z11.literal("other"),
1237
+ message: z11.string()
1184
1238
  })
1185
1239
  ).optional(),
1186
- providerMetadata: z10.record(z10.string(), providerMetadataEntrySchema()).optional(),
1240
+ providerMetadata: z11.record(z11.string(), providerMetadataEntrySchema()).optional(),
1187
1241
  usage: gatewayImageUsageSchema().optional()
1188
1242
  })
1189
1243
  )
@@ -1193,9 +1247,9 @@ var gatewayImageResponseSchema = lazySchema3(
1193
1247
  import {
1194
1248
  createProviderDefinedToolFactoryWithOutputSchema,
1195
1249
  lazySchema as lazySchema4,
1196
- zodSchema as zodSchema10
1250
+ zodSchema as zodSchema11
1197
1251
  } from "@ai-sdk/provider-utils";
1198
- import { z as z11 } from "zod";
1252
+ import { z as z12 } from "zod";
1199
1253
  var parallelSearchModes = [
1200
1254
  "turbo",
1201
1255
  "fast",
@@ -1205,82 +1259,82 @@ var parallelSearchModes = [
1205
1259
  "agentic"
1206
1260
  ];
1207
1261
  var parallelSearchInputSchema = lazySchema4(
1208
- () => zodSchema10(
1209
- z11.object({
1210
- objective: z11.string().describe(
1262
+ () => zodSchema11(
1263
+ z12.object({
1264
+ objective: z12.string().describe(
1211
1265
  "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
1212
1266
  ),
1213
- search_queries: z11.array(z11.string()).optional().describe(
1267
+ search_queries: z12.array(z12.string()).optional().describe(
1214
1268
  "Provide 2-3 concise keyword queries, 3-6 words each (max 5, 200 chars each). Strongly recommended; the search runs on these queries."
1215
1269
  ),
1216
- mode: z11.enum(parallelSearchModes).optional().describe(
1270
+ mode: z12.enum(parallelSearchModes).optional().describe(
1217
1271
  'Search mode: "turbo" and "fast" return quickly with shorter excerpts, "basic" is balanced (default), "advanced" is the most thorough. "turbo" supports English and Japanese only. "one-shot" and "agentic" are deprecated aliases of "basic" and "advanced".'
1218
1272
  ),
1219
- max_results: z11.number().optional().describe(
1273
+ max_results: z12.number().optional().describe(
1220
1274
  "Maximum number of results to return (1-20). Defaults to 10 if not specified."
1221
1275
  ),
1222
- source_policy: z11.object({
1223
- include_domains: z11.array(z11.string()).optional().describe(
1276
+ source_policy: z12.object({
1277
+ include_domains: z12.array(z12.string()).optional().describe(
1224
1278
  "Domains or domain/path prefixes to restrict results to, without scheme or port. Example: ['wikipedia.org', 'docs.python.org/3']."
1225
1279
  ),
1226
- exclude_domains: z11.array(z11.string()).optional().describe(
1280
+ exclude_domains: z12.array(z12.string()).optional().describe(
1227
1281
  "Domains or domain/path prefixes to exclude, without scheme or port. Example: ['reddit.com']."
1228
1282
  ),
1229
- after_date: z11.string().optional().describe(
1283
+ after_date: z12.string().optional().describe(
1230
1284
  "Only include results published on or after this date. Use an ISO 8601 calendar date formatted YYYY-MM-DD (e.g. 2025-01-01); do not include a time."
1231
1285
  )
1232
1286
  }).optional().describe(
1233
1287
  "Source policy for controlling which domains to include/exclude and freshness."
1234
1288
  ),
1235
- excerpts: z11.object({
1236
- max_chars_per_result: z11.number().optional().describe("Maximum characters per result."),
1237
- max_chars_total: z11.number().optional().describe("Deprecated: use the top-level max_chars_total.")
1289
+ excerpts: z12.object({
1290
+ max_chars_per_result: z12.number().optional().describe("Maximum characters per result."),
1291
+ max_chars_total: z12.number().optional().describe("Deprecated: use the top-level max_chars_total.")
1238
1292
  }).optional().describe("Excerpt configuration for controlling result length."),
1239
- max_chars_total: z11.number().optional().describe("Maximum total characters across all result excerpts."),
1240
- fetch_policy: z11.object({
1241
- max_age_seconds: z11.number().optional().describe(
1293
+ max_chars_total: z12.number().optional().describe("Maximum total characters across all result excerpts."),
1294
+ fetch_policy: z12.object({
1295
+ max_age_seconds: z12.number().optional().describe(
1242
1296
  "Maximum age of cached content in seconds before a live fetch, minimum 600."
1243
1297
  ),
1244
- timeout_seconds: z11.number().optional().describe(
1298
+ timeout_seconds: z12.number().optional().describe(
1245
1299
  "Timeout in seconds for a live fetch when content is not cached. Capped by the gateway tool timeout."
1246
1300
  ),
1247
- disable_cache_fallback: z11.boolean().optional().describe(
1301
+ disable_cache_fallback: z12.boolean().optional().describe(
1248
1302
  "Return an error instead of older cached content when a live fetch fails."
1249
1303
  )
1250
1304
  }).optional().describe("Fetch policy for controlling content freshness."),
1251
- location: z11.string().optional().describe(
1305
+ location: z12.string().optional().describe(
1252
1306
  'ISO 3166-1 alpha-2 country code to localize results, e.g. "us".'
1253
1307
  )
1254
1308
  })
1255
1309
  )
1256
1310
  );
1257
1311
  var parallelSearchOutputSchema = lazySchema4(
1258
- () => zodSchema10(
1259
- z11.union([
1312
+ () => zodSchema11(
1313
+ z12.union([
1260
1314
  // Success response (Parallel's response, passed through by the gateway)
1261
- z11.object({
1262
- search_id: z11.string(),
1263
- results: z11.array(
1264
- z11.object({
1265
- url: z11.string(),
1266
- title: z11.string().nullable().optional(),
1267
- publish_date: z11.string().nullable().optional(),
1268
- excerpts: z11.array(z11.string())
1315
+ z12.object({
1316
+ search_id: z12.string(),
1317
+ results: z12.array(
1318
+ z12.object({
1319
+ url: z12.string(),
1320
+ title: z12.string().nullable().optional(),
1321
+ publish_date: z12.string().nullable().optional(),
1322
+ excerpts: z12.array(z12.string())
1269
1323
  })
1270
1324
  ),
1271
- warnings: z11.array(
1272
- z11.object({
1273
- type: z11.string(),
1274
- message: z11.string(),
1275
- detail: z11.record(z11.string(), z11.unknown()).nullable().optional()
1325
+ warnings: z12.array(
1326
+ z12.object({
1327
+ type: z12.string(),
1328
+ message: z12.string(),
1329
+ detail: z12.record(z12.string(), z12.unknown()).nullable().optional()
1276
1330
  })
1277
1331
  ).nullable().optional(),
1278
- usage: z11.array(z11.object({ name: z11.string(), count: z11.number().optional() })).nullable().optional(),
1279
- session_id: z11.string().optional()
1332
+ usage: z12.array(z12.object({ name: z12.string(), count: z12.number().optional() })).nullable().optional(),
1333
+ session_id: z12.string().optional()
1280
1334
  }),
1281
1335
  // Error response
1282
- z11.object({
1283
- error: z11.enum([
1336
+ z12.object({
1337
+ error: z12.enum([
1284
1338
  "api_error",
1285
1339
  "configuration_error",
1286
1340
  "execution_error",
@@ -1291,8 +1345,8 @@ var parallelSearchOutputSchema = lazySchema4(
1291
1345
  "unknown",
1292
1346
  "unknown_tool"
1293
1347
  ]),
1294
- statusCode: z11.number().optional(),
1295
- message: z11.string()
1348
+ statusCode: z12.number().optional(),
1349
+ message: z12.string()
1296
1350
  })
1297
1351
  ])
1298
1352
  )
@@ -1309,78 +1363,78 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
1309
1363
  import {
1310
1364
  createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema2,
1311
1365
  lazySchema as lazySchema5,
1312
- zodSchema as zodSchema11
1366
+ zodSchema as zodSchema12
1313
1367
  } from "@ai-sdk/provider-utils";
1314
- import { z as z12 } from "zod";
1368
+ import { z as z13 } from "zod";
1315
1369
  var perplexitySearchInputSchema = lazySchema5(
1316
- () => zodSchema11(
1317
- z12.object({
1318
- query: z12.union([z12.string(), z12.array(z12.string())]).describe(
1370
+ () => zodSchema12(
1371
+ z13.object({
1372
+ query: z13.union([z13.string(), z13.array(z13.string())]).describe(
1319
1373
  "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
1320
1374
  ),
1321
- max_results: z12.number().optional().describe(
1375
+ max_results: z13.number().optional().describe(
1322
1376
  "Maximum number of search results to return (1-20, default: 10)"
1323
1377
  ),
1324
- max_tokens_per_page: z12.number().optional().describe(
1378
+ max_tokens_per_page: z13.number().optional().describe(
1325
1379
  "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
1326
1380
  ),
1327
- max_tokens: z12.number().optional().describe(
1381
+ max_tokens: z13.number().optional().describe(
1328
1382
  "Maximum total tokens across all search results (default: 25000, max: 1000000)"
1329
1383
  ),
1330
- country: z12.string().optional().describe(
1384
+ country: z13.string().optional().describe(
1331
1385
  "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
1332
1386
  ),
1333
- search_domain_filter: z12.array(z12.string()).optional().describe(
1387
+ search_domain_filter: z13.array(z13.string()).optional().describe(
1334
1388
  "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
1335
1389
  ),
1336
- search_language_filter: z12.array(z12.string()).optional().describe(
1390
+ search_language_filter: z13.array(z13.string()).optional().describe(
1337
1391
  "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
1338
1392
  ),
1339
- search_after_date: z12.string().optional().describe(
1393
+ search_after_date: z13.string().optional().describe(
1340
1394
  "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1341
1395
  ),
1342
- search_before_date: z12.string().optional().describe(
1396
+ search_before_date: z13.string().optional().describe(
1343
1397
  "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1344
1398
  ),
1345
- last_updated_after_filter: z12.string().optional().describe(
1399
+ last_updated_after_filter: z13.string().optional().describe(
1346
1400
  "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1347
1401
  ),
1348
- last_updated_before_filter: z12.string().optional().describe(
1402
+ last_updated_before_filter: z13.string().optional().describe(
1349
1403
  "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1350
1404
  ),
1351
- search_recency_filter: z12.enum(["day", "week", "month", "year"]).optional().describe(
1405
+ search_recency_filter: z13.enum(["day", "week", "month", "year"]).optional().describe(
1352
1406
  "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
1353
1407
  )
1354
1408
  })
1355
1409
  )
1356
1410
  );
1357
1411
  var perplexitySearchOutputSchema = lazySchema5(
1358
- () => zodSchema11(
1359
- z12.union([
1412
+ () => zodSchema12(
1413
+ z13.union([
1360
1414
  // Success response
1361
- z12.object({
1362
- results: z12.array(
1363
- z12.object({
1364
- title: z12.string(),
1365
- url: z12.string(),
1366
- snippet: z12.string(),
1367
- date: z12.string().optional(),
1368
- lastUpdated: z12.string().optional()
1415
+ z13.object({
1416
+ results: z13.array(
1417
+ z13.object({
1418
+ title: z13.string(),
1419
+ url: z13.string(),
1420
+ snippet: z13.string(),
1421
+ date: z13.string().optional(),
1422
+ lastUpdated: z13.string().optional()
1369
1423
  })
1370
1424
  ),
1371
- id: z12.string()
1425
+ id: z13.string()
1372
1426
  }),
1373
1427
  // Error response
1374
- z12.object({
1375
- error: z12.enum([
1428
+ z13.object({
1429
+ error: z13.enum([
1376
1430
  "api_error",
1377
1431
  "rate_limit",
1378
1432
  "timeout",
1379
1433
  "invalid_input",
1380
1434
  "unknown"
1381
1435
  ]),
1382
- statusCode: z12.number().optional(),
1383
- message: z12.string()
1436
+ statusCode: z13.number().optional(),
1437
+ message: z13.string()
1384
1438
  })
1385
1439
  ])
1386
1440
  )
@@ -1418,22 +1472,22 @@ var gatewayTools = {
1418
1472
  import { getContext } from "@vercel/oidc";
1419
1473
  import { getVercelOidcToken } from "@vercel/oidc";
1420
1474
  async function getVercelRequestId() {
1421
- var _a10;
1422
- return (_a10 = getContext().headers) == null ? void 0 : _a10["x-vercel-id"];
1475
+ var _a11;
1476
+ return (_a11 = getContext().headers) == null ? void 0 : _a11["x-vercel-id"];
1423
1477
  }
1424
1478
 
1425
1479
  // src/version.ts
1426
- var VERSION = true ? "2.0.181" : "0.0.0-test";
1480
+ var VERSION = true ? "2.0.182" : "0.0.0-test";
1427
1481
 
1428
1482
  // src/gateway-provider.ts
1429
1483
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
1430
1484
  function createGatewayProvider(options = {}) {
1431
- var _a10, _b10;
1485
+ var _a11, _b11;
1432
1486
  let pendingMetadata = null;
1433
1487
  let metadataCache = null;
1434
- const cacheRefreshMillis = (_a10 = options.metadataCacheRefreshMillis) != null ? _a10 : 1e3 * 60 * 5;
1488
+ const cacheRefreshMillis = (_a11 = options.metadataCacheRefreshMillis) != null ? _a11 : 1e3 * 60 * 5;
1435
1489
  let lastFetchTime = 0;
1436
- const baseURL = (_b10 = withoutTrailingSlash(options.baseURL)) != null ? _b10 : "https://ai-gateway.vercel.sh/v1/ai";
1490
+ const baseURL = (_b11 = withoutTrailingSlash(options.baseURL)) != null ? _b11 : "https://ai-gateway.vercel.sh/v1/ai";
1437
1491
  const getHeaders = async () => {
1438
1492
  const auth = await getGatewayAuthToken(options);
1439
1493
  if (auth) {
@@ -1491,8 +1545,8 @@ function createGatewayProvider(options = {}) {
1491
1545
  });
1492
1546
  };
1493
1547
  const getAvailableModels = async () => {
1494
- var _a11, _b11, _c;
1495
- const now = (_c = (_b11 = (_a11 = options._internal) == null ? void 0 : _a11.currentDate) == null ? void 0 : _b11.call(_a11).getTime()) != null ? _c : Date.now();
1548
+ var _a12, _b12, _c;
1549
+ const now = (_c = (_b12 = (_a12 = options._internal) == null ? void 0 : _a12.currentDate) == null ? void 0 : _b12.call(_a12).getTime()) != null ? _c : Date.now();
1496
1550
  if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
1497
1551
  lastFetchTime = now;
1498
1552
  pendingMetadata = new GatewayFetchMetadata({
@@ -1604,6 +1658,7 @@ async function getGatewayAuthToken(options) {
1604
1658
  }
1605
1659
  }
1606
1660
  export {
1661
+ GatewayAccessPolicyDeniedError,
1607
1662
  GatewayAuthenticationError,
1608
1663
  GatewayError,
1609
1664
  GatewayForbiddenError,