@ai-sdk/gateway 1.0.0-alpha.7 → 1.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,20 +1,332 @@
1
1
  // src/gateway-provider.ts
2
2
  import { NoSuchModelError } from "@ai-sdk/provider";
3
- import { loadOptionalSetting } from "@ai-sdk/provider-utils";
4
3
  import {
4
+ loadOptionalSetting,
5
5
  withoutTrailingSlash
6
6
  } from "@ai-sdk/provider-utils";
7
7
 
8
+ // src/errors/as-gateway-error.ts
9
+ import { APICallError } from "@ai-sdk/provider";
10
+
11
+ // src/errors/create-gateway-error.ts
12
+ import { z as z2 } from "zod";
13
+
14
+ // src/errors/gateway-error.ts
15
+ var marker = "vercel.ai.gateway.error";
16
+ var symbol = Symbol.for(marker);
17
+ var _a, _b;
18
+ var GatewayError = class _GatewayError extends (_b = Error, _a = symbol, _b) {
19
+ constructor({
20
+ message,
21
+ statusCode = 500,
22
+ cause
23
+ }) {
24
+ super(message);
25
+ this[_a] = true;
26
+ this.statusCode = statusCode;
27
+ this.cause = cause;
28
+ }
29
+ /**
30
+ * Checks if the given error is a Gateway Error.
31
+ * @param {unknown} error - The error to check.
32
+ * @returns {boolean} True if the error is a Gateway Error, false otherwise.
33
+ */
34
+ static isInstance(error) {
35
+ return _GatewayError.hasMarker(error);
36
+ }
37
+ static hasMarker(error) {
38
+ return typeof error === "object" && error !== null && symbol in error && error[symbol] === true;
39
+ }
40
+ };
41
+
42
+ // src/errors/gateway-authentication-error.ts
43
+ var name = "GatewayAuthenticationError";
44
+ var marker2 = `vercel.ai.gateway.error.${name}`;
45
+ var symbol2 = Symbol.for(marker2);
46
+ var _a2, _b2;
47
+ var GatewayAuthenticationError = class extends (_b2 = GatewayError, _a2 = symbol2, _b2) {
48
+ constructor({
49
+ message = "Authentication failed",
50
+ statusCode = 401,
51
+ cause
52
+ } = {}) {
53
+ super({ message, statusCode, cause });
54
+ this[_a2] = true;
55
+ // used in isInstance
56
+ this.name = name;
57
+ this.type = "authentication_error";
58
+ }
59
+ static isInstance(error) {
60
+ return GatewayError.hasMarker(error) && symbol2 in error;
61
+ }
62
+ };
63
+
64
+ // src/errors/gateway-invalid-request-error.ts
65
+ var name2 = "GatewayInvalidRequestError";
66
+ var marker3 = `vercel.ai.gateway.error.${name2}`;
67
+ var symbol3 = Symbol.for(marker3);
68
+ var _a3, _b3;
69
+ var GatewayInvalidRequestError = class extends (_b3 = GatewayError, _a3 = symbol3, _b3) {
70
+ constructor({
71
+ message = "Invalid request",
72
+ statusCode = 400,
73
+ cause
74
+ } = {}) {
75
+ super({ message, statusCode, cause });
76
+ this[_a3] = true;
77
+ // used in isInstance
78
+ this.name = name2;
79
+ this.type = "invalid_request_error";
80
+ }
81
+ static isInstance(error) {
82
+ return GatewayError.hasMarker(error) && symbol3 in error;
83
+ }
84
+ };
85
+
86
+ // src/errors/gateway-rate-limit-error.ts
87
+ var name3 = "GatewayRateLimitError";
88
+ var marker4 = `vercel.ai.gateway.error.${name3}`;
89
+ var symbol4 = Symbol.for(marker4);
90
+ var _a4, _b4;
91
+ var GatewayRateLimitError = class extends (_b4 = GatewayError, _a4 = symbol4, _b4) {
92
+ constructor({
93
+ message = "Rate limit exceeded",
94
+ statusCode = 429,
95
+ cause
96
+ } = {}) {
97
+ super({ message, statusCode, cause });
98
+ this[_a4] = true;
99
+ // used in isInstance
100
+ this.name = name3;
101
+ this.type = "rate_limit_exceeded";
102
+ }
103
+ static isInstance(error) {
104
+ return GatewayError.hasMarker(error) && symbol4 in error;
105
+ }
106
+ };
107
+
108
+ // src/errors/gateway-model-not-found-error.ts
109
+ import { z } from "zod";
110
+ var name4 = "GatewayModelNotFoundError";
111
+ var marker5 = `vercel.ai.gateway.error.${name4}`;
112
+ var symbol5 = Symbol.for(marker5);
113
+ var modelNotFoundParamSchema = z.object({
114
+ modelId: z.string()
115
+ });
116
+ var _a5, _b5;
117
+ var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a5 = symbol5, _b5) {
118
+ constructor({
119
+ message = "Model not found",
120
+ statusCode = 404,
121
+ modelId,
122
+ cause
123
+ } = {}) {
124
+ super({ message, statusCode, cause });
125
+ this[_a5] = true;
126
+ // used in isInstance
127
+ this.name = name4;
128
+ this.type = "model_not_found";
129
+ this.modelId = modelId;
130
+ }
131
+ static isInstance(error) {
132
+ return GatewayError.hasMarker(error) && symbol5 in error;
133
+ }
134
+ };
135
+
136
+ // src/errors/gateway-internal-server-error.ts
137
+ var name5 = "GatewayInternalServerError";
138
+ var marker6 = `vercel.ai.gateway.error.${name5}`;
139
+ var symbol6 = Symbol.for(marker6);
140
+ var _a6, _b6;
141
+ var GatewayInternalServerError = class extends (_b6 = GatewayError, _a6 = symbol6, _b6) {
142
+ constructor({
143
+ message = "Internal server error",
144
+ statusCode = 500,
145
+ cause
146
+ } = {}) {
147
+ super({ message, statusCode, cause });
148
+ this[_a6] = true;
149
+ // used in isInstance
150
+ this.name = name5;
151
+ this.type = "internal_server_error";
152
+ }
153
+ static isInstance(error) {
154
+ return GatewayError.hasMarker(error) && symbol6 in error;
155
+ }
156
+ };
157
+
158
+ // src/errors/gateway-response-error.ts
159
+ var name6 = "GatewayResponseError";
160
+ var marker7 = `vercel.ai.gateway.error.${name6}`;
161
+ var symbol7 = Symbol.for(marker7);
162
+ var _a7, _b7;
163
+ var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7) {
164
+ constructor({
165
+ message = "Invalid response from Gateway",
166
+ statusCode = 502,
167
+ response,
168
+ validationError,
169
+ cause
170
+ } = {}) {
171
+ super({ message, statusCode, cause });
172
+ this[_a7] = true;
173
+ // used in isInstance
174
+ this.name = name6;
175
+ this.type = "response_error";
176
+ this.response = response;
177
+ this.validationError = validationError;
178
+ }
179
+ static isInstance(error) {
180
+ return GatewayError.hasMarker(error) && symbol7 in error;
181
+ }
182
+ };
183
+
184
+ // src/errors/create-gateway-error.ts
185
+ function createGatewayErrorFromResponse({
186
+ response,
187
+ statusCode,
188
+ defaultMessage = "Gateway request failed",
189
+ cause
190
+ }) {
191
+ const parseResult = gatewayErrorResponseSchema.safeParse(response);
192
+ if (!parseResult.success) {
193
+ return new GatewayResponseError({
194
+ message: `Invalid error response format: ${defaultMessage}`,
195
+ statusCode,
196
+ response,
197
+ validationError: parseResult.error,
198
+ cause
199
+ });
200
+ }
201
+ const validatedResponse = parseResult.data;
202
+ const errorType = validatedResponse.error.type;
203
+ const message = validatedResponse.error.message;
204
+ switch (errorType) {
205
+ case "authentication_error":
206
+ return new GatewayAuthenticationError({ message, statusCode, cause });
207
+ case "invalid_request_error":
208
+ return new GatewayInvalidRequestError({ message, statusCode, cause });
209
+ case "rate_limit_exceeded":
210
+ return new GatewayRateLimitError({ message, statusCode, cause });
211
+ case "model_not_found": {
212
+ const modelResult = modelNotFoundParamSchema.safeParse(
213
+ validatedResponse.error.param
214
+ );
215
+ return new GatewayModelNotFoundError({
216
+ message,
217
+ statusCode,
218
+ modelId: modelResult.success ? modelResult.data.modelId : void 0,
219
+ cause
220
+ });
221
+ }
222
+ case "internal_server_error":
223
+ return new GatewayInternalServerError({ message, statusCode, cause });
224
+ default:
225
+ return new GatewayInternalServerError({ message, statusCode, cause });
226
+ }
227
+ }
228
+ var gatewayErrorResponseSchema = z2.object({
229
+ error: z2.object({
230
+ message: z2.string(),
231
+ type: z2.string().nullish(),
232
+ param: z2.unknown().nullish(),
233
+ code: z2.union([z2.string(), z2.number()]).nullish()
234
+ })
235
+ });
236
+
237
+ // src/errors/as-gateway-error.ts
238
+ function asGatewayError(error) {
239
+ var _a8;
240
+ if (GatewayError.isInstance(error)) {
241
+ return error;
242
+ }
243
+ if (APICallError.isInstance(error)) {
244
+ return createGatewayErrorFromResponse({
245
+ response: extractApiCallResponse(error),
246
+ statusCode: (_a8 = error.statusCode) != null ? _a8 : 500,
247
+ defaultMessage: "Gateway request failed",
248
+ cause: error
249
+ });
250
+ }
251
+ return createGatewayErrorFromResponse({
252
+ response: {},
253
+ statusCode: 500,
254
+ defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
255
+ cause: error
256
+ });
257
+ }
258
+
259
+ // src/errors/extract-api-call-response.ts
260
+ function extractApiCallResponse(error) {
261
+ if (error.data !== void 0) {
262
+ return error.data;
263
+ }
264
+ if (error.responseBody != null) {
265
+ try {
266
+ return JSON.parse(error.responseBody);
267
+ } catch (e) {
268
+ return error.responseBody;
269
+ }
270
+ }
271
+ return {};
272
+ }
273
+
274
+ // src/gateway-fetch-metadata.ts
275
+ import {
276
+ createJsonErrorResponseHandler,
277
+ createJsonResponseHandler,
278
+ getFromApi,
279
+ resolve
280
+ } from "@ai-sdk/provider-utils";
281
+ import { z as z3 } from "zod";
282
+ var GatewayFetchMetadata = class {
283
+ constructor(config) {
284
+ this.config = config;
285
+ }
286
+ async getAvailableModels() {
287
+ try {
288
+ const { value } = await getFromApi({
289
+ url: `${this.config.baseURL}/config`,
290
+ headers: await resolve(this.config.headers()),
291
+ successfulResponseHandler: createJsonResponseHandler(
292
+ gatewayFetchMetadataSchema
293
+ ),
294
+ failedResponseHandler: createJsonErrorResponseHandler({
295
+ errorSchema: z3.any(),
296
+ errorToMessage: (data) => data
297
+ }),
298
+ fetch: this.config.fetch
299
+ });
300
+ return value;
301
+ } catch (error) {
302
+ throw asGatewayError(error);
303
+ }
304
+ }
305
+ };
306
+ var gatewayLanguageModelSpecificationSchema = z3.object({
307
+ specificationVersion: z3.literal("v2"),
308
+ provider: z3.string(),
309
+ modelId: z3.string()
310
+ });
311
+ var gatewayLanguageModelEntrySchema = z3.object({
312
+ id: z3.string(),
313
+ name: z3.string(),
314
+ specification: gatewayLanguageModelSpecificationSchema
315
+ });
316
+ var gatewayFetchMetadataSchema = z3.object({
317
+ models: z3.array(gatewayLanguageModelEntrySchema)
318
+ });
319
+
8
320
  // src/gateway-language-model.ts
9
321
  import {
10
322
  combineHeaders,
11
323
  createEventSourceResponseHandler,
12
- createJsonErrorResponseHandler,
13
- createJsonResponseHandler,
324
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
325
+ createJsonResponseHandler as createJsonResponseHandler2,
14
326
  postJsonToApi,
15
- resolve
327
+ resolve as resolve2
16
328
  } from "@ai-sdk/provider-utils";
17
- import { z } from "zod";
329
+ import { z as z4 } from "zod";
18
330
  var GatewayLanguageModel = class {
19
331
  constructor(modelId, config) {
20
332
  this.modelId = modelId;
@@ -27,70 +339,78 @@ var GatewayLanguageModel = class {
27
339
  }
28
340
  async doGenerate(options) {
29
341
  const { abortSignal, ...body } = options;
30
- const {
31
- responseHeaders,
32
- value: responseBody,
33
- rawValue: rawResponse
34
- } = await postJsonToApi({
35
- url: this.getUrl(),
36
- headers: combineHeaders(
37
- await resolve(this.config.headers()),
38
- options.headers,
39
- this.getModelConfigHeaders(this.modelId, false),
40
- this.config.o11yHeaders
41
- ),
42
- body: this.maybeEncodeFileParts(body),
43
- successfulResponseHandler: createJsonResponseHandler(z.any()),
44
- failedResponseHandler: createJsonErrorResponseHandler({
45
- errorSchema: z.any(),
46
- errorToMessage: (data) => data
47
- }),
48
- ...abortSignal && { abortSignal },
49
- fetch: this.config.fetch
50
- });
51
- return {
52
- ...responseBody,
53
- request: { body },
54
- response: { headers: responseHeaders, body: rawResponse },
55
- warnings: []
56
- };
342
+ try {
343
+ const {
344
+ responseHeaders,
345
+ value: responseBody,
346
+ rawValue: rawResponse
347
+ } = await postJsonToApi({
348
+ url: this.getUrl(),
349
+ headers: combineHeaders(
350
+ await resolve2(this.config.headers()),
351
+ options.headers,
352
+ this.getModelConfigHeaders(this.modelId, false),
353
+ this.config.o11yHeaders
354
+ ),
355
+ body: this.maybeEncodeFileParts(body),
356
+ successfulResponseHandler: createJsonResponseHandler2(z4.any()),
357
+ failedResponseHandler: createJsonErrorResponseHandler2({
358
+ errorSchema: z4.any(),
359
+ errorToMessage: (data) => data
360
+ }),
361
+ ...abortSignal && { abortSignal },
362
+ fetch: this.config.fetch
363
+ });
364
+ return {
365
+ ...responseBody,
366
+ request: { body },
367
+ response: { headers: responseHeaders, body: rawResponse },
368
+ warnings: []
369
+ };
370
+ } catch (error) {
371
+ throw asGatewayError(error);
372
+ }
57
373
  }
58
374
  async doStream(options) {
59
375
  const { abortSignal, ...body } = options;
60
- const { value: response, responseHeaders } = await postJsonToApi({
61
- url: this.getUrl(),
62
- headers: combineHeaders(
63
- await resolve(this.config.headers()),
64
- options.headers,
65
- this.getModelConfigHeaders(this.modelId, true),
66
- this.config.o11yHeaders
67
- ),
68
- body: this.maybeEncodeFileParts(body),
69
- successfulResponseHandler: createEventSourceResponseHandler(z.any()),
70
- failedResponseHandler: createJsonErrorResponseHandler({
71
- errorSchema: z.any(),
72
- errorToMessage: (data) => data
73
- }),
74
- ...abortSignal && { abortSignal },
75
- fetch: this.config.fetch
76
- });
77
- return {
78
- stream: response.pipeThrough(
79
- new TransformStream({
80
- transform(chunk, controller) {
81
- if (chunk.success) {
82
- controller.enqueue(chunk.value);
83
- } else {
84
- controller.error(
85
- chunk.error
86
- );
376
+ try {
377
+ const { value: response, responseHeaders } = await postJsonToApi({
378
+ url: this.getUrl(),
379
+ headers: combineHeaders(
380
+ await resolve2(this.config.headers()),
381
+ options.headers,
382
+ this.getModelConfigHeaders(this.modelId, true),
383
+ this.config.o11yHeaders
384
+ ),
385
+ body: this.maybeEncodeFileParts(body),
386
+ successfulResponseHandler: createEventSourceResponseHandler(z4.any()),
387
+ failedResponseHandler: createJsonErrorResponseHandler2({
388
+ errorSchema: z4.any(),
389
+ errorToMessage: (data) => data
390
+ }),
391
+ ...abortSignal && { abortSignal },
392
+ fetch: this.config.fetch
393
+ });
394
+ return {
395
+ stream: response.pipeThrough(
396
+ new TransformStream({
397
+ transform(chunk, controller) {
398
+ if (chunk.success) {
399
+ controller.enqueue(chunk.value);
400
+ } else {
401
+ controller.error(
402
+ chunk.error
403
+ );
404
+ }
87
405
  }
88
- }
89
- })
90
- ),
91
- request: { body },
92
- response: { headers: responseHeaders }
93
- };
406
+ })
407
+ ),
408
+ request: { body },
409
+ response: { headers: responseHeaders }
410
+ };
411
+ } catch (error) {
412
+ throw asGatewayError(error);
413
+ }
94
414
  }
95
415
  isFilePart(part) {
96
416
  return part && typeof part === "object" && "type" in part && part.type === "file";
@@ -132,96 +452,44 @@ var GatewayLanguageModel = class {
132
452
 
133
453
  // src/get-vercel-oidc-token.ts
134
454
  async function getVercelOidcToken() {
135
- var _a, _b;
136
- const token = (_b = (_a = getContext().headers) == null ? void 0 : _a["x-vercel-oidc-token"]) != null ? _b : process.env.VERCEL_OIDC_TOKEN;
455
+ var _a8, _b8;
456
+ const token = (_b8 = (_a8 = getContext().headers) == null ? void 0 : _a8["x-vercel-oidc-token"]) != null ? _b8 : process.env.VERCEL_OIDC_TOKEN;
137
457
  if (!token) {
138
- throw new Error(
139
- `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
140
- );
458
+ throw new GatewayAuthenticationError({
459
+ message: `Failed to get Vercel OIDC token for AI Gateway access.
460
+ The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
461
+ - make sure your Vercel project settings have OIDC enabled
462
+ - if you're running locally with 'vercel dev' the token is automatically obtained and refreshed for you
463
+ - if you're running locally with your own dev server script you can fetch/update the token by running 'vercel env pull'
464
+ - in production or preview the token is automatically obtained and refreshed for you`,
465
+ statusCode: 401
466
+ });
141
467
  }
142
468
  return token;
143
469
  }
144
470
  var SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
145
471
  function getContext() {
146
- var _a, _b, _c;
472
+ var _a8, _b8, _c;
147
473
  const fromSymbol = globalThis;
148
- return (_c = (_b = (_a = fromSymbol[SYMBOL_FOR_REQ_CONTEXT]) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a)) != null ? _c : {};
474
+ return (_c = (_b8 = (_a8 = fromSymbol[SYMBOL_FOR_REQ_CONTEXT]) == null ? void 0 : _a8.get) == null ? void 0 : _b8.call(_a8)) != null ? _c : {};
149
475
  }
150
476
 
151
- // src/gateway-fetch-metadata.ts
152
- import {
153
- createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
154
- createJsonResponseHandler as createJsonResponseHandler2,
155
- getFromApi,
156
- resolve as resolve2
157
- } from "@ai-sdk/provider-utils";
158
- import { z as z2 } from "zod";
159
- var GatewayFetchMetadata = class {
160
- constructor(config) {
161
- this.config = config;
162
- }
163
- async getAvailableModels() {
164
- const { value } = await getFromApi({
165
- url: `${this.config.baseURL}/config`,
166
- headers: await resolve2(this.config.headers()),
167
- successfulResponseHandler: createJsonResponseHandler2(
168
- gatewayFetchMetadataSchema
169
- ),
170
- failedResponseHandler: createJsonErrorResponseHandler2({
171
- errorSchema: z2.any(),
172
- errorToMessage: (data) => data
173
- }),
174
- fetch: this.config.fetch
175
- });
176
- return value;
177
- }
178
- };
179
- var gatewayLanguageModelSpecificationSchema = z2.object({
180
- specificationVersion: z2.literal("v2"),
181
- provider: z2.string(),
182
- modelId: z2.string()
183
- });
184
- var gatewayLanguageModelEntrySchema = z2.object({
185
- id: z2.string(),
186
- name: z2.string(),
187
- specification: gatewayLanguageModelSpecificationSchema
188
- });
189
- var gatewayFetchMetadataSchema = z2.object({
190
- models: z2.array(gatewayLanguageModelEntrySchema)
191
- });
192
-
193
477
  // src/gateway-provider.ts
194
478
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
195
479
  async function getGatewayAuthToken(options) {
196
- var _a;
197
- try {
198
- return (_a = loadOptionalSetting({
199
- settingValue: options.apiKey,
200
- environmentVariableName: "AI_GATEWAY_API_KEY"
201
- })) != null ? _a : await getVercelOidcToken();
202
- } catch (error) {
203
- if (error instanceof Error && error.message.includes("'x-vercel-oidc-token' header is missing")) {
204
- const enhancedError = new Error(
205
- `Failed to get Vercel OIDC token for AI Gateway access.
206
- The token is expected to be provided via the 'VERCEL_OIDC_TOKEN' environment variable. It expires every 12 hours.
207
- - make sure your Vercel project settings have OIDC enabled
208
- - if you're running locally with 'vercel dev' the token is automatically obtained and refreshed for you
209
- - if you're running locally with your own dev server script you can fetch/update the token by running 'vercel env pull'
210
- - in production or preview the token is automatically obtained and refreshed for you`
211
- );
212
- enhancedError.cause = error;
213
- throw enhancedError;
214
- }
215
- throw error;
216
- }
480
+ var _a8;
481
+ return (_a8 = loadOptionalSetting({
482
+ settingValue: options.apiKey,
483
+ environmentVariableName: "AI_GATEWAY_API_KEY"
484
+ })) != null ? _a8 : await getVercelOidcToken();
217
485
  }
218
486
  function createGatewayProvider(options = {}) {
219
- var _a, _b;
487
+ var _a8, _b8;
220
488
  let pendingMetadata = null;
221
489
  let metadataCache = null;
222
- const cacheRefreshMillis = (_a = options.metadataCacheRefreshMillis) != null ? _a : 1e3 * 60 * 5;
490
+ const cacheRefreshMillis = (_a8 = options.metadataCacheRefreshMillis) != null ? _a8 : 1e3 * 60 * 5;
223
491
  let lastFetchTime = 0;
224
- const baseURL = (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : "https://ai-gateway.vercel.sh/v1/ai";
492
+ const baseURL = (_b8 = withoutTrailingSlash(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
225
493
  const getHeaders = async () => {
226
494
  return {
227
495
  Authorization: `Bearer ${await getGatewayAuthToken(options)}`,
@@ -255,8 +523,8 @@ function createGatewayProvider(options = {}) {
255
523
  });
256
524
  };
257
525
  const getAvailableModels = async () => {
258
- var _a2, _b2, _c;
259
- const now = (_c = (_b2 = (_a2 = options._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b2.call(_a2).getTime()) != null ? _c : Date.now();
526
+ var _a9, _b9, _c;
527
+ const now = (_c = (_b9 = (_a9 = options._internal) == null ? void 0 : _a9.currentDate) == null ? void 0 : _b9.call(_a9).getTime()) != null ? _c : Date.now();
260
528
  if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
261
529
  lastFetchTime = now;
262
530
  pendingMetadata = new GatewayFetchMetadata({
@@ -266,6 +534,8 @@ function createGatewayProvider(options = {}) {
266
534
  }).getAvailableModels().then((metadata) => {
267
535
  metadataCache = metadata;
268
536
  return metadata;
537
+ }).catch((error) => {
538
+ throw asGatewayError(error);
269
539
  });
270
540
  }
271
541
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
@@ -290,6 +560,13 @@ function createGatewayProvider(options = {}) {
290
560
  }
291
561
  var gateway = createGatewayProvider();
292
562
  export {
563
+ GatewayAuthenticationError,
564
+ GatewayError,
565
+ GatewayInternalServerError,
566
+ GatewayInvalidRequestError,
567
+ GatewayModelNotFoundError,
568
+ GatewayRateLimitError,
569
+ GatewayResponseError,
293
570
  createGatewayProvider,
294
571
  gateway
295
572
  };