@ai-sdk/gateway 2.0.0-beta.23 → 2.0.0-beta.24

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/gateway
2
2
 
3
+ ## 2.0.0-beta.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 0e29b8b: chore(provider/gateway): lazy schema loading
8
+
3
9
  ## 2.0.0-beta.23
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
- import { LanguageModelV3, ProviderV3, EmbeddingModelV3 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import * as z from 'zod/v4';
4
- import { ZodError } from 'zod/v4';
1
+ import { LanguageModelV3, ProviderV3, EmbeddingModelV3, TypeValidationError } from '@ai-sdk/provider';
2
+ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
+ import { FetchFunction, InferValidator } from '@ai-sdk/provider-utils';
5
4
 
6
5
  type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | 'alibaba/qwen3-coder' | 'alibaba/qwen3-coder-plus' | 'alibaba/qwen3-max' | 'alibaba/qwen3-max-preview' | 'alibaba/qwen3-next-80b-a3b-instruct' | 'alibaba/qwen3-next-80b-a3b-thinking' | 'alibaba/qwen3-vl-instruct' | 'alibaba/qwen3-vl-thinking' | 'amazon/nova-lite' | 'amazon/nova-micro' | 'amazon/nova-pro' | 'anthropic/claude-3-haiku' | 'anthropic/claude-3-opus' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-3.5-sonnet' | 'anthropic/claude-3.7-sonnet' | 'anthropic/claude-opus-4' | 'anthropic/claude-opus-4.1' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-sonnet-4.5' | 'cohere/command-a' | 'cohere/command-r' | 'cohere/command-r-plus' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-v3' | 'deepseek/deepseek-v3.1' | 'deepseek/deepseek-v3.1-base' | 'deepseek/deepseek-v3.1-terminus' | 'deepseek/deepseek-v3.2-exp' | 'deepseek/deepseek-v3.2-exp-thinking' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-flash-image-preview' | 'google/gemini-2.5-flash-preview-09-2025' | 'google/gemini-2.5-flash-lite' | 'google/gemini-2.5-flash-lite-preview-09-2025' | 'google/gemini-2.5-pro' | 'google/gemma-2-9b' | 'inception/mercury-coder-small' | 'meituan/longcat-flash-chat' | 'meituan/longcat-flash-thinking' | 'meta/llama-3-70b' | 'meta/llama-3-8b' | 'meta/llama-3.1-70b' | 'meta/llama-3.1-8b' | 'meta/llama-3.2-11b' | 'meta/llama-3.2-1b' | 'meta/llama-3.2-3b' | 'meta/llama-3.2-90b' | 'meta/llama-3.3-70b' | 'meta/llama-4-maverick' | 'meta/llama-4-scout' | 'mistral/codestral' | 'mistral/devstral-small' | 'mistral/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large' | 'mistral/mistral-medium' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2-0905' | 'moonshotai/kimi-k2-turbo' | 'morph/morph-v3-fast' | 'morph/morph-v3-large' | 'openai/gpt-3.5-turbo' | 'openai/gpt-3.5-turbo-instruct' | 'openai/gpt-4-turbo' | 'openai/gpt-4.1' | 'openai/gpt-4.1-mini' | 'openai/gpt-4.1-nano' | 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/gpt-5' | 'openai/gpt-5-codex' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | 'openai/gpt-5-pro' | 'openai/gpt-oss-120b' | 'openai/gpt-oss-20b' | 'openai/o1' | 'openai/o3' | 'openai/o3-mini' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning' | 'perplexity/sonar-reasoning-pro' | 'stealth/sonoma-dusk-alpha' | 'stealth/sonoma-sky-alpha' | 'vercel/v0-1.0-md' | 'vercel/v0-1.5-md' | 'xai/grok-2' | 'xai/grok-2-vision' | 'xai/grok-3' | 'xai/grok-3-fast' | 'xai/grok-3-mini' | 'xai/grok-3-mini-fast' | 'xai/grok-4' | 'xai/grok-code-fast-1' | 'xai/grok-4-fast-non-reasoning' | 'xai/grok-4-fast-reasoning' | 'zai/glm-4.5' | 'zai/glm-4.5-air' | 'zai/glm-4.5v' | 'zai/glm-4.6' | (string & {});
7
6
 
@@ -113,11 +112,11 @@ Create a remote provider instance.
113
112
  declare function createGatewayProvider(options?: GatewayProviderSettings): GatewayProvider;
114
113
  declare const gateway: GatewayProvider;
115
114
 
116
- declare const gatewayProviderOptions: z.ZodObject<{
117
- only: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
- order: z.ZodOptional<z.ZodArray<z.ZodString>>;
119
- }, z.core.$strip>;
120
- type GatewayProviderOptions = z.infer<typeof gatewayProviderOptions>;
115
+ declare const gatewayProviderOptions: _ai_sdk_provider_utils.LazyValidator<{
116
+ only?: string[] | undefined;
117
+ order?: string[] | undefined;
118
+ }>;
119
+ type GatewayProviderOptions = InferValidator<typeof gatewayProviderOptions>;
121
120
 
122
121
  declare const symbol$6: unique symbol;
123
122
  declare abstract class GatewayError extends Error {
@@ -140,15 +139,15 @@ declare abstract class GatewayError extends Error {
140
139
  static hasMarker(error: unknown): error is GatewayError;
141
140
  }
142
141
 
143
- declare const gatewayErrorResponseSchema: z.ZodObject<{
144
- error: z.ZodObject<{
145
- message: z.ZodString;
146
- type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
147
- param: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
148
- code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
149
- }, z.core.$strip>;
150
- }, z.core.$strip>;
151
- type GatewayErrorResponse = z.infer<typeof gatewayErrorResponseSchema>;
142
+ declare const gatewayErrorResponseSchema: _ai_sdk_provider_utils.LazyValidator<{
143
+ error: {
144
+ message: string;
145
+ type?: string | null | undefined;
146
+ param?: unknown;
147
+ code?: string | number | null | undefined;
148
+ };
149
+ }>;
150
+ type GatewayErrorResponse = InferValidator<typeof gatewayErrorResponseSchema>;
152
151
 
153
152
  declare const symbol$5: unique symbol;
154
153
  /**
@@ -251,12 +250,12 @@ declare class GatewayResponseError extends GatewayError {
251
250
  readonly name = "GatewayResponseError";
252
251
  readonly type = "response_error";
253
252
  readonly response?: unknown;
254
- readonly validationError?: ZodError;
253
+ readonly validationError?: TypeValidationError;
255
254
  constructor({ message, statusCode, response, validationError, cause, }?: {
256
255
  message?: string;
257
256
  statusCode?: number;
258
257
  response?: unknown;
259
- validationError?: ZodError;
258
+ validationError?: TypeValidationError;
260
259
  cause?: unknown;
261
260
  });
262
261
  static isInstance(error: unknown): error is GatewayResponseError;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { LanguageModelV3, ProviderV3, EmbeddingModelV3 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import * as z from 'zod/v4';
4
- import { ZodError } from 'zod/v4';
1
+ import { LanguageModelV3, ProviderV3, EmbeddingModelV3, TypeValidationError } from '@ai-sdk/provider';
2
+ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
+ import { FetchFunction, InferValidator } from '@ai-sdk/provider-utils';
5
4
 
6
5
  type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | 'alibaba/qwen3-coder' | 'alibaba/qwen3-coder-plus' | 'alibaba/qwen3-max' | 'alibaba/qwen3-max-preview' | 'alibaba/qwen3-next-80b-a3b-instruct' | 'alibaba/qwen3-next-80b-a3b-thinking' | 'alibaba/qwen3-vl-instruct' | 'alibaba/qwen3-vl-thinking' | 'amazon/nova-lite' | 'amazon/nova-micro' | 'amazon/nova-pro' | 'anthropic/claude-3-haiku' | 'anthropic/claude-3-opus' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-3.5-sonnet' | 'anthropic/claude-3.7-sonnet' | 'anthropic/claude-opus-4' | 'anthropic/claude-opus-4.1' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-sonnet-4.5' | 'cohere/command-a' | 'cohere/command-r' | 'cohere/command-r-plus' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-v3' | 'deepseek/deepseek-v3.1' | 'deepseek/deepseek-v3.1-base' | 'deepseek/deepseek-v3.1-terminus' | 'deepseek/deepseek-v3.2-exp' | 'deepseek/deepseek-v3.2-exp-thinking' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-flash-image-preview' | 'google/gemini-2.5-flash-preview-09-2025' | 'google/gemini-2.5-flash-lite' | 'google/gemini-2.5-flash-lite-preview-09-2025' | 'google/gemini-2.5-pro' | 'google/gemma-2-9b' | 'inception/mercury-coder-small' | 'meituan/longcat-flash-chat' | 'meituan/longcat-flash-thinking' | 'meta/llama-3-70b' | 'meta/llama-3-8b' | 'meta/llama-3.1-70b' | 'meta/llama-3.1-8b' | 'meta/llama-3.2-11b' | 'meta/llama-3.2-1b' | 'meta/llama-3.2-3b' | 'meta/llama-3.2-90b' | 'meta/llama-3.3-70b' | 'meta/llama-4-maverick' | 'meta/llama-4-scout' | 'mistral/codestral' | 'mistral/devstral-small' | 'mistral/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large' | 'mistral/mistral-medium' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2-0905' | 'moonshotai/kimi-k2-turbo' | 'morph/morph-v3-fast' | 'morph/morph-v3-large' | 'openai/gpt-3.5-turbo' | 'openai/gpt-3.5-turbo-instruct' | 'openai/gpt-4-turbo' | 'openai/gpt-4.1' | 'openai/gpt-4.1-mini' | 'openai/gpt-4.1-nano' | 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/gpt-5' | 'openai/gpt-5-codex' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | 'openai/gpt-5-pro' | 'openai/gpt-oss-120b' | 'openai/gpt-oss-20b' | 'openai/o1' | 'openai/o3' | 'openai/o3-mini' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning' | 'perplexity/sonar-reasoning-pro' | 'stealth/sonoma-dusk-alpha' | 'stealth/sonoma-sky-alpha' | 'vercel/v0-1.0-md' | 'vercel/v0-1.5-md' | 'xai/grok-2' | 'xai/grok-2-vision' | 'xai/grok-3' | 'xai/grok-3-fast' | 'xai/grok-3-mini' | 'xai/grok-3-mini-fast' | 'xai/grok-4' | 'xai/grok-code-fast-1' | 'xai/grok-4-fast-non-reasoning' | 'xai/grok-4-fast-reasoning' | 'zai/glm-4.5' | 'zai/glm-4.5-air' | 'zai/glm-4.5v' | 'zai/glm-4.6' | (string & {});
7
6
 
@@ -113,11 +112,11 @@ Create a remote provider instance.
113
112
  declare function createGatewayProvider(options?: GatewayProviderSettings): GatewayProvider;
114
113
  declare const gateway: GatewayProvider;
115
114
 
116
- declare const gatewayProviderOptions: z.ZodObject<{
117
- only: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
- order: z.ZodOptional<z.ZodArray<z.ZodString>>;
119
- }, z.core.$strip>;
120
- type GatewayProviderOptions = z.infer<typeof gatewayProviderOptions>;
115
+ declare const gatewayProviderOptions: _ai_sdk_provider_utils.LazyValidator<{
116
+ only?: string[] | undefined;
117
+ order?: string[] | undefined;
118
+ }>;
119
+ type GatewayProviderOptions = InferValidator<typeof gatewayProviderOptions>;
121
120
 
122
121
  declare const symbol$6: unique symbol;
123
122
  declare abstract class GatewayError extends Error {
@@ -140,15 +139,15 @@ declare abstract class GatewayError extends Error {
140
139
  static hasMarker(error: unknown): error is GatewayError;
141
140
  }
142
141
 
143
- declare const gatewayErrorResponseSchema: z.ZodObject<{
144
- error: z.ZodObject<{
145
- message: z.ZodString;
146
- type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
147
- param: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
148
- code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
149
- }, z.core.$strip>;
150
- }, z.core.$strip>;
151
- type GatewayErrorResponse = z.infer<typeof gatewayErrorResponseSchema>;
142
+ declare const gatewayErrorResponseSchema: _ai_sdk_provider_utils.LazyValidator<{
143
+ error: {
144
+ message: string;
145
+ type?: string | null | undefined;
146
+ param?: unknown;
147
+ code?: string | number | null | undefined;
148
+ };
149
+ }>;
150
+ type GatewayErrorResponse = InferValidator<typeof gatewayErrorResponseSchema>;
152
151
 
153
152
  declare const symbol$5: unique symbol;
154
153
  /**
@@ -251,12 +250,12 @@ declare class GatewayResponseError extends GatewayError {
251
250
  readonly name = "GatewayResponseError";
252
251
  readonly type = "response_error";
253
252
  readonly response?: unknown;
254
- readonly validationError?: ZodError;
253
+ readonly validationError?: TypeValidationError;
255
254
  constructor({ message, statusCode, response, validationError, cause, }?: {
256
255
  message?: string;
257
256
  statusCode?: number;
258
257
  response?: unknown;
259
- validationError?: ZodError;
258
+ validationError?: TypeValidationError;
260
259
  cause?: unknown;
261
260
  });
262
261
  static isInstance(error: unknown): error is GatewayResponseError;
package/dist/index.js CHANGED
@@ -45,7 +45,7 @@ module.exports = __toCommonJS(src_exports);
45
45
 
46
46
  // src/gateway-provider.ts
47
47
  var import_provider2 = require("@ai-sdk/provider");
48
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
48
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
49
49
 
50
50
  // src/errors/as-gateway-error.ts
51
51
  var import_provider = require("@ai-sdk/provider");
@@ -197,12 +197,17 @@ var GatewayRateLimitError = class extends (_b4 = GatewayError, _a4 = symbol4, _b
197
197
 
198
198
  // src/errors/gateway-model-not-found-error.ts
199
199
  var z = __toESM(require("zod/v4"));
200
+ var import_provider_utils = require("@ai-sdk/provider-utils");
200
201
  var name4 = "GatewayModelNotFoundError";
201
202
  var marker5 = `vercel.ai.gateway.error.${name4}`;
202
203
  var symbol5 = Symbol.for(marker5);
203
- var modelNotFoundParamSchema = z.object({
204
- modelId: z.string()
205
- });
204
+ var modelNotFoundParamSchema = (0, import_provider_utils.lazyValidator)(
205
+ () => (0, import_provider_utils.zodSchema)(
206
+ z.object({
207
+ modelId: z.string()
208
+ })
209
+ )
210
+ );
206
211
  var _a5, _b5;
207
212
  var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a5 = symbol5, _b5) {
208
213
  constructor({
@@ -272,14 +277,18 @@ var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7
272
277
  };
273
278
 
274
279
  // src/errors/create-gateway-error.ts
275
- function createGatewayErrorFromResponse({
280
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
281
+ async function createGatewayErrorFromResponse({
276
282
  response,
277
283
  statusCode,
278
284
  defaultMessage = "Gateway request failed",
279
285
  cause,
280
286
  authMethod
281
287
  }) {
282
- const parseResult = gatewayErrorResponseSchema.safeParse(response);
288
+ const parseResult = await (0, import_provider_utils2.safeValidateTypes)({
289
+ value: response,
290
+ schema: gatewayErrorResponseSchema
291
+ });
283
292
  if (!parseResult.success) {
284
293
  return new GatewayResponseError({
285
294
  message: `Invalid error response format: ${defaultMessage}`,
@@ -289,7 +298,7 @@ function createGatewayErrorFromResponse({
289
298
  cause
290
299
  });
291
300
  }
292
- const validatedResponse = parseResult.data;
301
+ const validatedResponse = parseResult.value;
293
302
  const errorType = validatedResponse.error.type;
294
303
  const message = validatedResponse.error.message;
295
304
  switch (errorType) {
@@ -305,13 +314,14 @@ function createGatewayErrorFromResponse({
305
314
  case "rate_limit_exceeded":
306
315
  return new GatewayRateLimitError({ message, statusCode, cause });
307
316
  case "model_not_found": {
308
- const modelResult = modelNotFoundParamSchema.safeParse(
309
- validatedResponse.error.param
310
- );
317
+ const modelResult = await (0, import_provider_utils2.safeValidateTypes)({
318
+ value: validatedResponse.error.param,
319
+ schema: modelNotFoundParamSchema
320
+ });
311
321
  return new GatewayModelNotFoundError({
312
322
  message,
313
323
  statusCode,
314
- modelId: modelResult.success ? modelResult.data.modelId : void 0,
324
+ modelId: modelResult.success ? modelResult.value.modelId : void 0,
315
325
  cause
316
326
  });
317
327
  }
@@ -321,14 +331,18 @@ function createGatewayErrorFromResponse({
321
331
  return new GatewayInternalServerError({ message, statusCode, cause });
322
332
  }
323
333
  }
324
- var gatewayErrorResponseSchema = z2.object({
325
- error: z2.object({
326
- message: z2.string(),
327
- type: z2.string().nullish(),
328
- param: z2.unknown().nullish(),
329
- code: z2.union([z2.string(), z2.number()]).nullish()
330
- })
331
- });
334
+ var gatewayErrorResponseSchema = (0, import_provider_utils2.lazyValidator)(
335
+ () => (0, import_provider_utils2.zodSchema)(
336
+ z2.object({
337
+ error: z2.object({
338
+ message: z2.string(),
339
+ type: z2.string().nullish(),
340
+ param: z2.unknown().nullish(),
341
+ code: z2.union([z2.string(), z2.number()]).nullish()
342
+ })
343
+ })
344
+ )
345
+ );
332
346
 
333
347
  // src/errors/as-gateway-error.ts
334
348
  function asGatewayError(error, authMethod) {
@@ -370,21 +384,22 @@ function extractApiCallResponse(error) {
370
384
  }
371
385
 
372
386
  // src/errors/parse-auth-method.ts
387
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
373
388
  var z3 = __toESM(require("zod/v4"));
374
389
  var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
375
- function parseAuthMethod(headers) {
376
- const result = gatewayAuthMethodSchema.safeParse(
377
- headers[GATEWAY_AUTH_METHOD_HEADER]
378
- );
379
- return result.success ? result.data : void 0;
390
+ async function parseAuthMethod(headers) {
391
+ const result = await (0, import_provider_utils3.safeValidateTypes)({
392
+ value: headers[GATEWAY_AUTH_METHOD_HEADER],
393
+ schema: gatewayAuthMethodSchema
394
+ });
395
+ return result.success ? result.value : void 0;
380
396
  }
381
- var gatewayAuthMethodSchema = z3.union([
382
- z3.literal("api-key"),
383
- z3.literal("oidc")
384
- ]);
397
+ var gatewayAuthMethodSchema = (0, import_provider_utils3.lazyValidator)(
398
+ () => (0, import_provider_utils3.zodSchema)(z3.union([z3.literal("api-key"), z3.literal("oidc")]))
399
+ );
385
400
 
386
401
  // src/gateway-fetch-metadata.ts
387
- var import_provider_utils = require("@ai-sdk/provider-utils");
402
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
388
403
  var z4 = __toESM(require("zod/v4"));
389
404
  var GatewayFetchMetadata = class {
390
405
  constructor(config) {
@@ -392,13 +407,13 @@ var GatewayFetchMetadata = class {
392
407
  }
393
408
  async getAvailableModels() {
394
409
  try {
395
- const { value } = await (0, import_provider_utils.getFromApi)({
410
+ const { value } = await (0, import_provider_utils4.getFromApi)({
396
411
  url: `${this.config.baseURL}/config`,
397
- headers: await (0, import_provider_utils.resolve)(this.config.headers()),
398
- successfulResponseHandler: (0, import_provider_utils.createJsonResponseHandler)(
399
- gatewayFetchMetadataSchema
412
+ headers: await (0, import_provider_utils4.resolve)(this.config.headers()),
413
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
414
+ gatewayAvailableModelsResponseSchema
400
415
  ),
401
- failedResponseHandler: (0, import_provider_utils.createJsonErrorResponseHandler)({
416
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
402
417
  errorSchema: z4.any(),
403
418
  errorToMessage: (data) => data
404
419
  }),
@@ -406,17 +421,19 @@ var GatewayFetchMetadata = class {
406
421
  });
407
422
  return value;
408
423
  } catch (error) {
409
- throw asGatewayError(error);
424
+ throw await asGatewayError(error);
410
425
  }
411
426
  }
412
427
  async getCredits() {
413
428
  try {
414
429
  const baseUrl = new URL(this.config.baseURL);
415
- const { value } = await (0, import_provider_utils.getFromApi)({
430
+ const { value } = await (0, import_provider_utils4.getFromApi)({
416
431
  url: `${baseUrl.origin}/v1/credits`,
417
- headers: await (0, import_provider_utils.resolve)(this.config.headers()),
418
- successfulResponseHandler: (0, import_provider_utils.createJsonResponseHandler)(gatewayCreditsSchema),
419
- failedResponseHandler: (0, import_provider_utils.createJsonErrorResponseHandler)({
432
+ headers: await (0, import_provider_utils4.resolve)(this.config.headers()),
433
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
434
+ gatewayCreditsResponseSchema
435
+ ),
436
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
420
437
  errorSchema: z4.any(),
421
438
  errorToMessage: (data) => data
422
439
  }),
@@ -424,47 +441,56 @@ var GatewayFetchMetadata = class {
424
441
  });
425
442
  return value;
426
443
  } catch (error) {
427
- throw asGatewayError(error);
444
+ throw await asGatewayError(error);
428
445
  }
429
446
  }
430
447
  };
431
- var gatewayLanguageModelSpecificationSchema = z4.object({
432
- specificationVersion: z4.literal("v3"),
433
- provider: z4.string(),
434
- modelId: z4.string()
435
- });
436
- var gatewayLanguageModelPricingSchema = z4.object({
437
- input: z4.string(),
438
- output: z4.string(),
439
- input_cache_read: z4.string().nullish(),
440
- input_cache_write: z4.string().nullish()
441
- }).transform(({ input, output, input_cache_read, input_cache_write }) => ({
442
- input,
443
- output,
444
- ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
445
- ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
446
- }));
447
- var gatewayLanguageModelEntrySchema = z4.object({
448
- id: z4.string(),
449
- name: z4.string(),
450
- description: z4.string().nullish(),
451
- pricing: gatewayLanguageModelPricingSchema.nullish(),
452
- specification: gatewayLanguageModelSpecificationSchema,
453
- modelType: z4.enum(["language", "embedding", "image"]).nullish()
454
- });
455
- var gatewayFetchMetadataSchema = z4.object({
456
- models: z4.array(gatewayLanguageModelEntrySchema)
457
- });
458
- var gatewayCreditsSchema = z4.object({
459
- balance: z4.string(),
460
- total_used: z4.string()
461
- }).transform(({ balance, total_used }) => ({
462
- balance,
463
- totalUsed: total_used
464
- }));
448
+ var gatewayAvailableModelsResponseSchema = (0, import_provider_utils4.lazyValidator)(
449
+ () => (0, import_provider_utils4.zodSchema)(
450
+ z4.object({
451
+ models: z4.array(
452
+ z4.object({
453
+ id: z4.string(),
454
+ name: z4.string(),
455
+ description: z4.string().nullish(),
456
+ pricing: z4.object({
457
+ input: z4.string(),
458
+ output: z4.string(),
459
+ input_cache_read: z4.string().nullish(),
460
+ input_cache_write: z4.string().nullish()
461
+ }).transform(
462
+ ({ input, output, input_cache_read, input_cache_write }) => ({
463
+ input,
464
+ output,
465
+ ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
466
+ ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
467
+ })
468
+ ).nullish(),
469
+ specification: z4.object({
470
+ specificationVersion: z4.literal("v3"),
471
+ provider: z4.string(),
472
+ modelId: z4.string()
473
+ }),
474
+ modelType: z4.enum(["language", "embedding", "image"]).nullish()
475
+ })
476
+ )
477
+ })
478
+ )
479
+ );
480
+ var gatewayCreditsResponseSchema = (0, import_provider_utils4.lazyValidator)(
481
+ () => (0, import_provider_utils4.zodSchema)(
482
+ z4.object({
483
+ balance: z4.string(),
484
+ total_used: z4.string()
485
+ }).transform(({ balance, total_used }) => ({
486
+ balance,
487
+ totalUsed: total_used
488
+ }))
489
+ )
490
+ );
465
491
 
466
492
  // src/gateway-language-model.ts
467
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
493
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
468
494
  var z5 = __toESM(require("zod/v4"));
469
495
  var GatewayLanguageModel = class {
470
496
  constructor(modelId, config) {
@@ -486,23 +512,23 @@ var GatewayLanguageModel = class {
486
512
  async doGenerate(options) {
487
513
  const { args, warnings } = await this.getArgs(options);
488
514
  const { abortSignal } = options;
489
- const resolvedHeaders = await (0, import_provider_utils2.resolve)(this.config.headers());
515
+ const resolvedHeaders = await (0, import_provider_utils5.resolve)(this.config.headers());
490
516
  try {
491
517
  const {
492
518
  responseHeaders,
493
519
  value: responseBody,
494
520
  rawValue: rawResponse
495
- } = await (0, import_provider_utils2.postJsonToApi)({
521
+ } = await (0, import_provider_utils5.postJsonToApi)({
496
522
  url: this.getUrl(),
497
- headers: (0, import_provider_utils2.combineHeaders)(
523
+ headers: (0, import_provider_utils5.combineHeaders)(
498
524
  resolvedHeaders,
499
525
  options.headers,
500
526
  this.getModelConfigHeaders(this.modelId, false),
501
- await (0, import_provider_utils2.resolve)(this.config.o11yHeaders)
527
+ await (0, import_provider_utils5.resolve)(this.config.o11yHeaders)
502
528
  ),
503
529
  body: args,
504
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(z5.any()),
505
- failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
530
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(z5.any()),
531
+ failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
506
532
  errorSchema: z5.any(),
507
533
  errorToMessage: (data) => data
508
534
  }),
@@ -516,25 +542,25 @@ var GatewayLanguageModel = class {
516
542
  warnings
517
543
  };
518
544
  } catch (error) {
519
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
545
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
520
546
  }
521
547
  }
522
548
  async doStream(options) {
523
549
  const { args, warnings } = await this.getArgs(options);
524
550
  const { abortSignal } = options;
525
- const resolvedHeaders = await (0, import_provider_utils2.resolve)(this.config.headers());
551
+ const resolvedHeaders = await (0, import_provider_utils5.resolve)(this.config.headers());
526
552
  try {
527
- const { value: response, responseHeaders } = await (0, import_provider_utils2.postJsonToApi)({
553
+ const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
528
554
  url: this.getUrl(),
529
- headers: (0, import_provider_utils2.combineHeaders)(
555
+ headers: (0, import_provider_utils5.combineHeaders)(
530
556
  resolvedHeaders,
531
557
  options.headers,
532
558
  this.getModelConfigHeaders(this.modelId, true),
533
- await (0, import_provider_utils2.resolve)(this.config.o11yHeaders)
559
+ await (0, import_provider_utils5.resolve)(this.config.o11yHeaders)
534
560
  ),
535
561
  body: args,
536
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(z5.any()),
537
- failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
562
+ successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(z5.any()),
563
+ failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
538
564
  errorSchema: z5.any(),
539
565
  errorToMessage: (data) => data
540
566
  }),
@@ -571,7 +597,7 @@ var GatewayLanguageModel = class {
571
597
  response: { headers: responseHeaders }
572
598
  };
573
599
  } catch (error) {
574
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
600
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
575
601
  }
576
602
  }
577
603
  isFilePart(part) {
@@ -613,7 +639,7 @@ var GatewayLanguageModel = class {
613
639
  };
614
640
 
615
641
  // src/gateway-embedding-model.ts
616
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
642
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
617
643
  var z6 = __toESM(require("zod/v4"));
618
644
  var GatewayEmbeddingModel = class {
619
645
  constructor(modelId, config) {
@@ -633,28 +659,28 @@ var GatewayEmbeddingModel = class {
633
659
  providerOptions
634
660
  }) {
635
661
  var _a8;
636
- const resolvedHeaders = await (0, import_provider_utils3.resolve)(this.config.headers());
662
+ const resolvedHeaders = await (0, import_provider_utils6.resolve)(this.config.headers());
637
663
  try {
638
664
  const {
639
665
  responseHeaders,
640
666
  value: responseBody,
641
667
  rawValue
642
- } = await (0, import_provider_utils3.postJsonToApi)({
668
+ } = await (0, import_provider_utils6.postJsonToApi)({
643
669
  url: this.getUrl(),
644
- headers: (0, import_provider_utils3.combineHeaders)(
670
+ headers: (0, import_provider_utils6.combineHeaders)(
645
671
  resolvedHeaders,
646
672
  headers != null ? headers : {},
647
673
  this.getModelConfigHeaders(),
648
- await (0, import_provider_utils3.resolve)(this.config.o11yHeaders)
674
+ await (0, import_provider_utils6.resolve)(this.config.o11yHeaders)
649
675
  ),
650
676
  body: {
651
677
  input: values.length === 1 ? values[0] : values,
652
678
  ...providerOptions ? { providerOptions } : {}
653
679
  },
654
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
680
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
655
681
  gatewayEmbeddingResponseSchema
656
682
  ),
657
- failedResponseHandler: (0, import_provider_utils3.createJsonErrorResponseHandler)({
683
+ failedResponseHandler: (0, import_provider_utils6.createJsonErrorResponseHandler)({
658
684
  errorSchema: z6.any(),
659
685
  errorToMessage: (data) => data
660
686
  }),
@@ -668,7 +694,7 @@ var GatewayEmbeddingModel = class {
668
694
  response: { headers: responseHeaders, body: rawValue }
669
695
  };
670
696
  } catch (error) {
671
- throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
697
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
672
698
  }
673
699
  }
674
700
  getUrl() {
@@ -681,11 +707,15 @@ var GatewayEmbeddingModel = class {
681
707
  };
682
708
  }
683
709
  };
684
- var gatewayEmbeddingResponseSchema = z6.object({
685
- embeddings: z6.array(z6.array(z6.number())),
686
- usage: z6.object({ tokens: z6.number() }).nullish(),
687
- providerMetadata: z6.record(z6.string(), z6.record(z6.string(), z6.unknown())).optional()
688
- });
710
+ var gatewayEmbeddingResponseSchema = (0, import_provider_utils6.lazyValidator)(
711
+ () => (0, import_provider_utils6.zodSchema)(
712
+ z6.object({
713
+ embeddings: z6.array(z6.array(z6.number())),
714
+ usage: z6.object({ tokens: z6.number() }).nullish(),
715
+ providerMetadata: z6.record(z6.string(), z6.record(z6.string(), z6.unknown())).optional()
716
+ })
717
+ )
718
+ );
689
719
 
690
720
  // src/vercel-environment.ts
691
721
  var import_oidc = require("@vercel/oidc");
@@ -696,10 +726,10 @@ async function getVercelRequestId() {
696
726
  }
697
727
 
698
728
  // src/gateway-provider.ts
699
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
729
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
700
730
 
701
731
  // src/version.ts
702
- var VERSION = true ? "2.0.0-beta.23" : "0.0.0-test";
732
+ var VERSION = true ? "2.0.0-beta.24" : "0.0.0-test";
703
733
 
704
734
  // src/gateway-provider.ts
705
735
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -709,11 +739,11 @@ function createGatewayProvider(options = {}) {
709
739
  let metadataCache = null;
710
740
  const cacheRefreshMillis = (_a8 = options.metadataCacheRefreshMillis) != null ? _a8 : 1e3 * 60 * 5;
711
741
  let lastFetchTime = 0;
712
- const baseURL = (_b8 = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
742
+ const baseURL = (_b8 = (0, import_provider_utils7.withoutTrailingSlash)(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
713
743
  const getHeaders = async () => {
714
744
  const auth = await getGatewayAuthToken(options);
715
745
  if (auth) {
716
- return (0, import_provider_utils5.withUserAgentSuffix)(
746
+ return (0, import_provider_utils8.withUserAgentSuffix)(
717
747
  {
718
748
  Authorization: `Bearer ${auth.token}`,
719
749
  "ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
@@ -730,15 +760,15 @@ function createGatewayProvider(options = {}) {
730
760
  });
731
761
  };
732
762
  const createO11yHeaders = () => {
733
- const deploymentId = (0, import_provider_utils4.loadOptionalSetting)({
763
+ const deploymentId = (0, import_provider_utils7.loadOptionalSetting)({
734
764
  settingValue: void 0,
735
765
  environmentVariableName: "VERCEL_DEPLOYMENT_ID"
736
766
  });
737
- const environment = (0, import_provider_utils4.loadOptionalSetting)({
767
+ const environment = (0, import_provider_utils7.loadOptionalSetting)({
738
768
  settingValue: void 0,
739
769
  environmentVariableName: "VERCEL_ENV"
740
770
  });
741
- const region = (0, import_provider_utils4.loadOptionalSetting)({
771
+ const region = (0, import_provider_utils7.loadOptionalSetting)({
742
772
  settingValue: void 0,
743
773
  environmentVariableName: "VERCEL_REGION"
744
774
  });
@@ -774,7 +804,10 @@ function createGatewayProvider(options = {}) {
774
804
  metadataCache = metadata;
775
805
  return metadata;
776
806
  }).catch(async (error) => {
777
- throw asGatewayError(error, parseAuthMethod(await getHeaders()));
807
+ throw await asGatewayError(
808
+ error,
809
+ await parseAuthMethod(await getHeaders())
810
+ );
778
811
  });
779
812
  }
780
813
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
@@ -785,7 +818,10 @@ function createGatewayProvider(options = {}) {
785
818
  headers: getHeaders,
786
819
  fetch: options.fetch
787
820
  }).getCredits().catch(async (error) => {
788
- throw asGatewayError(error, parseAuthMethod(await getHeaders()));
821
+ throw await asGatewayError(
822
+ error,
823
+ await parseAuthMethod(await getHeaders())
824
+ );
789
825
  });
790
826
  };
791
827
  const provider = function(modelId) {
@@ -815,7 +851,7 @@ function createGatewayProvider(options = {}) {
815
851
  }
816
852
  var gateway = createGatewayProvider();
817
853
  async function getGatewayAuthToken(options) {
818
- const apiKey = (0, import_provider_utils4.loadOptionalSetting)({
854
+ const apiKey = (0, import_provider_utils7.loadOptionalSetting)({
819
855
  settingValue: options.apiKey,
820
856
  environmentVariableName: "AI_GATEWAY_API_KEY"
821
857
  });