@ai-sdk/gateway 0.0.0-02dba89b-20251009204516 → 0.0.0-1c33ba03-20260114162300

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.js CHANGED
@@ -34,8 +34,7 @@ __export(src_exports, {
34
34
  module.exports = __toCommonJS(src_exports);
35
35
 
36
36
  // src/gateway-provider.ts
37
- var import_provider2 = require("@ai-sdk/provider");
38
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
37
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
39
38
 
40
39
  // src/errors/as-gateway-error.ts
41
40
  var import_provider = require("@ai-sdk/provider");
@@ -103,35 +102,26 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2
103
102
  }) {
104
103
  let contextualMessage;
105
104
  if (apiKeyProvided) {
106
- contextualMessage = `AI Gateway authentication failed: Invalid API key provided.
105
+ contextualMessage = `AI Gateway authentication failed: Invalid API key.
106
+
107
+ Create a new API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
107
108
 
108
- The token is expected to be provided via the 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
109
+ Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
109
110
  } else if (oidcTokenProvided) {
110
- contextualMessage = `AI Gateway authentication failed: Invalid OIDC token provided.
111
+ contextualMessage = `AI Gateway authentication failed: Invalid OIDC token.
111
112
 
112
- The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
113
- - make sure your Vercel project settings have OIDC enabled
114
- - if running locally with 'vercel dev', the token is automatically obtained and refreshed
115
- - if running locally with your own dev server, run 'vercel env pull' to fetch the token
116
- - in production/preview, the token is automatically obtained and refreshed
113
+ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.
117
114
 
118
- Alternative: Provide an API key via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
115
+ Alternatively, use an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys`;
119
116
  } else {
120
117
  contextualMessage = `AI Gateway authentication failed: No authentication provided.
121
118
 
122
- Provide either an API key or OIDC token.
123
-
124
- API key instructions:
119
+ Option 1 - API key:
120
+ Create an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
121
+ Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.
125
122
 
126
- The token is expected to be provided via the 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.
127
-
128
- OIDC token instructions:
129
-
130
- The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
131
- - make sure your Vercel project settings have OIDC enabled
132
- - if running locally with 'vercel dev', the token is automatically obtained and refreshed
133
- - if running locally with your own dev server, run 'vercel env pull' to fetch the token
134
- - in production/preview, the token is automatically obtained and refreshed`;
123
+ Option 2 - OIDC token:
124
+ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.`;
135
125
  }
136
126
  return new _GatewayAuthenticationError({
137
127
  message: contextualMessage,
@@ -187,12 +177,17 @@ var GatewayRateLimitError = class extends (_b4 = GatewayError, _a4 = symbol4, _b
187
177
 
188
178
  // src/errors/gateway-model-not-found-error.ts
189
179
  var import_v4 = require("zod/v4");
180
+ var import_provider_utils = require("@ai-sdk/provider-utils");
190
181
  var name4 = "GatewayModelNotFoundError";
191
182
  var marker5 = `vercel.ai.gateway.error.${name4}`;
192
183
  var symbol5 = Symbol.for(marker5);
193
- var modelNotFoundParamSchema = import_v4.z.object({
194
- modelId: import_v4.z.string()
195
- });
184
+ var modelNotFoundParamSchema = (0, import_provider_utils.lazySchema)(
185
+ () => (0, import_provider_utils.zodSchema)(
186
+ import_v4.z.object({
187
+ modelId: import_v4.z.string()
188
+ })
189
+ )
190
+ );
196
191
  var _a5, _b5;
197
192
  var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a5 = symbol5, _b5) {
198
193
  constructor({
@@ -262,14 +257,18 @@ var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7
262
257
  };
263
258
 
264
259
  // src/errors/create-gateway-error.ts
265
- function createGatewayErrorFromResponse({
260
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
261
+ async function createGatewayErrorFromResponse({
266
262
  response,
267
263
  statusCode,
268
264
  defaultMessage = "Gateway request failed",
269
265
  cause,
270
266
  authMethod
271
267
  }) {
272
- const parseResult = gatewayErrorResponseSchema.safeParse(response);
268
+ const parseResult = await (0, import_provider_utils2.safeValidateTypes)({
269
+ value: response,
270
+ schema: gatewayErrorResponseSchema
271
+ });
273
272
  if (!parseResult.success) {
274
273
  return new GatewayResponseError({
275
274
  message: `Invalid error response format: ${defaultMessage}`,
@@ -279,7 +278,7 @@ function createGatewayErrorFromResponse({
279
278
  cause
280
279
  });
281
280
  }
282
- const validatedResponse = parseResult.data;
281
+ const validatedResponse = parseResult.value;
283
282
  const errorType = validatedResponse.error.type;
284
283
  const message = validatedResponse.error.message;
285
284
  switch (errorType) {
@@ -295,13 +294,14 @@ function createGatewayErrorFromResponse({
295
294
  case "rate_limit_exceeded":
296
295
  return new GatewayRateLimitError({ message, statusCode, cause });
297
296
  case "model_not_found": {
298
- const modelResult = modelNotFoundParamSchema.safeParse(
299
- validatedResponse.error.param
300
- );
297
+ const modelResult = await (0, import_provider_utils2.safeValidateTypes)({
298
+ value: validatedResponse.error.param,
299
+ schema: modelNotFoundParamSchema
300
+ });
301
301
  return new GatewayModelNotFoundError({
302
302
  message,
303
303
  statusCode,
304
- modelId: modelResult.success ? modelResult.data.modelId : void 0,
304
+ modelId: modelResult.success ? modelResult.value.modelId : void 0,
305
305
  cause
306
306
  });
307
307
  }
@@ -311,14 +311,18 @@ function createGatewayErrorFromResponse({
311
311
  return new GatewayInternalServerError({ message, statusCode, cause });
312
312
  }
313
313
  }
314
- var gatewayErrorResponseSchema = import_v42.z.object({
315
- error: import_v42.z.object({
316
- message: import_v42.z.string(),
317
- type: import_v42.z.string().nullish(),
318
- param: import_v42.z.unknown().nullish(),
319
- code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
320
- })
321
- });
314
+ var gatewayErrorResponseSchema = (0, import_provider_utils2.lazySchema)(
315
+ () => (0, import_provider_utils2.zodSchema)(
316
+ import_v42.z.object({
317
+ error: import_v42.z.object({
318
+ message: import_v42.z.string(),
319
+ type: import_v42.z.string().nullish(),
320
+ param: import_v42.z.unknown().nullish(),
321
+ code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
322
+ })
323
+ })
324
+ )
325
+ );
322
326
 
323
327
  // src/errors/as-gateway-error.ts
324
328
  function asGatewayError(error, authMethod) {
@@ -361,20 +365,21 @@ function extractApiCallResponse(error) {
361
365
 
362
366
  // src/errors/parse-auth-method.ts
363
367
  var import_v43 = require("zod/v4");
368
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
364
369
  var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
365
- function parseAuthMethod(headers) {
366
- const result = gatewayAuthMethodSchema.safeParse(
367
- headers[GATEWAY_AUTH_METHOD_HEADER]
368
- );
369
- return result.success ? result.data : void 0;
370
+ async function parseAuthMethod(headers) {
371
+ const result = await (0, import_provider_utils3.safeValidateTypes)({
372
+ value: headers[GATEWAY_AUTH_METHOD_HEADER],
373
+ schema: gatewayAuthMethodSchema
374
+ });
375
+ return result.success ? result.value : void 0;
370
376
  }
371
- var gatewayAuthMethodSchema = import_v43.z.union([
372
- import_v43.z.literal("api-key"),
373
- import_v43.z.literal("oidc")
374
- ]);
377
+ var gatewayAuthMethodSchema = (0, import_provider_utils3.lazySchema)(
378
+ () => (0, import_provider_utils3.zodSchema)(import_v43.z.union([import_v43.z.literal("api-key"), import_v43.z.literal("oidc")]))
379
+ );
375
380
 
376
381
  // src/gateway-fetch-metadata.ts
377
- var import_provider_utils = require("@ai-sdk/provider-utils");
382
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
378
383
  var import_v44 = require("zod/v4");
379
384
  var GatewayFetchMetadata = class {
380
385
  constructor(config) {
@@ -382,13 +387,13 @@ var GatewayFetchMetadata = class {
382
387
  }
383
388
  async getAvailableModels() {
384
389
  try {
385
- const { value } = await (0, import_provider_utils.getFromApi)({
390
+ const { value } = await (0, import_provider_utils4.getFromApi)({
386
391
  url: `${this.config.baseURL}/config`,
387
- headers: await (0, import_provider_utils.resolve)(this.config.headers()),
388
- successfulResponseHandler: (0, import_provider_utils.createJsonResponseHandler)(
389
- gatewayFetchMetadataSchema
392
+ headers: await (0, import_provider_utils4.resolve)(this.config.headers()),
393
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
394
+ gatewayAvailableModelsResponseSchema
390
395
  ),
391
- failedResponseHandler: (0, import_provider_utils.createJsonErrorResponseHandler)({
396
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
392
397
  errorSchema: import_v44.z.any(),
393
398
  errorToMessage: (data) => data
394
399
  }),
@@ -396,17 +401,19 @@ var GatewayFetchMetadata = class {
396
401
  });
397
402
  return value;
398
403
  } catch (error) {
399
- throw asGatewayError(error);
404
+ throw await asGatewayError(error);
400
405
  }
401
406
  }
402
407
  async getCredits() {
403
408
  try {
404
409
  const baseUrl = new URL(this.config.baseURL);
405
- const { value } = await (0, import_provider_utils.getFromApi)({
410
+ const { value } = await (0, import_provider_utils4.getFromApi)({
406
411
  url: `${baseUrl.origin}/v1/credits`,
407
- headers: await (0, import_provider_utils.resolve)(this.config.headers()),
408
- successfulResponseHandler: (0, import_provider_utils.createJsonResponseHandler)(gatewayCreditsSchema),
409
- failedResponseHandler: (0, import_provider_utils.createJsonErrorResponseHandler)({
412
+ headers: await (0, import_provider_utils4.resolve)(this.config.headers()),
413
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
414
+ gatewayCreditsResponseSchema
415
+ ),
416
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
410
417
  errorSchema: import_v44.z.any(),
411
418
  errorToMessage: (data) => data
412
419
  }),
@@ -414,53 +421,62 @@ var GatewayFetchMetadata = class {
414
421
  });
415
422
  return value;
416
423
  } catch (error) {
417
- throw asGatewayError(error);
424
+ throw await asGatewayError(error);
418
425
  }
419
426
  }
420
427
  };
421
- var gatewayLanguageModelSpecificationSchema = import_v44.z.object({
422
- specificationVersion: import_v44.z.literal("v2"),
423
- provider: import_v44.z.string(),
424
- modelId: import_v44.z.string()
425
- });
426
- var gatewayLanguageModelPricingSchema = import_v44.z.object({
427
- input: import_v44.z.string(),
428
- output: import_v44.z.string(),
429
- input_cache_read: import_v44.z.string().nullish(),
430
- input_cache_write: import_v44.z.string().nullish()
431
- }).transform(({ input, output, input_cache_read, input_cache_write }) => ({
432
- input,
433
- output,
434
- ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
435
- ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
436
- }));
437
- var gatewayLanguageModelEntrySchema = import_v44.z.object({
438
- id: import_v44.z.string(),
439
- name: import_v44.z.string(),
440
- description: import_v44.z.string().nullish(),
441
- pricing: gatewayLanguageModelPricingSchema.nullish(),
442
- specification: gatewayLanguageModelSpecificationSchema,
443
- modelType: import_v44.z.enum(["language", "embedding", "image"]).nullish()
444
- });
445
- var gatewayFetchMetadataSchema = import_v44.z.object({
446
- models: import_v44.z.array(gatewayLanguageModelEntrySchema)
447
- });
448
- var gatewayCreditsSchema = import_v44.z.object({
449
- balance: import_v44.z.string(),
450
- total_used: import_v44.z.string()
451
- }).transform(({ balance, total_used }) => ({
452
- balance,
453
- totalUsed: total_used
454
- }));
428
+ var gatewayAvailableModelsResponseSchema = (0, import_provider_utils4.lazySchema)(
429
+ () => (0, import_provider_utils4.zodSchema)(
430
+ import_v44.z.object({
431
+ models: import_v44.z.array(
432
+ import_v44.z.object({
433
+ id: import_v44.z.string(),
434
+ name: import_v44.z.string(),
435
+ description: import_v44.z.string().nullish(),
436
+ pricing: import_v44.z.object({
437
+ input: import_v44.z.string(),
438
+ output: import_v44.z.string(),
439
+ input_cache_read: import_v44.z.string().nullish(),
440
+ input_cache_write: import_v44.z.string().nullish()
441
+ }).transform(
442
+ ({ input, output, input_cache_read, input_cache_write }) => ({
443
+ input,
444
+ output,
445
+ ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
446
+ ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
447
+ })
448
+ ).nullish(),
449
+ specification: import_v44.z.object({
450
+ specificationVersion: import_v44.z.literal("v3"),
451
+ provider: import_v44.z.string(),
452
+ modelId: import_v44.z.string()
453
+ }),
454
+ modelType: import_v44.z.enum(["language", "embedding", "image"]).nullish()
455
+ })
456
+ )
457
+ })
458
+ )
459
+ );
460
+ var gatewayCreditsResponseSchema = (0, import_provider_utils4.lazySchema)(
461
+ () => (0, import_provider_utils4.zodSchema)(
462
+ import_v44.z.object({
463
+ balance: import_v44.z.string(),
464
+ total_used: import_v44.z.string()
465
+ }).transform(({ balance, total_used }) => ({
466
+ balance,
467
+ totalUsed: total_used
468
+ }))
469
+ )
470
+ );
455
471
 
456
472
  // src/gateway-language-model.ts
457
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
473
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
458
474
  var import_v45 = require("zod/v4");
459
475
  var GatewayLanguageModel = class {
460
476
  constructor(modelId, config) {
461
477
  this.modelId = modelId;
462
478
  this.config = config;
463
- this.specificationVersion = "v2";
479
+ this.specificationVersion = "v3";
464
480
  this.supportedUrls = { "*/*": [/.*/] };
465
481
  }
466
482
  get provider() {
@@ -476,23 +492,23 @@ var GatewayLanguageModel = class {
476
492
  async doGenerate(options) {
477
493
  const { args, warnings } = await this.getArgs(options);
478
494
  const { abortSignal } = options;
479
- const resolvedHeaders = await (0, import_provider_utils2.resolve)(this.config.headers());
495
+ const resolvedHeaders = await (0, import_provider_utils5.resolve)(this.config.headers());
480
496
  try {
481
497
  const {
482
498
  responseHeaders,
483
499
  value: responseBody,
484
500
  rawValue: rawResponse
485
- } = await (0, import_provider_utils2.postJsonToApi)({
501
+ } = await (0, import_provider_utils5.postJsonToApi)({
486
502
  url: this.getUrl(),
487
- headers: (0, import_provider_utils2.combineHeaders)(
503
+ headers: (0, import_provider_utils5.combineHeaders)(
488
504
  resolvedHeaders,
489
505
  options.headers,
490
506
  this.getModelConfigHeaders(this.modelId, false),
491
- await (0, import_provider_utils2.resolve)(this.config.o11yHeaders)
507
+ await (0, import_provider_utils5.resolve)(this.config.o11yHeaders)
492
508
  ),
493
509
  body: args,
494
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(import_v45.z.any()),
495
- failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
510
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(import_v45.z.any()),
511
+ failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
496
512
  errorSchema: import_v45.z.any(),
497
513
  errorToMessage: (data) => data
498
514
  }),
@@ -506,25 +522,25 @@ var GatewayLanguageModel = class {
506
522
  warnings
507
523
  };
508
524
  } catch (error) {
509
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
525
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
510
526
  }
511
527
  }
512
528
  async doStream(options) {
513
529
  const { args, warnings } = await this.getArgs(options);
514
530
  const { abortSignal } = options;
515
- const resolvedHeaders = await (0, import_provider_utils2.resolve)(this.config.headers());
531
+ const resolvedHeaders = await (0, import_provider_utils5.resolve)(this.config.headers());
516
532
  try {
517
- const { value: response, responseHeaders } = await (0, import_provider_utils2.postJsonToApi)({
533
+ const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
518
534
  url: this.getUrl(),
519
- headers: (0, import_provider_utils2.combineHeaders)(
535
+ headers: (0, import_provider_utils5.combineHeaders)(
520
536
  resolvedHeaders,
521
537
  options.headers,
522
538
  this.getModelConfigHeaders(this.modelId, true),
523
- await (0, import_provider_utils2.resolve)(this.config.o11yHeaders)
539
+ await (0, import_provider_utils5.resolve)(this.config.o11yHeaders)
524
540
  ),
525
541
  body: args,
526
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(import_v45.z.any()),
527
- failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
542
+ successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(import_v45.z.any()),
543
+ failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
528
544
  errorSchema: import_v45.z.any(),
529
545
  errorToMessage: (data) => data
530
546
  }),
@@ -561,7 +577,7 @@ var GatewayLanguageModel = class {
561
577
  response: { headers: responseHeaders }
562
578
  };
563
579
  } catch (error) {
564
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
580
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
565
581
  }
566
582
  }
567
583
  isFilePart(part) {
@@ -595,7 +611,7 @@ var GatewayLanguageModel = class {
595
611
  }
596
612
  getModelConfigHeaders(modelId, streaming) {
597
613
  return {
598
- "ai-language-model-specification-version": "2",
614
+ "ai-language-model-specification-version": "3",
599
615
  "ai-language-model-id": modelId,
600
616
  "ai-language-model-streaming": String(streaming)
601
617
  };
@@ -603,13 +619,13 @@ var GatewayLanguageModel = class {
603
619
  };
604
620
 
605
621
  // src/gateway-embedding-model.ts
606
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
622
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
607
623
  var import_v46 = require("zod/v4");
608
624
  var GatewayEmbeddingModel = class {
609
625
  constructor(modelId, config) {
610
626
  this.modelId = modelId;
611
627
  this.config = config;
612
- this.specificationVersion = "v2";
628
+ this.specificationVersion = "v3";
613
629
  this.maxEmbeddingsPerCall = 2048;
614
630
  this.supportsParallelCalls = true;
615
631
  }
@@ -623,28 +639,28 @@ var GatewayEmbeddingModel = class {
623
639
  providerOptions
624
640
  }) {
625
641
  var _a8;
626
- const resolvedHeaders = await (0, import_provider_utils3.resolve)(this.config.headers());
642
+ const resolvedHeaders = await (0, import_provider_utils6.resolve)(this.config.headers());
627
643
  try {
628
644
  const {
629
645
  responseHeaders,
630
646
  value: responseBody,
631
647
  rawValue
632
- } = await (0, import_provider_utils3.postJsonToApi)({
648
+ } = await (0, import_provider_utils6.postJsonToApi)({
633
649
  url: this.getUrl(),
634
- headers: (0, import_provider_utils3.combineHeaders)(
650
+ headers: (0, import_provider_utils6.combineHeaders)(
635
651
  resolvedHeaders,
636
652
  headers != null ? headers : {},
637
653
  this.getModelConfigHeaders(),
638
- await (0, import_provider_utils3.resolve)(this.config.o11yHeaders)
654
+ await (0, import_provider_utils6.resolve)(this.config.o11yHeaders)
639
655
  ),
640
656
  body: {
641
- input: values.length === 1 ? values[0] : values,
657
+ values,
642
658
  ...providerOptions ? { providerOptions } : {}
643
659
  },
644
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
660
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
645
661
  gatewayEmbeddingResponseSchema
646
662
  ),
647
- failedResponseHandler: (0, import_provider_utils3.createJsonErrorResponseHandler)({
663
+ failedResponseHandler: (0, import_provider_utils6.createJsonErrorResponseHandler)({
648
664
  errorSchema: import_v46.z.any(),
649
665
  errorToMessage: (data) => data
650
666
  }),
@@ -655,10 +671,11 @@ var GatewayEmbeddingModel = class {
655
671
  embeddings: responseBody.embeddings,
656
672
  usage: (_a8 = responseBody.usage) != null ? _a8 : void 0,
657
673
  providerMetadata: responseBody.providerMetadata,
658
- response: { headers: responseHeaders, body: rawValue }
674
+ response: { headers: responseHeaders, body: rawValue },
675
+ warnings: []
659
676
  };
660
677
  } catch (error) {
661
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
678
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
662
679
  }
663
680
  }
664
681
  getUrl() {
@@ -666,17 +683,228 @@ var GatewayEmbeddingModel = class {
666
683
  }
667
684
  getModelConfigHeaders() {
668
685
  return {
669
- "ai-embedding-model-specification-version": "2",
686
+ "ai-embedding-model-specification-version": "3",
670
687
  "ai-model-id": this.modelId
671
688
  };
672
689
  }
673
690
  };
674
- var gatewayEmbeddingResponseSchema = import_v46.z.object({
675
- embeddings: import_v46.z.array(import_v46.z.array(import_v46.z.number())),
676
- usage: import_v46.z.object({ tokens: import_v46.z.number() }).nullish(),
677
- providerMetadata: import_v46.z.record(import_v46.z.string(), import_v46.z.record(import_v46.z.string(), import_v46.z.unknown())).optional()
691
+ var gatewayEmbeddingResponseSchema = (0, import_provider_utils6.lazySchema)(
692
+ () => (0, import_provider_utils6.zodSchema)(
693
+ import_v46.z.object({
694
+ embeddings: import_v46.z.array(import_v46.z.array(import_v46.z.number())),
695
+ usage: import_v46.z.object({ tokens: import_v46.z.number() }).nullish(),
696
+ providerMetadata: import_v46.z.record(import_v46.z.string(), import_v46.z.record(import_v46.z.string(), import_v46.z.unknown())).optional()
697
+ })
698
+ )
699
+ );
700
+
701
+ // src/gateway-image-model.ts
702
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
703
+ var import_v47 = require("zod/v4");
704
+ var GatewayImageModel = class {
705
+ constructor(modelId, config) {
706
+ this.modelId = modelId;
707
+ this.config = config;
708
+ this.specificationVersion = "v3";
709
+ // Set a very large number to prevent client-side splitting of requests
710
+ this.maxImagesPerCall = Number.MAX_SAFE_INTEGER;
711
+ }
712
+ get provider() {
713
+ return this.config.provider;
714
+ }
715
+ async doGenerate({
716
+ prompt,
717
+ n,
718
+ size,
719
+ aspectRatio,
720
+ seed,
721
+ files,
722
+ mask,
723
+ providerOptions,
724
+ headers,
725
+ abortSignal
726
+ }) {
727
+ var _a8;
728
+ const resolvedHeaders = await (0, import_provider_utils7.resolve)(this.config.headers());
729
+ try {
730
+ const {
731
+ responseHeaders,
732
+ value: responseBody,
733
+ rawValue
734
+ } = await (0, import_provider_utils7.postJsonToApi)({
735
+ url: this.getUrl(),
736
+ headers: (0, import_provider_utils7.combineHeaders)(
737
+ resolvedHeaders,
738
+ headers != null ? headers : {},
739
+ this.getModelConfigHeaders(),
740
+ await (0, import_provider_utils7.resolve)(this.config.o11yHeaders)
741
+ ),
742
+ body: {
743
+ prompt,
744
+ n,
745
+ ...size && { size },
746
+ ...aspectRatio && { aspectRatio },
747
+ ...seed && { seed },
748
+ ...providerOptions && { providerOptions },
749
+ ...files && {
750
+ files: files.map((file) => maybeEncodeImageFile(file))
751
+ },
752
+ ...mask && { mask: maybeEncodeImageFile(mask) }
753
+ },
754
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
755
+ gatewayImageResponseSchema
756
+ ),
757
+ failedResponseHandler: (0, import_provider_utils7.createJsonErrorResponseHandler)({
758
+ errorSchema: import_v47.z.any(),
759
+ errorToMessage: (data) => data
760
+ }),
761
+ ...abortSignal && { abortSignal },
762
+ fetch: this.config.fetch
763
+ });
764
+ return {
765
+ images: responseBody.images,
766
+ // Always base64 strings from server
767
+ warnings: (_a8 = responseBody.warnings) != null ? _a8 : [],
768
+ providerMetadata: responseBody.providerMetadata,
769
+ response: {
770
+ timestamp: /* @__PURE__ */ new Date(),
771
+ modelId: this.modelId,
772
+ headers: responseHeaders
773
+ }
774
+ };
775
+ } catch (error) {
776
+ throw asGatewayError(error, await parseAuthMethod(resolvedHeaders));
777
+ }
778
+ }
779
+ getUrl() {
780
+ return `${this.config.baseURL}/image-model`;
781
+ }
782
+ getModelConfigHeaders() {
783
+ return {
784
+ "ai-image-model-specification-version": "3",
785
+ "ai-model-id": this.modelId
786
+ };
787
+ }
788
+ };
789
+ function maybeEncodeImageFile(file) {
790
+ if (file.type === "file" && file.data instanceof Uint8Array) {
791
+ return {
792
+ ...file,
793
+ data: (0, import_provider_utils7.convertUint8ArrayToBase64)(file.data)
794
+ };
795
+ }
796
+ return file;
797
+ }
798
+ var providerMetadataEntrySchema = import_v47.z.object({
799
+ images: import_v47.z.array(import_v47.z.unknown()).optional()
800
+ }).catchall(import_v47.z.unknown());
801
+ var gatewayImageResponseSchema = import_v47.z.object({
802
+ images: import_v47.z.array(import_v47.z.string()),
803
+ // Always base64 strings over the wire
804
+ warnings: import_v47.z.array(
805
+ import_v47.z.object({
806
+ type: import_v47.z.literal("other"),
807
+ message: import_v47.z.string()
808
+ })
809
+ ).optional(),
810
+ providerMetadata: import_v47.z.record(import_v47.z.string(), providerMetadataEntrySchema).optional()
678
811
  });
679
812
 
813
+ // src/tool/perplexity-search.ts
814
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
815
+ var import_zod = require("zod");
816
+ var perplexitySearchInputSchema = (0, import_provider_utils8.lazySchema)(
817
+ () => (0, import_provider_utils8.zodSchema)(
818
+ import_zod.z.object({
819
+ query: import_zod.z.union([import_zod.z.string(), import_zod.z.array(import_zod.z.string())]).describe(
820
+ "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
821
+ ),
822
+ max_results: import_zod.z.number().optional().describe(
823
+ "Maximum number of search results to return (1-20, default: 10)"
824
+ ),
825
+ max_tokens_per_page: import_zod.z.number().optional().describe(
826
+ "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
827
+ ),
828
+ max_tokens: import_zod.z.number().optional().describe(
829
+ "Maximum total tokens across all search results (default: 25000, max: 1000000)"
830
+ ),
831
+ country: import_zod.z.string().optional().describe(
832
+ "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
833
+ ),
834
+ search_domain_filter: import_zod.z.array(import_zod.z.string()).optional().describe(
835
+ "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
836
+ ),
837
+ search_language_filter: import_zod.z.array(import_zod.z.string()).optional().describe(
838
+ "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
839
+ ),
840
+ search_after_date: import_zod.z.string().optional().describe(
841
+ "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
842
+ ),
843
+ search_before_date: import_zod.z.string().optional().describe(
844
+ "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
845
+ ),
846
+ last_updated_after_filter: import_zod.z.string().optional().describe(
847
+ "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
848
+ ),
849
+ last_updated_before_filter: import_zod.z.string().optional().describe(
850
+ "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
851
+ ),
852
+ search_recency_filter: import_zod.z.enum(["day", "week", "month", "year"]).optional().describe(
853
+ "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
854
+ )
855
+ })
856
+ )
857
+ );
858
+ var perplexitySearchOutputSchema = (0, import_provider_utils8.lazySchema)(
859
+ () => (0, import_provider_utils8.zodSchema)(
860
+ import_zod.z.union([
861
+ // Success response
862
+ import_zod.z.object({
863
+ results: import_zod.z.array(
864
+ import_zod.z.object({
865
+ title: import_zod.z.string(),
866
+ url: import_zod.z.string(),
867
+ snippet: import_zod.z.string(),
868
+ date: import_zod.z.string().optional(),
869
+ lastUpdated: import_zod.z.string().optional()
870
+ })
871
+ ),
872
+ id: import_zod.z.string()
873
+ }),
874
+ // Error response
875
+ import_zod.z.object({
876
+ error: import_zod.z.enum([
877
+ "api_error",
878
+ "rate_limit",
879
+ "timeout",
880
+ "invalid_input",
881
+ "unknown"
882
+ ]),
883
+ statusCode: import_zod.z.number().optional(),
884
+ message: import_zod.z.string()
885
+ })
886
+ ])
887
+ )
888
+ );
889
+ var perplexitySearchToolFactory = (0, import_provider_utils8.createProviderToolFactoryWithOutputSchema)({
890
+ id: "gateway.perplexity_search",
891
+ inputSchema: perplexitySearchInputSchema,
892
+ outputSchema: perplexitySearchOutputSchema
893
+ });
894
+ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
895
+
896
+ // src/gateway-tools.ts
897
+ var gatewayTools = {
898
+ /**
899
+ * Search the web using Perplexity's Search API for real-time information,
900
+ * news, research papers, and articles.
901
+ *
902
+ * Provides ranked search results with advanced filtering options including
903
+ * domain, language, date range, and recency filters.
904
+ */
905
+ perplexitySearch
906
+ };
907
+
680
908
  // src/vercel-environment.ts
681
909
  var import_oidc = require("@vercel/oidc");
682
910
  var import_oidc2 = require("@vercel/oidc");
@@ -686,10 +914,10 @@ async function getVercelRequestId() {
686
914
  }
687
915
 
688
916
  // src/gateway-provider.ts
689
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
917
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
690
918
 
691
919
  // src/version.ts
692
- var VERSION = true ? "0.0.0-02dba89b-20251009204516" : "0.0.0-test";
920
+ var VERSION = true ? "0.0.0-1c33ba03-20260114162300" : "0.0.0-test";
693
921
 
694
922
  // src/gateway-provider.ts
695
923
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -699,11 +927,11 @@ function createGatewayProvider(options = {}) {
699
927
  let metadataCache = null;
700
928
  const cacheRefreshMillis = (_a8 = options.metadataCacheRefreshMillis) != null ? _a8 : 1e3 * 60 * 5;
701
929
  let lastFetchTime = 0;
702
- const baseURL = (_b8 = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
930
+ const baseURL = (_b8 = (0, import_provider_utils9.withoutTrailingSlash)(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v3/ai";
703
931
  const getHeaders = async () => {
704
- const auth = await getGatewayAuthToken(options);
705
- if (auth) {
706
- return (0, import_provider_utils5.withUserAgentSuffix)(
932
+ try {
933
+ const auth = await getGatewayAuthToken(options);
934
+ return (0, import_provider_utils10.withUserAgentSuffix)(
707
935
  {
708
936
  Authorization: `Bearer ${auth.token}`,
709
937
  "ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
@@ -712,23 +940,25 @@ function createGatewayProvider(options = {}) {
712
940
  },
713
941
  `ai-sdk/gateway/${VERSION}`
714
942
  );
943
+ } catch (error) {
944
+ throw GatewayAuthenticationError.createContextualError({
945
+ apiKeyProvided: false,
946
+ oidcTokenProvided: false,
947
+ statusCode: 401,
948
+ cause: error
949
+ });
715
950
  }
716
- throw GatewayAuthenticationError.createContextualError({
717
- apiKeyProvided: false,
718
- oidcTokenProvided: false,
719
- statusCode: 401
720
- });
721
951
  };
722
952
  const createO11yHeaders = () => {
723
- const deploymentId = (0, import_provider_utils4.loadOptionalSetting)({
953
+ const deploymentId = (0, import_provider_utils9.loadOptionalSetting)({
724
954
  settingValue: void 0,
725
955
  environmentVariableName: "VERCEL_DEPLOYMENT_ID"
726
956
  });
727
- const environment = (0, import_provider_utils4.loadOptionalSetting)({
957
+ const environment = (0, import_provider_utils9.loadOptionalSetting)({
728
958
  settingValue: void 0,
729
959
  environmentVariableName: "VERCEL_ENV"
730
960
  });
731
- const region = (0, import_provider_utils4.loadOptionalSetting)({
961
+ const region = (0, import_provider_utils9.loadOptionalSetting)({
732
962
  settingValue: void 0,
733
963
  environmentVariableName: "VERCEL_REGION"
734
964
  });
@@ -764,7 +994,10 @@ function createGatewayProvider(options = {}) {
764
994
  metadataCache = metadata;
765
995
  return metadata;
766
996
  }).catch(async (error) => {
767
- throw asGatewayError(error, parseAuthMethod(await getHeaders()));
997
+ throw await asGatewayError(
998
+ error,
999
+ await parseAuthMethod(await getHeaders())
1000
+ );
768
1001
  });
769
1002
  }
770
1003
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
@@ -775,7 +1008,10 @@ function createGatewayProvider(options = {}) {
775
1008
  headers: getHeaders,
776
1009
  fetch: options.fetch
777
1010
  }).getCredits().catch(async (error) => {
778
- throw asGatewayError(error, parseAuthMethod(await getHeaders()));
1011
+ throw await asGatewayError(
1012
+ error,
1013
+ await parseAuthMethod(await getHeaders())
1014
+ );
779
1015
  });
780
1016
  };
781
1017
  const provider = function(modelId) {
@@ -786,13 +1022,20 @@ function createGatewayProvider(options = {}) {
786
1022
  }
787
1023
  return createLanguageModel(modelId);
788
1024
  };
1025
+ provider.specificationVersion = "v3";
789
1026
  provider.getAvailableModels = getAvailableModels;
790
1027
  provider.getCredits = getCredits;
791
1028
  provider.imageModel = (modelId) => {
792
- throw new import_provider2.NoSuchModelError({ modelId, modelType: "imageModel" });
1029
+ return new GatewayImageModel(modelId, {
1030
+ provider: "gateway",
1031
+ baseURL,
1032
+ headers: getHeaders,
1033
+ fetch: options.fetch,
1034
+ o11yHeaders: createO11yHeaders()
1035
+ });
793
1036
  };
794
1037
  provider.languageModel = createLanguageModel;
795
- provider.textEmbeddingModel = (modelId) => {
1038
+ const createEmbeddingModel = (modelId) => {
796
1039
  return new GatewayEmbeddingModel(modelId, {
797
1040
  provider: "gateway",
798
1041
  baseURL,
@@ -801,11 +1044,14 @@ function createGatewayProvider(options = {}) {
801
1044
  o11yHeaders: createO11yHeaders()
802
1045
  });
803
1046
  };
1047
+ provider.embeddingModel = createEmbeddingModel;
1048
+ provider.textEmbeddingModel = createEmbeddingModel;
1049
+ provider.tools = gatewayTools;
804
1050
  return provider;
805
1051
  }
806
1052
  var gateway = createGatewayProvider();
807
1053
  async function getGatewayAuthToken(options) {
808
- const apiKey = (0, import_provider_utils4.loadOptionalSetting)({
1054
+ const apiKey = (0, import_provider_utils9.loadOptionalSetting)({
809
1055
  settingValue: options.apiKey,
810
1056
  environmentVariableName: "AI_GATEWAY_API_KEY"
811
1057
  });
@@ -815,15 +1061,11 @@ async function getGatewayAuthToken(options) {
815
1061
  authMethod: "api-key"
816
1062
  };
817
1063
  }
818
- try {
819
- const oidcToken = await (0, import_oidc2.getVercelOidcToken)();
820
- return {
821
- token: oidcToken,
822
- authMethod: "oidc"
823
- };
824
- } catch (e) {
825
- return null;
826
- }
1064
+ const oidcToken = await (0, import_oidc2.getVercelOidcToken)();
1065
+ return {
1066
+ token: oidcToken,
1067
+ authMethod: "oidc"
1068
+ };
827
1069
  }
828
1070
  // Annotate the CommonJS export names for ESM import in node:
829
1071
  0 && (module.exports = {