@ai-sdk/gateway 1.0.0-beta.1 → 1.0.0-beta.11

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,77 @@
1
1
  # @ai-sdk/gateway
2
2
 
3
+ ## 1.0.0-beta.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 8bd3624: feat (provider/gateway): update model ids to include vercel
8
+ - e001ea1: fix (provider/gateway): remove unnecessary 'x-' prefix on auth method header
9
+
10
+ ## 1.0.0-beta.10
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [57edfcb]
15
+ - Updated dependencies [383cbfa]
16
+ - @ai-sdk/provider-utils@3.0.0-beta.5
17
+
18
+ ## 1.0.0-beta.9
19
+
20
+ ### Patch Changes
21
+
22
+ - 205077b: fix: improve Zod compatibility
23
+ - Updated dependencies [205077b]
24
+ - @ai-sdk/provider-utils@3.0.0-beta.4
25
+
26
+ ## 1.0.0-beta.8
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [05d2819]
31
+ - @ai-sdk/provider-utils@3.0.0-beta.3
32
+
33
+ ## 1.0.0-beta.7
34
+
35
+ ### Patch Changes
36
+
37
+ - c190907: fix (provider/gateway): use zod v4
38
+
39
+ ## 1.0.0-beta.6
40
+
41
+ ### Patch Changes
42
+
43
+ - 9e16bfd: feat (provider/gateway): update model ids
44
+
45
+ ## 1.0.0-beta.5
46
+
47
+ ### Patch Changes
48
+
49
+ - 30ab1de: feat (provider/gateway): add grok-4 model id
50
+
51
+ ## 1.0.0-beta.4
52
+
53
+ ### Patch Changes
54
+
55
+ - 97fedf9: feat (providers/gateway): include description and pricing info in model list
56
+
57
+ ## 1.0.0-beta.3
58
+
59
+ ### Patch Changes
60
+
61
+ - f3639fa: feat (providers/gateway): improve oidc api key client auth flow
62
+ - d454e4b: fix (providers/gateway): fix timestamp error when streaming objects
63
+
64
+ ## 1.0.0-beta.2
65
+
66
+ ### Patch Changes
67
+
68
+ - c91586a: chore (providers/gateway): update language model ids
69
+ - d1a034f: feature: using Zod 4 for internal stuff
70
+ - Updated dependencies [0571b98]
71
+ - Updated dependencies [39a4fab]
72
+ - Updated dependencies [d1a034f]
73
+ - @ai-sdk/provider-utils@3.0.0-beta.2
74
+
3
75
  ## 1.0.0-beta.1
4
76
 
5
77
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { LanguageModelV2, ProviderV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { z, ZodError } from 'zod';
3
+ import { z, ZodError } from 'zod/v4';
4
4
 
5
- type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | 'alibaba/qwq-32b' | 'amazon/nova-lite' | 'amazon/nova-micro' | 'amazon/nova-pro' | 'anthropic/claude-3-haiku' | 'anthropic/claude-3-opus' | 'anthropic/claude-3-sonnet' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-3.5-sonnet' | 'anthropic/claude-3.7-sonnet' | 'anthropic/claude-4-opus' | 'anthropic/claude-4-sonnet' | 'cohere/command-a' | 'cohere/command-r' | 'cohere/command-r-plus' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-v3' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-pro' | 'google/gemma-2-9b' | 'inception/mercury-coder-small' | '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/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large' | 'mistral/mistral-saba-24b' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'morph/morph-v2' | '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/o1' | 'openai/o3' | 'openai/o3-mini' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning' | 'perplexity/sonar-reasoning-pro' | 'xai/grok-2' | 'xai/grok-2-vision' | 'xai/grok-3' | 'xai/grok-3-fast' | 'xai/grok-3-mini' | 'xai/grok-3-mini-fast' | (string & {});
5
+ type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | '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-4-opus' | 'anthropic/claude-4-sonnet' | 'cohere/command-a' | 'cohere/command-r' | 'cohere/command-r-plus' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-v3' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-pro' | 'google/gemma-2-9b' | 'inception/mercury-coder-small' | '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/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large' | 'mistral/mistral-saba-24b' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'moonshotai/kimi-k2' | '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/o1' | 'openai/o3' | 'openai/o3-mini' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning' | 'perplexity/sonar-reasoning-pro' | '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' | (string & {});
6
6
 
7
7
  interface GatewayLanguageModelEntry {
8
8
  /**
@@ -14,6 +14,23 @@ interface GatewayLanguageModelEntry {
14
14
  * The display name of the model for presentation in user-facing contexts.
15
15
  */
16
16
  name: string;
17
+ /**
18
+ * Optional description of the model.
19
+ */
20
+ description?: string | null;
21
+ /**
22
+ * Optional pricing information for the model.
23
+ */
24
+ pricing?: {
25
+ /**
26
+ * Cost per input token in USD.
27
+ */
28
+ input: string;
29
+ /**
30
+ * Cost per output token in USD.
31
+ */
32
+ output: string;
33
+ } | null;
17
34
  /**
18
35
  * Additional AI SDK language model specifications for the model.
19
36
  */
@@ -91,33 +108,9 @@ declare const gatewayErrorResponseSchema: z.ZodObject<{
91
108
  message: z.ZodString;
92
109
  type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
93
110
  param: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
94
- code: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
95
- }, "strip", z.ZodTypeAny, {
96
- message: string;
97
- code?: string | number | null | undefined;
98
- type?: string | null | undefined;
99
- param?: unknown;
100
- }, {
101
- message: string;
102
- code?: string | number | null | undefined;
103
- type?: string | null | undefined;
104
- param?: unknown;
105
- }>;
106
- }, "strip", z.ZodTypeAny, {
107
- error: {
108
- message: string;
109
- code?: string | number | null | undefined;
110
- type?: string | null | undefined;
111
- param?: unknown;
112
- };
113
- }, {
114
- error: {
115
- message: string;
116
- code?: string | number | null | undefined;
117
- type?: string | null | undefined;
118
- param?: unknown;
119
- };
120
- }>;
111
+ code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
112
+ }, z.core.$strip>;
113
+ }, z.core.$strip>;
121
114
  type GatewayErrorResponse = z.infer<typeof gatewayErrorResponseSchema>;
122
115
 
123
116
  declare const symbol$5: unique symbol;
@@ -134,6 +127,16 @@ declare class GatewayAuthenticationError extends GatewayError {
134
127
  cause?: unknown;
135
128
  });
136
129
  static isInstance(error: unknown): error is GatewayAuthenticationError;
130
+ /**
131
+ * Creates a contextual error message when authentication fails
132
+ */
133
+ static createContextualError({ apiKeyProvided, oidcTokenProvided, message, statusCode, cause, }: {
134
+ apiKeyProvided: boolean;
135
+ oidcTokenProvided: boolean;
136
+ message?: string;
137
+ statusCode?: number;
138
+ cause?: unknown;
139
+ }): GatewayAuthenticationError;
137
140
  }
138
141
 
139
142
  declare const symbol$4: unique symbol;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { LanguageModelV2, ProviderV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { z, ZodError } from 'zod';
3
+ import { z, ZodError } from 'zod/v4';
4
4
 
5
- type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | 'alibaba/qwq-32b' | 'amazon/nova-lite' | 'amazon/nova-micro' | 'amazon/nova-pro' | 'anthropic/claude-3-haiku' | 'anthropic/claude-3-opus' | 'anthropic/claude-3-sonnet' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-3.5-sonnet' | 'anthropic/claude-3.7-sonnet' | 'anthropic/claude-4-opus' | 'anthropic/claude-4-sonnet' | 'cohere/command-a' | 'cohere/command-r' | 'cohere/command-r-plus' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-v3' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-pro' | 'google/gemma-2-9b' | 'inception/mercury-coder-small' | '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/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large' | 'mistral/mistral-saba-24b' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'morph/morph-v2' | '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/o1' | 'openai/o3' | 'openai/o3-mini' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning' | 'perplexity/sonar-reasoning-pro' | 'xai/grok-2' | 'xai/grok-2-vision' | 'xai/grok-3' | 'xai/grok-3-fast' | 'xai/grok-3-mini' | 'xai/grok-3-mini-fast' | (string & {});
5
+ type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | '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-4-opus' | 'anthropic/claude-4-sonnet' | 'cohere/command-a' | 'cohere/command-r' | 'cohere/command-r-plus' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-v3' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-pro' | 'google/gemma-2-9b' | 'inception/mercury-coder-small' | '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/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large' | 'mistral/mistral-saba-24b' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'moonshotai/kimi-k2' | '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/o1' | 'openai/o3' | 'openai/o3-mini' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning' | 'perplexity/sonar-reasoning-pro' | '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' | (string & {});
6
6
 
7
7
  interface GatewayLanguageModelEntry {
8
8
  /**
@@ -14,6 +14,23 @@ interface GatewayLanguageModelEntry {
14
14
  * The display name of the model for presentation in user-facing contexts.
15
15
  */
16
16
  name: string;
17
+ /**
18
+ * Optional description of the model.
19
+ */
20
+ description?: string | null;
21
+ /**
22
+ * Optional pricing information for the model.
23
+ */
24
+ pricing?: {
25
+ /**
26
+ * Cost per input token in USD.
27
+ */
28
+ input: string;
29
+ /**
30
+ * Cost per output token in USD.
31
+ */
32
+ output: string;
33
+ } | null;
17
34
  /**
18
35
  * Additional AI SDK language model specifications for the model.
19
36
  */
@@ -91,33 +108,9 @@ declare const gatewayErrorResponseSchema: z.ZodObject<{
91
108
  message: z.ZodString;
92
109
  type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
93
110
  param: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
94
- code: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
95
- }, "strip", z.ZodTypeAny, {
96
- message: string;
97
- code?: string | number | null | undefined;
98
- type?: string | null | undefined;
99
- param?: unknown;
100
- }, {
101
- message: string;
102
- code?: string | number | null | undefined;
103
- type?: string | null | undefined;
104
- param?: unknown;
105
- }>;
106
- }, "strip", z.ZodTypeAny, {
107
- error: {
108
- message: string;
109
- code?: string | number | null | undefined;
110
- type?: string | null | undefined;
111
- param?: unknown;
112
- };
113
- }, {
114
- error: {
115
- message: string;
116
- code?: string | number | null | undefined;
117
- type?: string | null | undefined;
118
- param?: unknown;
119
- };
120
- }>;
111
+ code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
112
+ }, z.core.$strip>;
113
+ }, z.core.$strip>;
121
114
  type GatewayErrorResponse = z.infer<typeof gatewayErrorResponseSchema>;
122
115
 
123
116
  declare const symbol$5: unique symbol;
@@ -134,6 +127,16 @@ declare class GatewayAuthenticationError extends GatewayError {
134
127
  cause?: unknown;
135
128
  });
136
129
  static isInstance(error: unknown): error is GatewayAuthenticationError;
130
+ /**
131
+ * Creates a contextual error message when authentication fails
132
+ */
133
+ static createContextualError({ apiKeyProvided, oidcTokenProvided, message, statusCode, cause, }: {
134
+ apiKeyProvided: boolean;
135
+ oidcTokenProvided: boolean;
136
+ message?: string;
137
+ statusCode?: number;
138
+ cause?: unknown;
139
+ }): GatewayAuthenticationError;
137
140
  }
138
141
 
139
142
  declare const symbol$4: unique symbol;
package/dist/index.js CHANGED
@@ -41,7 +41,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
41
41
  var import_provider = require("@ai-sdk/provider");
42
42
 
43
43
  // src/errors/create-gateway-error.ts
44
- var import_zod2 = require("zod");
44
+ var import_v42 = require("zod/v4");
45
45
 
46
46
  // src/errors/gateway-error.ts
47
47
  var marker = "vercel.ai.gateway.error";
@@ -76,7 +76,7 @@ var name = "GatewayAuthenticationError";
76
76
  var marker2 = `vercel.ai.gateway.error.${name}`;
77
77
  var symbol2 = Symbol.for(marker2);
78
78
  var _a2, _b2;
79
- var GatewayAuthenticationError = class extends (_b2 = GatewayError, _a2 = symbol2, _b2) {
79
+ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2 = GatewayError, _a2 = symbol2, _b2) {
80
80
  constructor({
81
81
  message = "Authentication failed",
82
82
  statusCode = 401,
@@ -91,6 +91,54 @@ var GatewayAuthenticationError = class extends (_b2 = GatewayError, _a2 = symbol
91
91
  static isInstance(error) {
92
92
  return GatewayError.hasMarker(error) && symbol2 in error;
93
93
  }
94
+ /**
95
+ * Creates a contextual error message when authentication fails
96
+ */
97
+ static createContextualError({
98
+ apiKeyProvided,
99
+ oidcTokenProvided,
100
+ message = "Authentication failed",
101
+ statusCode = 401,
102
+ cause
103
+ }) {
104
+ let contextualMessage;
105
+ if (apiKeyProvided) {
106
+ contextualMessage = `AI Gateway authentication failed: Invalid API key provided.
107
+
108
+ The token is expected to be provided via the 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
109
+ } else if (oidcTokenProvided) {
110
+ contextualMessage = `AI Gateway authentication failed: Invalid OIDC token provided.
111
+
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
117
+
118
+ Alternative: Provide an API key via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
119
+ } else {
120
+ contextualMessage = `AI Gateway authentication failed: No authentication provided.
121
+
122
+ Provide either an API key or OIDC token.
123
+
124
+ API key instructions:
125
+
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`;
135
+ }
136
+ return new _GatewayAuthenticationError({
137
+ message: contextualMessage,
138
+ statusCode,
139
+ cause
140
+ });
141
+ }
94
142
  };
95
143
 
96
144
  // src/errors/gateway-invalid-request-error.ts
@@ -138,12 +186,12 @@ var GatewayRateLimitError = class extends (_b4 = GatewayError, _a4 = symbol4, _b
138
186
  };
139
187
 
140
188
  // src/errors/gateway-model-not-found-error.ts
141
- var import_zod = require("zod");
189
+ var import_v4 = require("zod/v4");
142
190
  var name4 = "GatewayModelNotFoundError";
143
191
  var marker5 = `vercel.ai.gateway.error.${name4}`;
144
192
  var symbol5 = Symbol.for(marker5);
145
- var modelNotFoundParamSchema = import_zod.z.object({
146
- modelId: import_zod.z.string()
193
+ var modelNotFoundParamSchema = import_v4.z.object({
194
+ modelId: import_v4.z.string()
147
195
  });
148
196
  var _a5, _b5;
149
197
  var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a5 = symbol5, _b5) {
@@ -218,7 +266,8 @@ function createGatewayErrorFromResponse({
218
266
  response,
219
267
  statusCode,
220
268
  defaultMessage = "Gateway request failed",
221
- cause
269
+ cause,
270
+ authMethod
222
271
  }) {
223
272
  const parseResult = gatewayErrorResponseSchema.safeParse(response);
224
273
  if (!parseResult.success) {
@@ -235,7 +284,12 @@ function createGatewayErrorFromResponse({
235
284
  const message = validatedResponse.error.message;
236
285
  switch (errorType) {
237
286
  case "authentication_error":
238
- return new GatewayAuthenticationError({ message, statusCode, cause });
287
+ return GatewayAuthenticationError.createContextualError({
288
+ apiKeyProvided: authMethod === "api-key",
289
+ oidcTokenProvided: authMethod === "oidc",
290
+ statusCode,
291
+ cause
292
+ });
239
293
  case "invalid_request_error":
240
294
  return new GatewayInvalidRequestError({ message, statusCode, cause });
241
295
  case "rate_limit_exceeded":
@@ -257,17 +311,17 @@ function createGatewayErrorFromResponse({
257
311
  return new GatewayInternalServerError({ message, statusCode, cause });
258
312
  }
259
313
  }
260
- var gatewayErrorResponseSchema = import_zod2.z.object({
261
- error: import_zod2.z.object({
262
- message: import_zod2.z.string(),
263
- type: import_zod2.z.string().nullish(),
264
- param: import_zod2.z.unknown().nullish(),
265
- code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
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()
266
320
  })
267
321
  });
268
322
 
269
323
  // src/errors/as-gateway-error.ts
270
- function asGatewayError(error) {
324
+ function asGatewayError(error, authMethod) {
271
325
  var _a8;
272
326
  if (GatewayError.isInstance(error)) {
273
327
  return error;
@@ -277,14 +331,16 @@ function asGatewayError(error) {
277
331
  response: extractApiCallResponse(error),
278
332
  statusCode: (_a8 = error.statusCode) != null ? _a8 : 500,
279
333
  defaultMessage: "Gateway request failed",
280
- cause: error
334
+ cause: error,
335
+ authMethod
281
336
  });
282
337
  }
283
338
  return createGatewayErrorFromResponse({
284
339
  response: {},
285
340
  statusCode: 500,
286
341
  defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
287
- cause: error
342
+ cause: error,
343
+ authMethod
288
344
  });
289
345
  }
290
346
 
@@ -303,9 +359,23 @@ function extractApiCallResponse(error) {
303
359
  return {};
304
360
  }
305
361
 
362
+ // src/errors/parse-auth-method.ts
363
+ var import_v43 = require("zod/v4");
364
+ 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
+ }
371
+ var gatewayAuthMethodSchema = import_v43.z.union([
372
+ import_v43.z.literal("api-key"),
373
+ import_v43.z.literal("oidc")
374
+ ]);
375
+
306
376
  // src/gateway-fetch-metadata.ts
307
377
  var import_provider_utils = require("@ai-sdk/provider-utils");
308
- var import_zod3 = require("zod");
378
+ var import_v44 = require("zod/v4");
309
379
  var GatewayFetchMetadata = class {
310
380
  constructor(config) {
311
381
  this.config = config;
@@ -319,7 +389,7 @@ var GatewayFetchMetadata = class {
319
389
  gatewayFetchMetadataSchema
320
390
  ),
321
391
  failedResponseHandler: (0, import_provider_utils.createJsonErrorResponseHandler)({
322
- errorSchema: import_zod3.z.any(),
392
+ errorSchema: import_v44.z.any(),
323
393
  errorToMessage: (data) => data
324
394
  }),
325
395
  fetch: this.config.fetch
@@ -330,23 +400,29 @@ var GatewayFetchMetadata = class {
330
400
  }
331
401
  }
332
402
  };
333
- var gatewayLanguageModelSpecificationSchema = import_zod3.z.object({
334
- specificationVersion: import_zod3.z.literal("v2"),
335
- provider: import_zod3.z.string(),
336
- modelId: import_zod3.z.string()
403
+ var gatewayLanguageModelSpecificationSchema = import_v44.z.object({
404
+ specificationVersion: import_v44.z.literal("v2"),
405
+ provider: import_v44.z.string(),
406
+ modelId: import_v44.z.string()
407
+ });
408
+ var gatewayLanguageModelPricingSchema = import_v44.z.object({
409
+ input: import_v44.z.string(),
410
+ output: import_v44.z.string()
337
411
  });
338
- var gatewayLanguageModelEntrySchema = import_zod3.z.object({
339
- id: import_zod3.z.string(),
340
- name: import_zod3.z.string(),
412
+ var gatewayLanguageModelEntrySchema = import_v44.z.object({
413
+ id: import_v44.z.string(),
414
+ name: import_v44.z.string(),
415
+ description: import_v44.z.string().nullish(),
416
+ pricing: gatewayLanguageModelPricingSchema.nullish(),
341
417
  specification: gatewayLanguageModelSpecificationSchema
342
418
  });
343
- var gatewayFetchMetadataSchema = import_zod3.z.object({
344
- models: import_zod3.z.array(gatewayLanguageModelEntrySchema)
419
+ var gatewayFetchMetadataSchema = import_v44.z.object({
420
+ models: import_v44.z.array(gatewayLanguageModelEntrySchema)
345
421
  });
346
422
 
347
423
  // src/gateway-language-model.ts
348
424
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
349
- var import_zod4 = require("zod");
425
+ var import_v45 = require("zod/v4");
350
426
  var GatewayLanguageModel = class {
351
427
  constructor(modelId, config) {
352
428
  this.modelId = modelId;
@@ -359,6 +435,7 @@ var GatewayLanguageModel = class {
359
435
  }
360
436
  async doGenerate(options) {
361
437
  const { abortSignal, ...body } = options;
438
+ const resolvedHeaders = await (0, import_provider_utils2.resolve)(this.config.headers());
362
439
  try {
363
440
  const {
364
441
  responseHeaders,
@@ -367,15 +444,15 @@ var GatewayLanguageModel = class {
367
444
  } = await (0, import_provider_utils2.postJsonToApi)({
368
445
  url: this.getUrl(),
369
446
  headers: (0, import_provider_utils2.combineHeaders)(
370
- await (0, import_provider_utils2.resolve)(this.config.headers()),
447
+ resolvedHeaders,
371
448
  options.headers,
372
449
  this.getModelConfigHeaders(this.modelId, false),
373
450
  await (0, import_provider_utils2.resolve)(this.config.o11yHeaders)
374
451
  ),
375
452
  body: this.maybeEncodeFileParts(body),
376
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(import_zod4.z.any()),
453
+ successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(import_v45.z.any()),
377
454
  failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
378
- errorSchema: import_zod4.z.any(),
455
+ errorSchema: import_v45.z.any(),
379
456
  errorToMessage: (data) => data
380
457
  }),
381
458
  ...abortSignal && { abortSignal },
@@ -388,24 +465,25 @@ var GatewayLanguageModel = class {
388
465
  warnings: []
389
466
  };
390
467
  } catch (error) {
391
- throw asGatewayError(error);
468
+ throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
392
469
  }
393
470
  }
394
471
  async doStream(options) {
395
472
  const { abortSignal, ...body } = options;
473
+ const resolvedHeaders = await (0, import_provider_utils2.resolve)(this.config.headers());
396
474
  try {
397
475
  const { value: response, responseHeaders } = await (0, import_provider_utils2.postJsonToApi)({
398
476
  url: this.getUrl(),
399
477
  headers: (0, import_provider_utils2.combineHeaders)(
400
- await (0, import_provider_utils2.resolve)(this.config.headers()),
478
+ resolvedHeaders,
401
479
  options.headers,
402
480
  this.getModelConfigHeaders(this.modelId, true),
403
481
  await (0, import_provider_utils2.resolve)(this.config.o11yHeaders)
404
482
  ),
405
483
  body: this.maybeEncodeFileParts(body),
406
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(import_zod4.z.any()),
484
+ successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(import_v45.z.any()),
407
485
  failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
408
- errorSchema: import_zod4.z.any(),
486
+ errorSchema: import_v45.z.any(),
409
487
  errorToMessage: (data) => data
410
488
  }),
411
489
  ...abortSignal && { abortSignal },
@@ -420,6 +498,9 @@ var GatewayLanguageModel = class {
420
498
  if (streamPart.type === "raw" && !options.includeRawChunks) {
421
499
  return;
422
500
  }
501
+ if (streamPart.type === "response-metadata" && streamPart.timestamp && typeof streamPart.timestamp === "string") {
502
+ streamPart.timestamp = new Date(streamPart.timestamp);
503
+ }
423
504
  controller.enqueue(streamPart);
424
505
  } else {
425
506
  controller.error(
@@ -433,17 +514,17 @@ var GatewayLanguageModel = class {
433
514
  response: { headers: responseHeaders }
434
515
  };
435
516
  } catch (error) {
436
- throw asGatewayError(error);
517
+ throw asGatewayError(error, parseAuthMethod(resolvedHeaders));
437
518
  }
438
519
  }
439
520
  isFilePart(part) {
440
521
  return part && typeof part === "object" && "type" in part && part.type === "file";
441
522
  }
442
523
  /**
443
- * Encodes image parts in the prompt to base64. Mutates the passed options
444
- * instance directly to avoid copying the image data.
524
+ * Encodes file parts in the prompt to base64. Mutates the passed options
525
+ * instance directly to avoid copying the file data.
445
526
  * @param options - The options to encode.
446
- * @returns The options with the image parts encoded.
527
+ * @returns The options with the file parts encoded.
447
528
  */
448
529
  maybeEncodeFileParts(options) {
449
530
  for (const message of options.prompt) {
@@ -480,12 +561,7 @@ async function getVercelOidcToken() {
480
561
  const token = (_b8 = (_a8 = getContext().headers) == null ? void 0 : _a8["x-vercel-oidc-token"]) != null ? _b8 : process.env.VERCEL_OIDC_TOKEN;
481
562
  if (!token) {
482
563
  throw new GatewayAuthenticationError({
483
- message: `Failed to get Vercel OIDC token for AI Gateway access.
484
- The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
485
- - make sure your Vercel project settings have OIDC enabled
486
- - if you're running locally with 'vercel dev' the token is automatically obtained and refreshed for you
487
- - if you're running locally with your own dev server script you can fetch/update the token by running 'vercel env pull'
488
- - in production or preview the token is automatically obtained and refreshed for you`,
564
+ message: "OIDC token not available",
489
565
  statusCode: 401
490
566
  });
491
567
  }
@@ -504,13 +580,6 @@ function getContext() {
504
580
 
505
581
  // src/gateway-provider.ts
506
582
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
507
- async function getGatewayAuthToken(options) {
508
- var _a8;
509
- return (_a8 = (0, import_provider_utils3.loadOptionalSetting)({
510
- settingValue: options.apiKey,
511
- environmentVariableName: "AI_GATEWAY_API_KEY"
512
- })) != null ? _a8 : await getVercelOidcToken();
513
- }
514
583
  function createGatewayProvider(options = {}) {
515
584
  var _a8, _b8;
516
585
  let pendingMetadata = null;
@@ -519,11 +588,20 @@ function createGatewayProvider(options = {}) {
519
588
  let lastFetchTime = 0;
520
589
  const baseURL = (_b8 = (0, import_provider_utils3.withoutTrailingSlash)(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
521
590
  const getHeaders = async () => {
522
- return {
523
- Authorization: `Bearer ${await getGatewayAuthToken(options)}`,
524
- "ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
525
- ...options.headers
526
- };
591
+ const auth = await getGatewayAuthToken(options);
592
+ if (auth) {
593
+ return {
594
+ Authorization: `Bearer ${auth.token}`,
595
+ "ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
596
+ [GATEWAY_AUTH_METHOD_HEADER]: auth.authMethod,
597
+ ...options.headers
598
+ };
599
+ }
600
+ throw GatewayAuthenticationError.createContextualError({
601
+ apiKeyProvided: false,
602
+ oidcTokenProvided: false,
603
+ statusCode: 401
604
+ });
527
605
  };
528
606
  const createLanguageModel = (modelId) => {
529
607
  const deploymentId = (0, import_provider_utils3.loadOptionalSetting)({
@@ -566,8 +644,8 @@ function createGatewayProvider(options = {}) {
566
644
  }).getAvailableModels().then((metadata) => {
567
645
  metadataCache = metadata;
568
646
  return metadata;
569
- }).catch((error) => {
570
- throw asGatewayError(error);
647
+ }).catch(async (error) => {
648
+ throw asGatewayError(error, parseAuthMethod(await getHeaders()));
571
649
  });
572
650
  }
573
651
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
@@ -591,6 +669,27 @@ function createGatewayProvider(options = {}) {
591
669
  return provider;
592
670
  }
593
671
  var gateway = createGatewayProvider();
672
+ async function getGatewayAuthToken(options) {
673
+ const apiKey = (0, import_provider_utils3.loadOptionalSetting)({
674
+ settingValue: options.apiKey,
675
+ environmentVariableName: "AI_GATEWAY_API_KEY"
676
+ });
677
+ if (apiKey) {
678
+ return {
679
+ token: apiKey,
680
+ authMethod: "api-key"
681
+ };
682
+ }
683
+ try {
684
+ const oidcToken = await getVercelOidcToken();
685
+ return {
686
+ token: oidcToken,
687
+ authMethod: "oidc"
688
+ };
689
+ } catch (error) {
690
+ return null;
691
+ }
692
+ }
594
693
  // Annotate the CommonJS export names for ESM import in node:
595
694
  0 && (module.exports = {
596
695
  GatewayAuthenticationError,