@ai-sdk/gateway 0.0.0-02dba89b-20251009204516 → 0.0.0-64aae7dd-20260114144918

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
@@ -1,5 +1,4 @@
1
1
  // src/gateway-provider.ts
2
- import { NoSuchModelError } from "@ai-sdk/provider";
3
2
  import {
4
3
  loadOptionalSetting,
5
4
  withoutTrailingSlash
@@ -71,35 +70,26 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2
71
70
  }) {
72
71
  let contextualMessage;
73
72
  if (apiKeyProvided) {
74
- contextualMessage = `AI Gateway authentication failed: Invalid API key provided.
73
+ contextualMessage = `AI Gateway authentication failed: Invalid API key.
75
74
 
76
- The token is expected to be provided via the 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
75
+ Create a new API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
76
+
77
+ Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
77
78
  } else if (oidcTokenProvided) {
78
- contextualMessage = `AI Gateway authentication failed: Invalid OIDC token provided.
79
+ contextualMessage = `AI Gateway authentication failed: Invalid OIDC token.
79
80
 
80
- The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
81
- - make sure your Vercel project settings have OIDC enabled
82
- - if running locally with 'vercel dev', the token is automatically obtained and refreshed
83
- - if running locally with your own dev server, run 'vercel env pull' to fetch the token
84
- - in production/preview, the token is automatically obtained and refreshed
81
+ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.
85
82
 
86
- Alternative: Provide an API key via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
83
+ Alternatively, use an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys`;
87
84
  } else {
88
85
  contextualMessage = `AI Gateway authentication failed: No authentication provided.
89
86
 
90
- Provide either an API key or OIDC token.
91
-
92
- API key instructions:
93
-
94
- The token is expected to be provided via the 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.
87
+ Option 1 - API key:
88
+ Create an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
89
+ Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.
95
90
 
96
- OIDC token instructions:
97
-
98
- The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
99
- - make sure your Vercel project settings have OIDC enabled
100
- - if running locally with 'vercel dev', the token is automatically obtained and refreshed
101
- - if running locally with your own dev server, run 'vercel env pull' to fetch the token
102
- - in production/preview, the token is automatically obtained and refreshed`;
91
+ Option 2 - OIDC token:
92
+ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.`;
103
93
  }
104
94
  return new _GatewayAuthenticationError({
105
95
  message: contextualMessage,
@@ -155,12 +145,17 @@ var GatewayRateLimitError = class extends (_b4 = GatewayError, _a4 = symbol4, _b
155
145
 
156
146
  // src/errors/gateway-model-not-found-error.ts
157
147
  import { z } from "zod/v4";
148
+ import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
158
149
  var name4 = "GatewayModelNotFoundError";
159
150
  var marker5 = `vercel.ai.gateway.error.${name4}`;
160
151
  var symbol5 = Symbol.for(marker5);
161
- var modelNotFoundParamSchema = z.object({
162
- modelId: z.string()
163
- });
152
+ var modelNotFoundParamSchema = lazySchema(
153
+ () => zodSchema(
154
+ z.object({
155
+ modelId: z.string()
156
+ })
157
+ )
158
+ );
164
159
  var _a5, _b5;
165
160
  var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a5 = symbol5, _b5) {
166
161
  constructor({
@@ -230,14 +225,22 @@ var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7
230
225
  };
231
226
 
232
227
  // src/errors/create-gateway-error.ts
233
- function createGatewayErrorFromResponse({
228
+ import {
229
+ lazySchema as lazySchema2,
230
+ safeValidateTypes,
231
+ zodSchema as zodSchema2
232
+ } from "@ai-sdk/provider-utils";
233
+ async function createGatewayErrorFromResponse({
234
234
  response,
235
235
  statusCode,
236
236
  defaultMessage = "Gateway request failed",
237
237
  cause,
238
238
  authMethod
239
239
  }) {
240
- const parseResult = gatewayErrorResponseSchema.safeParse(response);
240
+ const parseResult = await safeValidateTypes({
241
+ value: response,
242
+ schema: gatewayErrorResponseSchema
243
+ });
241
244
  if (!parseResult.success) {
242
245
  return new GatewayResponseError({
243
246
  message: `Invalid error response format: ${defaultMessage}`,
@@ -247,7 +250,7 @@ function createGatewayErrorFromResponse({
247
250
  cause
248
251
  });
249
252
  }
250
- const validatedResponse = parseResult.data;
253
+ const validatedResponse = parseResult.value;
251
254
  const errorType = validatedResponse.error.type;
252
255
  const message = validatedResponse.error.message;
253
256
  switch (errorType) {
@@ -263,13 +266,14 @@ function createGatewayErrorFromResponse({
263
266
  case "rate_limit_exceeded":
264
267
  return new GatewayRateLimitError({ message, statusCode, cause });
265
268
  case "model_not_found": {
266
- const modelResult = modelNotFoundParamSchema.safeParse(
267
- validatedResponse.error.param
268
- );
269
+ const modelResult = await safeValidateTypes({
270
+ value: validatedResponse.error.param,
271
+ schema: modelNotFoundParamSchema
272
+ });
269
273
  return new GatewayModelNotFoundError({
270
274
  message,
271
275
  statusCode,
272
- modelId: modelResult.success ? modelResult.data.modelId : void 0,
276
+ modelId: modelResult.success ? modelResult.value.modelId : void 0,
273
277
  cause
274
278
  });
275
279
  }
@@ -279,14 +283,18 @@ function createGatewayErrorFromResponse({
279
283
  return new GatewayInternalServerError({ message, statusCode, cause });
280
284
  }
281
285
  }
282
- var gatewayErrorResponseSchema = z2.object({
283
- error: z2.object({
284
- message: z2.string(),
285
- type: z2.string().nullish(),
286
- param: z2.unknown().nullish(),
287
- code: z2.union([z2.string(), z2.number()]).nullish()
288
- })
289
- });
286
+ var gatewayErrorResponseSchema = lazySchema2(
287
+ () => zodSchema2(
288
+ z2.object({
289
+ error: z2.object({
290
+ message: z2.string(),
291
+ type: z2.string().nullish(),
292
+ param: z2.unknown().nullish(),
293
+ code: z2.union([z2.string(), z2.number()]).nullish()
294
+ })
295
+ })
296
+ )
297
+ );
290
298
 
291
299
  // src/errors/as-gateway-error.ts
292
300
  function asGatewayError(error, authMethod) {
@@ -329,24 +337,31 @@ function extractApiCallResponse(error) {
329
337
 
330
338
  // src/errors/parse-auth-method.ts
331
339
  import { z as z3 } from "zod/v4";
340
+ import {
341
+ lazySchema as lazySchema3,
342
+ safeValidateTypes as safeValidateTypes2,
343
+ zodSchema as zodSchema3
344
+ } from "@ai-sdk/provider-utils";
332
345
  var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
333
- function parseAuthMethod(headers) {
334
- const result = gatewayAuthMethodSchema.safeParse(
335
- headers[GATEWAY_AUTH_METHOD_HEADER]
336
- );
337
- return result.success ? result.data : void 0;
346
+ async function parseAuthMethod(headers) {
347
+ const result = await safeValidateTypes2({
348
+ value: headers[GATEWAY_AUTH_METHOD_HEADER],
349
+ schema: gatewayAuthMethodSchema
350
+ });
351
+ return result.success ? result.value : void 0;
338
352
  }
339
- var gatewayAuthMethodSchema = z3.union([
340
- z3.literal("api-key"),
341
- z3.literal("oidc")
342
- ]);
353
+ var gatewayAuthMethodSchema = lazySchema3(
354
+ () => zodSchema3(z3.union([z3.literal("api-key"), z3.literal("oidc")]))
355
+ );
343
356
 
344
357
  // src/gateway-fetch-metadata.ts
345
358
  import {
346
359
  createJsonErrorResponseHandler,
347
360
  createJsonResponseHandler,
348
361
  getFromApi,
349
- resolve
362
+ lazySchema as lazySchema4,
363
+ resolve,
364
+ zodSchema as zodSchema4
350
365
  } from "@ai-sdk/provider-utils";
351
366
  import { z as z4 } from "zod/v4";
352
367
  var GatewayFetchMetadata = class {
@@ -359,7 +374,7 @@ var GatewayFetchMetadata = class {
359
374
  url: `${this.config.baseURL}/config`,
360
375
  headers: await resolve(this.config.headers()),
361
376
  successfulResponseHandler: createJsonResponseHandler(
362
- gatewayFetchMetadataSchema
377
+ gatewayAvailableModelsResponseSchema
363
378
  ),
364
379
  failedResponseHandler: createJsonErrorResponseHandler({
365
380
  errorSchema: z4.any(),
@@ -369,7 +384,7 @@ var GatewayFetchMetadata = class {
369
384
  });
370
385
  return value;
371
386
  } catch (error) {
372
- throw asGatewayError(error);
387
+ throw await asGatewayError(error);
373
388
  }
374
389
  }
375
390
  async getCredits() {
@@ -378,7 +393,9 @@ var GatewayFetchMetadata = class {
378
393
  const { value } = await getFromApi({
379
394
  url: `${baseUrl.origin}/v1/credits`,
380
395
  headers: await resolve(this.config.headers()),
381
- successfulResponseHandler: createJsonResponseHandler(gatewayCreditsSchema),
396
+ successfulResponseHandler: createJsonResponseHandler(
397
+ gatewayCreditsResponseSchema
398
+ ),
382
399
  failedResponseHandler: createJsonErrorResponseHandler({
383
400
  errorSchema: z4.any(),
384
401
  errorToMessage: (data) => data
@@ -387,44 +404,53 @@ var GatewayFetchMetadata = class {
387
404
  });
388
405
  return value;
389
406
  } catch (error) {
390
- throw asGatewayError(error);
407
+ throw await asGatewayError(error);
391
408
  }
392
409
  }
393
410
  };
394
- var gatewayLanguageModelSpecificationSchema = z4.object({
395
- specificationVersion: z4.literal("v2"),
396
- provider: z4.string(),
397
- modelId: z4.string()
398
- });
399
- var gatewayLanguageModelPricingSchema = z4.object({
400
- input: z4.string(),
401
- output: z4.string(),
402
- input_cache_read: z4.string().nullish(),
403
- input_cache_write: z4.string().nullish()
404
- }).transform(({ input, output, input_cache_read, input_cache_write }) => ({
405
- input,
406
- output,
407
- ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
408
- ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
409
- }));
410
- var gatewayLanguageModelEntrySchema = z4.object({
411
- id: z4.string(),
412
- name: z4.string(),
413
- description: z4.string().nullish(),
414
- pricing: gatewayLanguageModelPricingSchema.nullish(),
415
- specification: gatewayLanguageModelSpecificationSchema,
416
- modelType: z4.enum(["language", "embedding", "image"]).nullish()
417
- });
418
- var gatewayFetchMetadataSchema = z4.object({
419
- models: z4.array(gatewayLanguageModelEntrySchema)
420
- });
421
- var gatewayCreditsSchema = z4.object({
422
- balance: z4.string(),
423
- total_used: z4.string()
424
- }).transform(({ balance, total_used }) => ({
425
- balance,
426
- totalUsed: total_used
427
- }));
411
+ var gatewayAvailableModelsResponseSchema = lazySchema4(
412
+ () => zodSchema4(
413
+ z4.object({
414
+ models: z4.array(
415
+ z4.object({
416
+ id: z4.string(),
417
+ name: z4.string(),
418
+ description: z4.string().nullish(),
419
+ pricing: z4.object({
420
+ input: z4.string(),
421
+ output: z4.string(),
422
+ input_cache_read: z4.string().nullish(),
423
+ input_cache_write: z4.string().nullish()
424
+ }).transform(
425
+ ({ input, output, input_cache_read, input_cache_write }) => ({
426
+ input,
427
+ output,
428
+ ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
429
+ ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
430
+ })
431
+ ).nullish(),
432
+ specification: z4.object({
433
+ specificationVersion: z4.literal("v3"),
434
+ provider: z4.string(),
435
+ modelId: z4.string()
436
+ }),
437
+ modelType: z4.enum(["language", "embedding", "image"]).nullish()
438
+ })
439
+ )
440
+ })
441
+ )
442
+ );
443
+ var gatewayCreditsResponseSchema = lazySchema4(
444
+ () => zodSchema4(
445
+ z4.object({
446
+ balance: z4.string(),
447
+ total_used: z4.string()
448
+ }).transform(({ balance, total_used }) => ({
449
+ balance,
450
+ totalUsed: total_used
451
+ }))
452
+ )
453
+ );
428
454
 
429
455
  // src/gateway-language-model.ts
430
456
  import {
@@ -440,7 +466,7 @@ var GatewayLanguageModel = class {
440
466
  constructor(modelId, config) {
441
467
  this.modelId = modelId;
442
468
  this.config = config;
443
- this.specificationVersion = "v2";
469
+ this.specificationVersion = "v3";
444
470
  this.supportedUrls = { "*/*": [/.*/] };
445
471
  }
446
472
  get provider() {
@@ -486,7 +512,7 @@ var GatewayLanguageModel = class {
486
512
  warnings
487
513
  };
488
514
  } catch (error) {
489
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
515
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
490
516
  }
491
517
  }
492
518
  async doStream(options) {
@@ -541,7 +567,7 @@ var GatewayLanguageModel = class {
541
567
  response: { headers: responseHeaders }
542
568
  };
543
569
  } catch (error) {
544
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
570
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
545
571
  }
546
572
  }
547
573
  isFilePart(part) {
@@ -575,7 +601,7 @@ var GatewayLanguageModel = class {
575
601
  }
576
602
  getModelConfigHeaders(modelId, streaming) {
577
603
  return {
578
- "ai-language-model-specification-version": "2",
604
+ "ai-language-model-specification-version": "3",
579
605
  "ai-language-model-id": modelId,
580
606
  "ai-language-model-streaming": String(streaming)
581
607
  };
@@ -585,17 +611,19 @@ var GatewayLanguageModel = class {
585
611
  // src/gateway-embedding-model.ts
586
612
  import {
587
613
  combineHeaders as combineHeaders2,
588
- createJsonResponseHandler as createJsonResponseHandler3,
589
614
  createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
615
+ createJsonResponseHandler as createJsonResponseHandler3,
616
+ lazySchema as lazySchema5,
590
617
  postJsonToApi as postJsonToApi2,
591
- resolve as resolve3
618
+ resolve as resolve3,
619
+ zodSchema as zodSchema5
592
620
  } from "@ai-sdk/provider-utils";
593
621
  import { z as z6 } from "zod/v4";
594
622
  var GatewayEmbeddingModel = class {
595
623
  constructor(modelId, config) {
596
624
  this.modelId = modelId;
597
625
  this.config = config;
598
- this.specificationVersion = "v2";
626
+ this.specificationVersion = "v3";
599
627
  this.maxEmbeddingsPerCall = 2048;
600
628
  this.supportsParallelCalls = true;
601
629
  }
@@ -624,7 +652,7 @@ var GatewayEmbeddingModel = class {
624
652
  await resolve3(this.config.o11yHeaders)
625
653
  ),
626
654
  body: {
627
- input: values.length === 1 ? values[0] : values,
655
+ values,
628
656
  ...providerOptions ? { providerOptions } : {}
629
657
  },
630
658
  successfulResponseHandler: createJsonResponseHandler3(
@@ -641,10 +669,11 @@ var GatewayEmbeddingModel = class {
641
669
  embeddings: responseBody.embeddings,
642
670
  usage: (_a8 = responseBody.usage) != null ? _a8 : void 0,
643
671
  providerMetadata: responseBody.providerMetadata,
644
- response: { headers: responseHeaders, body: rawValue }
672
+ response: { headers: responseHeaders, body: rawValue },
673
+ warnings: []
645
674
  };
646
675
  } catch (error) {
647
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
676
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
648
677
  }
649
678
  }
650
679
  getUrl() {
@@ -652,16 +681,238 @@ var GatewayEmbeddingModel = class {
652
681
  }
653
682
  getModelConfigHeaders() {
654
683
  return {
655
- "ai-embedding-model-specification-version": "2",
684
+ "ai-embedding-model-specification-version": "3",
685
+ "ai-model-id": this.modelId
686
+ };
687
+ }
688
+ };
689
+ var gatewayEmbeddingResponseSchema = lazySchema5(
690
+ () => zodSchema5(
691
+ z6.object({
692
+ embeddings: z6.array(z6.array(z6.number())),
693
+ usage: z6.object({ tokens: z6.number() }).nullish(),
694
+ providerMetadata: z6.record(z6.string(), z6.record(z6.string(), z6.unknown())).optional()
695
+ })
696
+ )
697
+ );
698
+
699
+ // src/gateway-image-model.ts
700
+ import {
701
+ combineHeaders as combineHeaders3,
702
+ convertUint8ArrayToBase64,
703
+ createJsonResponseHandler as createJsonResponseHandler4,
704
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
705
+ postJsonToApi as postJsonToApi3,
706
+ resolve as resolve4
707
+ } from "@ai-sdk/provider-utils";
708
+ import { z as z7 } from "zod/v4";
709
+ var GatewayImageModel = class {
710
+ constructor(modelId, config) {
711
+ this.modelId = modelId;
712
+ this.config = config;
713
+ this.specificationVersion = "v3";
714
+ // Set a very large number to prevent client-side splitting of requests
715
+ this.maxImagesPerCall = Number.MAX_SAFE_INTEGER;
716
+ }
717
+ get provider() {
718
+ return this.config.provider;
719
+ }
720
+ async doGenerate({
721
+ prompt,
722
+ n,
723
+ size,
724
+ aspectRatio,
725
+ seed,
726
+ files,
727
+ mask,
728
+ providerOptions,
729
+ headers,
730
+ abortSignal
731
+ }) {
732
+ var _a8;
733
+ const resolvedHeaders = await resolve4(this.config.headers());
734
+ try {
735
+ const {
736
+ responseHeaders,
737
+ value: responseBody,
738
+ rawValue
739
+ } = await postJsonToApi3({
740
+ url: this.getUrl(),
741
+ headers: combineHeaders3(
742
+ resolvedHeaders,
743
+ headers != null ? headers : {},
744
+ this.getModelConfigHeaders(),
745
+ await resolve4(this.config.o11yHeaders)
746
+ ),
747
+ body: {
748
+ prompt,
749
+ n,
750
+ ...size && { size },
751
+ ...aspectRatio && { aspectRatio },
752
+ ...seed && { seed },
753
+ ...providerOptions && { providerOptions },
754
+ ...files && {
755
+ files: files.map((file) => maybeEncodeImageFile(file))
756
+ },
757
+ ...mask && { mask: maybeEncodeImageFile(mask) }
758
+ },
759
+ successfulResponseHandler: createJsonResponseHandler4(
760
+ gatewayImageResponseSchema
761
+ ),
762
+ failedResponseHandler: createJsonErrorResponseHandler4({
763
+ errorSchema: z7.any(),
764
+ errorToMessage: (data) => data
765
+ }),
766
+ ...abortSignal && { abortSignal },
767
+ fetch: this.config.fetch
768
+ });
769
+ return {
770
+ images: responseBody.images,
771
+ // Always base64 strings from server
772
+ warnings: (_a8 = responseBody.warnings) != null ? _a8 : [],
773
+ providerMetadata: responseBody.providerMetadata,
774
+ response: {
775
+ timestamp: /* @__PURE__ */ new Date(),
776
+ modelId: this.modelId,
777
+ headers: responseHeaders
778
+ }
779
+ };
780
+ } catch (error) {
781
+ throw asGatewayError(error, await parseAuthMethod(resolvedHeaders));
782
+ }
783
+ }
784
+ getUrl() {
785
+ return `${this.config.baseURL}/image-model`;
786
+ }
787
+ getModelConfigHeaders() {
788
+ return {
789
+ "ai-image-model-specification-version": "3",
656
790
  "ai-model-id": this.modelId
657
791
  };
658
792
  }
659
793
  };
660
- var gatewayEmbeddingResponseSchema = z6.object({
661
- embeddings: z6.array(z6.array(z6.number())),
662
- usage: z6.object({ tokens: z6.number() }).nullish(),
663
- providerMetadata: z6.record(z6.string(), z6.record(z6.string(), z6.unknown())).optional()
794
+ function maybeEncodeImageFile(file) {
795
+ if (file.type === "file" && file.data instanceof Uint8Array) {
796
+ return {
797
+ ...file,
798
+ data: convertUint8ArrayToBase64(file.data)
799
+ };
800
+ }
801
+ return file;
802
+ }
803
+ var providerMetadataEntrySchema = z7.object({
804
+ images: z7.array(z7.unknown()).optional()
805
+ }).catchall(z7.unknown());
806
+ var gatewayImageResponseSchema = z7.object({
807
+ images: z7.array(z7.string()),
808
+ // Always base64 strings over the wire
809
+ warnings: z7.array(
810
+ z7.object({
811
+ type: z7.literal("other"),
812
+ message: z7.string()
813
+ })
814
+ ).optional(),
815
+ providerMetadata: z7.record(z7.string(), providerMetadataEntrySchema).optional()
816
+ });
817
+
818
+ // src/tool/perplexity-search.ts
819
+ import {
820
+ createProviderToolFactoryWithOutputSchema,
821
+ lazySchema as lazySchema6,
822
+ zodSchema as zodSchema6
823
+ } from "@ai-sdk/provider-utils";
824
+ import { z as z8 } from "zod";
825
+ var perplexitySearchInputSchema = lazySchema6(
826
+ () => zodSchema6(
827
+ z8.object({
828
+ query: z8.union([z8.string(), z8.array(z8.string())]).describe(
829
+ "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
830
+ ),
831
+ max_results: z8.number().optional().describe(
832
+ "Maximum number of search results to return (1-20, default: 10)"
833
+ ),
834
+ max_tokens_per_page: z8.number().optional().describe(
835
+ "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
836
+ ),
837
+ max_tokens: z8.number().optional().describe(
838
+ "Maximum total tokens across all search results (default: 25000, max: 1000000)"
839
+ ),
840
+ country: z8.string().optional().describe(
841
+ "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
842
+ ),
843
+ search_domain_filter: z8.array(z8.string()).optional().describe(
844
+ "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
845
+ ),
846
+ search_language_filter: z8.array(z8.string()).optional().describe(
847
+ "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
848
+ ),
849
+ search_after_date: z8.string().optional().describe(
850
+ "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
851
+ ),
852
+ search_before_date: z8.string().optional().describe(
853
+ "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
854
+ ),
855
+ last_updated_after_filter: z8.string().optional().describe(
856
+ "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
857
+ ),
858
+ last_updated_before_filter: z8.string().optional().describe(
859
+ "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
860
+ ),
861
+ search_recency_filter: z8.enum(["day", "week", "month", "year"]).optional().describe(
862
+ "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
863
+ )
864
+ })
865
+ )
866
+ );
867
+ var perplexitySearchOutputSchema = lazySchema6(
868
+ () => zodSchema6(
869
+ z8.union([
870
+ // Success response
871
+ z8.object({
872
+ results: z8.array(
873
+ z8.object({
874
+ title: z8.string(),
875
+ url: z8.string(),
876
+ snippet: z8.string(),
877
+ date: z8.string().optional(),
878
+ lastUpdated: z8.string().optional()
879
+ })
880
+ ),
881
+ id: z8.string()
882
+ }),
883
+ // Error response
884
+ z8.object({
885
+ error: z8.enum([
886
+ "api_error",
887
+ "rate_limit",
888
+ "timeout",
889
+ "invalid_input",
890
+ "unknown"
891
+ ]),
892
+ statusCode: z8.number().optional(),
893
+ message: z8.string()
894
+ })
895
+ ])
896
+ )
897
+ );
898
+ var perplexitySearchToolFactory = createProviderToolFactoryWithOutputSchema({
899
+ id: "gateway.perplexity_search",
900
+ inputSchema: perplexitySearchInputSchema,
901
+ outputSchema: perplexitySearchOutputSchema
664
902
  });
903
+ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
904
+
905
+ // src/gateway-tools.ts
906
+ var gatewayTools = {
907
+ /**
908
+ * Search the web using Perplexity's Search API for real-time information,
909
+ * news, research papers, and articles.
910
+ *
911
+ * Provides ranked search results with advanced filtering options including
912
+ * domain, language, date range, and recency filters.
913
+ */
914
+ perplexitySearch
915
+ };
665
916
 
666
917
  // src/vercel-environment.ts
667
918
  import { getContext } from "@vercel/oidc";
@@ -675,7 +926,7 @@ async function getVercelRequestId() {
675
926
  import { withUserAgentSuffix } from "@ai-sdk/provider-utils";
676
927
 
677
928
  // src/version.ts
678
- var VERSION = true ? "0.0.0-02dba89b-20251009204516" : "0.0.0-test";
929
+ var VERSION = true ? "0.0.0-64aae7dd-20260114144918" : "0.0.0-test";
679
930
 
680
931
  // src/gateway-provider.ts
681
932
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -685,10 +936,10 @@ function createGatewayProvider(options = {}) {
685
936
  let metadataCache = null;
686
937
  const cacheRefreshMillis = (_a8 = options.metadataCacheRefreshMillis) != null ? _a8 : 1e3 * 60 * 5;
687
938
  let lastFetchTime = 0;
688
- const baseURL = (_b8 = withoutTrailingSlash(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
939
+ const baseURL = (_b8 = withoutTrailingSlash(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v3/ai";
689
940
  const getHeaders = async () => {
690
- const auth = await getGatewayAuthToken(options);
691
- if (auth) {
941
+ try {
942
+ const auth = await getGatewayAuthToken(options);
692
943
  return withUserAgentSuffix(
693
944
  {
694
945
  Authorization: `Bearer ${auth.token}`,
@@ -698,12 +949,14 @@ function createGatewayProvider(options = {}) {
698
949
  },
699
950
  `ai-sdk/gateway/${VERSION}`
700
951
  );
952
+ } catch (error) {
953
+ throw GatewayAuthenticationError.createContextualError({
954
+ apiKeyProvided: false,
955
+ oidcTokenProvided: false,
956
+ statusCode: 401,
957
+ cause: error
958
+ });
701
959
  }
702
- throw GatewayAuthenticationError.createContextualError({
703
- apiKeyProvided: false,
704
- oidcTokenProvided: false,
705
- statusCode: 401
706
- });
707
960
  };
708
961
  const createO11yHeaders = () => {
709
962
  const deploymentId = loadOptionalSetting({
@@ -750,7 +1003,10 @@ function createGatewayProvider(options = {}) {
750
1003
  metadataCache = metadata;
751
1004
  return metadata;
752
1005
  }).catch(async (error) => {
753
- throw asGatewayError(error, parseAuthMethod(await getHeaders()));
1006
+ throw await asGatewayError(
1007
+ error,
1008
+ await parseAuthMethod(await getHeaders())
1009
+ );
754
1010
  });
755
1011
  }
756
1012
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
@@ -761,7 +1017,10 @@ function createGatewayProvider(options = {}) {
761
1017
  headers: getHeaders,
762
1018
  fetch: options.fetch
763
1019
  }).getCredits().catch(async (error) => {
764
- throw asGatewayError(error, parseAuthMethod(await getHeaders()));
1020
+ throw await asGatewayError(
1021
+ error,
1022
+ await parseAuthMethod(await getHeaders())
1023
+ );
765
1024
  });
766
1025
  };
767
1026
  const provider = function(modelId) {
@@ -772,13 +1031,20 @@ function createGatewayProvider(options = {}) {
772
1031
  }
773
1032
  return createLanguageModel(modelId);
774
1033
  };
1034
+ provider.specificationVersion = "v3";
775
1035
  provider.getAvailableModels = getAvailableModels;
776
1036
  provider.getCredits = getCredits;
777
1037
  provider.imageModel = (modelId) => {
778
- throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1038
+ return new GatewayImageModel(modelId, {
1039
+ provider: "gateway",
1040
+ baseURL,
1041
+ headers: getHeaders,
1042
+ fetch: options.fetch,
1043
+ o11yHeaders: createO11yHeaders()
1044
+ });
779
1045
  };
780
1046
  provider.languageModel = createLanguageModel;
781
- provider.textEmbeddingModel = (modelId) => {
1047
+ const createEmbeddingModel = (modelId) => {
782
1048
  return new GatewayEmbeddingModel(modelId, {
783
1049
  provider: "gateway",
784
1050
  baseURL,
@@ -787,6 +1053,9 @@ function createGatewayProvider(options = {}) {
787
1053
  o11yHeaders: createO11yHeaders()
788
1054
  });
789
1055
  };
1056
+ provider.embeddingModel = createEmbeddingModel;
1057
+ provider.textEmbeddingModel = createEmbeddingModel;
1058
+ provider.tools = gatewayTools;
790
1059
  return provider;
791
1060
  }
792
1061
  var gateway = createGatewayProvider();
@@ -801,15 +1070,11 @@ async function getGatewayAuthToken(options) {
801
1070
  authMethod: "api-key"
802
1071
  };
803
1072
  }
804
- try {
805
- const oidcToken = await getVercelOidcToken();
806
- return {
807
- token: oidcToken,
808
- authMethod: "oidc"
809
- };
810
- } catch (e) {
811
- return null;
812
- }
1073
+ const oidcToken = await getVercelOidcToken();
1074
+ return {
1075
+ token: oidcToken,
1076
+ authMethod: "oidc"
1077
+ };
813
1078
  }
814
1079
  export {
815
1080
  GatewayAuthenticationError,