@hebo-ai/gateway 0.4.1 → 0.5.0-beta.0

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.
Files changed (62) hide show
  1. package/README.md +2 -3
  2. package/dist/endpoints/chat-completions/converters.d.ts +3 -1
  3. package/dist/endpoints/chat-completions/converters.js +121 -90
  4. package/dist/endpoints/chat-completions/handler.js +2 -4
  5. package/dist/endpoints/chat-completions/otel.js +7 -0
  6. package/dist/endpoints/chat-completions/schema.d.ts +400 -76
  7. package/dist/endpoints/chat-completions/schema.js +80 -36
  8. package/dist/endpoints/embeddings/handler.js +2 -4
  9. package/dist/endpoints/embeddings/schema.d.ts +1 -1
  10. package/dist/endpoints/embeddings/schema.js +1 -1
  11. package/dist/errors/gateway.js +1 -0
  12. package/dist/lifecycle.js +7 -12
  13. package/dist/logger/default.d.ts +0 -1
  14. package/dist/logger/default.js +30 -6
  15. package/dist/middleware/utils.js +1 -0
  16. package/dist/models/amazon/middleware.js +1 -0
  17. package/dist/models/anthropic/middleware.d.ts +2 -0
  18. package/dist/models/anthropic/middleware.js +77 -16
  19. package/dist/models/google/middleware.js +17 -0
  20. package/dist/models/google/presets.d.ts +387 -0
  21. package/dist/models/google/presets.js +9 -2
  22. package/dist/models/openai/middleware.js +1 -0
  23. package/dist/models/types.d.ts +1 -1
  24. package/dist/models/types.js +1 -0
  25. package/dist/providers/bedrock/index.d.ts +1 -0
  26. package/dist/providers/bedrock/index.js +1 -0
  27. package/dist/providers/bedrock/middleware.d.ts +2 -0
  28. package/dist/providers/bedrock/middleware.js +35 -0
  29. package/dist/telemetry/http.js +0 -3
  30. package/dist/types.d.ts +10 -20
  31. package/dist/utils/request.d.ts +1 -3
  32. package/dist/utils/request.js +3 -26
  33. package/dist/utils/response.d.ts +1 -1
  34. package/dist/utils/response.js +3 -3
  35. package/package.json +19 -21
  36. package/src/endpoints/chat-completions/converters.test.ts +219 -0
  37. package/src/endpoints/chat-completions/converters.ts +144 -104
  38. package/src/endpoints/chat-completions/handler.test.ts +87 -0
  39. package/src/endpoints/chat-completions/handler.ts +2 -5
  40. package/src/endpoints/chat-completions/otel.ts +6 -0
  41. package/src/endpoints/chat-completions/schema.ts +85 -43
  42. package/src/endpoints/embeddings/handler.ts +5 -5
  43. package/src/endpoints/embeddings/schema.ts +1 -1
  44. package/src/errors/gateway.ts +2 -0
  45. package/src/lifecycle.ts +7 -11
  46. package/src/logger/default.ts +34 -8
  47. package/src/middleware/utils.ts +1 -0
  48. package/src/models/amazon/middleware.ts +1 -0
  49. package/src/models/anthropic/middleware.test.ts +332 -1
  50. package/src/models/anthropic/middleware.ts +83 -19
  51. package/src/models/google/middleware.test.ts +31 -0
  52. package/src/models/google/middleware.ts +18 -0
  53. package/src/models/google/presets.ts +13 -2
  54. package/src/models/openai/middleware.ts +1 -0
  55. package/src/models/types.ts +1 -0
  56. package/src/providers/bedrock/index.ts +1 -0
  57. package/src/providers/bedrock/middleware.test.ts +73 -0
  58. package/src/providers/bedrock/middleware.ts +43 -0
  59. package/src/telemetry/http.ts +0 -3
  60. package/src/types.ts +19 -23
  61. package/src/utils/request.ts +5 -33
  62. package/src/utils/response.ts +3 -3
@@ -230,6 +230,84 @@ export declare const gemini3ProPreview: <const O extends {
230
230
  context: number;
231
231
  providers: readonly ["vertex"];
232
232
  } & O>;
233
+ export declare const gemini31ProPreview: <const O extends {
234
+ name?: string | undefined;
235
+ created?: string | undefined;
236
+ knowledge?: string | undefined;
237
+ modalities?: {
238
+ input?: readonly ("text" | "file" | "image" | "audio" | "video" | "pdf")[] | undefined;
239
+ output?: readonly ("text" | "embedding" | "image" | "audio" | "video")[] | undefined;
240
+ } | undefined;
241
+ context?: number | undefined;
242
+ capabilities?: readonly ("temperature" | "reasoning" | "attachments" | "tool_call" | "structured_output")[] | undefined;
243
+ providers?: readonly ("anthropic" | "azure" | "bedrock" | "cohere" | "groq" | "openai" | "vertex" | "voyage" | {
244
+ readonly [x: number]: string | undefined;
245
+ toString?: (() => string) | undefined;
246
+ charAt?: {} | undefined;
247
+ charCodeAt?: {} | undefined;
248
+ concat?: {} | undefined;
249
+ indexOf?: {} | undefined;
250
+ lastIndexOf?: {} | undefined;
251
+ localeCompare?: {} | undefined;
252
+ match?: {} | undefined;
253
+ replace?: {} | undefined;
254
+ search?: {} | undefined;
255
+ slice?: {} | undefined;
256
+ split?: {} | undefined;
257
+ substring?: {} | undefined;
258
+ toLowerCase?: (() => string) | undefined;
259
+ toLocaleLowerCase?: {} | undefined;
260
+ toUpperCase?: (() => string) | undefined;
261
+ toLocaleUpperCase?: {} | undefined;
262
+ trim?: (() => string) | undefined;
263
+ readonly length?: number | undefined;
264
+ substr?: {} | undefined;
265
+ valueOf?: (() => string) | undefined;
266
+ codePointAt?: {} | undefined;
267
+ includes?: {} | undefined;
268
+ endsWith?: {} | undefined;
269
+ normalize?: {} | undefined;
270
+ repeat?: {} | undefined;
271
+ startsWith?: {} | undefined;
272
+ anchor?: {} | undefined;
273
+ big?: (() => string) | undefined;
274
+ blink?: (() => string) | undefined;
275
+ bold?: (() => string) | undefined;
276
+ fixed?: (() => string) | undefined;
277
+ fontcolor?: {} | undefined;
278
+ fontsize?: {} | undefined;
279
+ italics?: (() => string) | undefined;
280
+ link?: {} | undefined;
281
+ small?: (() => string) | undefined;
282
+ strike?: (() => string) | undefined;
283
+ sub?: (() => string) | undefined;
284
+ sup?: (() => string) | undefined;
285
+ padStart?: {} | undefined;
286
+ padEnd?: {} | undefined;
287
+ trimEnd?: (() => string) | undefined;
288
+ trimStart?: (() => string) | undefined;
289
+ trimLeft?: (() => string) | undefined;
290
+ trimRight?: (() => string) | undefined;
291
+ matchAll?: {} | undefined;
292
+ replaceAll?: {} | undefined;
293
+ at?: {} | undefined;
294
+ [Symbol.iterator]?: (() => StringIterator<string>) | undefined;
295
+ })[] | undefined;
296
+ additionalProperties?: {
297
+ [x: string]: unknown;
298
+ } | undefined;
299
+ }>(override?: O | undefined) => Record<"google/gemini-3.1-pro-preview", {
300
+ name: string;
301
+ created: string;
302
+ knowledge: string;
303
+ modalities: {
304
+ input: readonly ["text", "image", "pdf", "file", "audio", "video"];
305
+ output: readonly ["text"];
306
+ };
307
+ capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
308
+ context: number;
309
+ providers: readonly ["vertex"];
310
+ } & O>;
233
311
  export declare const gemini25FlashLite: <const O extends {
234
312
  name?: string | undefined;
235
313
  created?: string | undefined;
@@ -851,6 +929,83 @@ export declare const gemini: {
851
929
  capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
852
930
  context: number;
853
931
  providers: readonly ["vertex"];
932
+ } & O>, <const O extends {
933
+ name?: string | undefined;
934
+ created?: string | undefined;
935
+ knowledge?: string | undefined;
936
+ modalities?: {
937
+ input?: readonly ("text" | "file" | "image" | "audio" | "video" | "pdf")[] | undefined;
938
+ output?: readonly ("text" | "embedding" | "image" | "audio" | "video")[] | undefined;
939
+ } | undefined;
940
+ context?: number | undefined;
941
+ capabilities?: readonly ("temperature" | "reasoning" | "attachments" | "tool_call" | "structured_output")[] | undefined;
942
+ providers?: readonly ("anthropic" | "azure" | "bedrock" | "cohere" | "groq" | "openai" | "vertex" | "voyage" | {
943
+ readonly [x: number]: string | undefined;
944
+ toString?: (() => string) | undefined;
945
+ charAt?: {} | undefined;
946
+ charCodeAt?: {} | undefined;
947
+ concat?: {} | undefined;
948
+ indexOf?: {} | undefined;
949
+ lastIndexOf?: {} | undefined;
950
+ localeCompare?: {} | undefined;
951
+ match?: {} | undefined;
952
+ replace?: {} | undefined;
953
+ search?: {} | undefined;
954
+ slice?: {} | undefined;
955
+ split?: {} | undefined;
956
+ substring?: {} | undefined;
957
+ toLowerCase?: (() => string) | undefined;
958
+ toLocaleLowerCase?: {} | undefined;
959
+ toUpperCase?: (() => string) | undefined;
960
+ toLocaleUpperCase?: {} | undefined;
961
+ trim?: (() => string) | undefined;
962
+ readonly length?: number | undefined;
963
+ substr?: {} | undefined;
964
+ valueOf?: (() => string) | undefined;
965
+ codePointAt?: {} | undefined;
966
+ includes?: {} | undefined;
967
+ endsWith?: {} | undefined;
968
+ normalize?: {} | undefined;
969
+ repeat?: {} | undefined;
970
+ startsWith?: {} | undefined;
971
+ anchor?: {} | undefined;
972
+ big?: (() => string) | undefined;
973
+ blink?: (() => string) | undefined;
974
+ bold?: (() => string) | undefined;
975
+ fixed?: (() => string) | undefined;
976
+ fontcolor?: {} | undefined;
977
+ fontsize?: {} | undefined;
978
+ italics?: (() => string) | undefined;
979
+ link?: {} | undefined;
980
+ small?: (() => string) | undefined;
981
+ strike?: (() => string) | undefined;
982
+ sub?: (() => string) | undefined;
983
+ sup?: (() => string) | undefined;
984
+ padStart?: {} | undefined;
985
+ padEnd?: {} | undefined;
986
+ trimEnd?: (() => string) | undefined;
987
+ trimStart?: (() => string) | undefined;
988
+ trimLeft?: (() => string) | undefined;
989
+ trimRight?: (() => string) | undefined;
990
+ matchAll?: {} | undefined;
991
+ replaceAll?: {} | undefined;
992
+ at?: {} | undefined;
993
+ [Symbol.iterator]?: (() => StringIterator<string>) | undefined;
994
+ })[] | undefined;
995
+ additionalProperties?: {
996
+ [x: string]: unknown;
997
+ } | undefined;
998
+ }>(override?: O | undefined) => Record<"google/gemini-3.1-pro-preview", {
999
+ name: string;
1000
+ created: string;
1001
+ knowledge: string;
1002
+ modalities: {
1003
+ input: readonly ["text", "image", "pdf", "file", "audio", "video"];
1004
+ output: readonly ["text"];
1005
+ };
1006
+ capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
1007
+ context: number;
1008
+ providers: readonly ["vertex"];
854
1009
  } & O>];
855
1010
  readonly embeddings: readonly [<const O extends {
856
1011
  name?: string | undefined;
@@ -1223,6 +1378,83 @@ export declare const gemini: {
1223
1378
  additionalProperties?: {
1224
1379
  [x: string]: unknown;
1225
1380
  } | undefined;
1381
+ }>(override?: O | undefined) => Record<"google/gemini-3.1-pro-preview", {
1382
+ name: string;
1383
+ created: string;
1384
+ knowledge: string;
1385
+ modalities: {
1386
+ input: readonly ["text", "image", "pdf", "file", "audio", "video"];
1387
+ output: readonly ["text"];
1388
+ };
1389
+ capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
1390
+ context: number;
1391
+ providers: readonly ["vertex"];
1392
+ } & O>) | (<const O extends {
1393
+ name?: string | undefined;
1394
+ created?: string | undefined;
1395
+ knowledge?: string | undefined;
1396
+ modalities?: {
1397
+ input?: readonly ("text" | "file" | "image" | "audio" | "video" | "pdf")[] | undefined;
1398
+ output?: readonly ("text" | "embedding" | "image" | "audio" | "video")[] | undefined;
1399
+ } | undefined;
1400
+ context?: number | undefined;
1401
+ capabilities?: readonly ("temperature" | "reasoning" | "attachments" | "tool_call" | "structured_output")[] | undefined;
1402
+ providers?: readonly ("anthropic" | "azure" | "bedrock" | "cohere" | "groq" | "openai" | "vertex" | "voyage" | {
1403
+ readonly [x: number]: string | undefined;
1404
+ toString?: (() => string) | undefined;
1405
+ charAt?: {} | undefined;
1406
+ charCodeAt?: {} | undefined;
1407
+ concat?: {} | undefined;
1408
+ indexOf?: {} | undefined;
1409
+ lastIndexOf?: {} | undefined;
1410
+ localeCompare?: {} | undefined;
1411
+ match?: {} | undefined;
1412
+ replace?: {} | undefined;
1413
+ search?: {} | undefined;
1414
+ slice?: {} | undefined;
1415
+ split?: {} | undefined;
1416
+ substring?: {} | undefined;
1417
+ toLowerCase?: (() => string) | undefined;
1418
+ toLocaleLowerCase?: {} | undefined;
1419
+ toUpperCase?: (() => string) | undefined;
1420
+ toLocaleUpperCase?: {} | undefined;
1421
+ trim?: (() => string) | undefined;
1422
+ readonly length?: number | undefined;
1423
+ substr?: {} | undefined;
1424
+ valueOf?: (() => string) | undefined;
1425
+ codePointAt?: {} | undefined;
1426
+ includes?: {} | undefined;
1427
+ endsWith?: {} | undefined;
1428
+ normalize?: {} | undefined;
1429
+ repeat?: {} | undefined;
1430
+ startsWith?: {} | undefined;
1431
+ anchor?: {} | undefined;
1432
+ big?: (() => string) | undefined;
1433
+ blink?: (() => string) | undefined;
1434
+ bold?: (() => string) | undefined;
1435
+ fixed?: (() => string) | undefined;
1436
+ fontcolor?: {} | undefined;
1437
+ fontsize?: {} | undefined;
1438
+ italics?: (() => string) | undefined;
1439
+ link?: {} | undefined;
1440
+ small?: (() => string) | undefined;
1441
+ strike?: (() => string) | undefined;
1442
+ sub?: (() => string) | undefined;
1443
+ sup?: (() => string) | undefined;
1444
+ padStart?: {} | undefined;
1445
+ padEnd?: {} | undefined;
1446
+ trimEnd?: (() => string) | undefined;
1447
+ trimStart?: (() => string) | undefined;
1448
+ trimLeft?: (() => string) | undefined;
1449
+ trimRight?: (() => string) | undefined;
1450
+ matchAll?: {} | undefined;
1451
+ replaceAll?: {} | undefined;
1452
+ at?: {} | undefined;
1453
+ [Symbol.iterator]?: (() => StringIterator<string>) | undefined;
1454
+ })[] | undefined;
1455
+ additionalProperties?: {
1456
+ [x: string]: unknown;
1457
+ } | undefined;
1226
1458
  }>(override?: O | undefined) => Record<"google/gemini-2.5-flash-lite", {
1227
1459
  name: string;
1228
1460
  created: string;
@@ -1775,6 +2007,83 @@ export declare const gemini: {
1775
2007
  capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
1776
2008
  context: number;
1777
2009
  providers: readonly ["vertex"];
2010
+ } & O>, <const O extends {
2011
+ name?: string | undefined;
2012
+ created?: string | undefined;
2013
+ knowledge?: string | undefined;
2014
+ modalities?: {
2015
+ input?: readonly ("text" | "file" | "image" | "audio" | "video" | "pdf")[] | undefined;
2016
+ output?: readonly ("text" | "embedding" | "image" | "audio" | "video")[] | undefined;
2017
+ } | undefined;
2018
+ context?: number | undefined;
2019
+ capabilities?: readonly ("temperature" | "reasoning" | "attachments" | "tool_call" | "structured_output")[] | undefined;
2020
+ providers?: readonly ("anthropic" | "azure" | "bedrock" | "cohere" | "groq" | "openai" | "vertex" | "voyage" | {
2021
+ readonly [x: number]: string | undefined;
2022
+ toString?: (() => string) | undefined;
2023
+ charAt?: {} | undefined;
2024
+ charCodeAt?: {} | undefined;
2025
+ concat?: {} | undefined;
2026
+ indexOf?: {} | undefined;
2027
+ lastIndexOf?: {} | undefined;
2028
+ localeCompare?: {} | undefined;
2029
+ match?: {} | undefined;
2030
+ replace?: {} | undefined;
2031
+ search?: {} | undefined;
2032
+ slice?: {} | undefined;
2033
+ split?: {} | undefined;
2034
+ substring?: {} | undefined;
2035
+ toLowerCase?: (() => string) | undefined;
2036
+ toLocaleLowerCase?: {} | undefined;
2037
+ toUpperCase?: (() => string) | undefined;
2038
+ toLocaleUpperCase?: {} | undefined;
2039
+ trim?: (() => string) | undefined;
2040
+ readonly length?: number | undefined;
2041
+ substr?: {} | undefined;
2042
+ valueOf?: (() => string) | undefined;
2043
+ codePointAt?: {} | undefined;
2044
+ includes?: {} | undefined;
2045
+ endsWith?: {} | undefined;
2046
+ normalize?: {} | undefined;
2047
+ repeat?: {} | undefined;
2048
+ startsWith?: {} | undefined;
2049
+ anchor?: {} | undefined;
2050
+ big?: (() => string) | undefined;
2051
+ blink?: (() => string) | undefined;
2052
+ bold?: (() => string) | undefined;
2053
+ fixed?: (() => string) | undefined;
2054
+ fontcolor?: {} | undefined;
2055
+ fontsize?: {} | undefined;
2056
+ italics?: (() => string) | undefined;
2057
+ link?: {} | undefined;
2058
+ small?: (() => string) | undefined;
2059
+ strike?: (() => string) | undefined;
2060
+ sub?: (() => string) | undefined;
2061
+ sup?: (() => string) | undefined;
2062
+ padStart?: {} | undefined;
2063
+ padEnd?: {} | undefined;
2064
+ trimEnd?: (() => string) | undefined;
2065
+ trimStart?: (() => string) | undefined;
2066
+ trimLeft?: (() => string) | undefined;
2067
+ trimRight?: (() => string) | undefined;
2068
+ matchAll?: {} | undefined;
2069
+ replaceAll?: {} | undefined;
2070
+ at?: {} | undefined;
2071
+ [Symbol.iterator]?: (() => StringIterator<string>) | undefined;
2072
+ })[] | undefined;
2073
+ additionalProperties?: {
2074
+ [x: string]: unknown;
2075
+ } | undefined;
2076
+ }>(override?: O | undefined) => Record<"google/gemini-3.1-pro-preview", {
2077
+ name: string;
2078
+ created: string;
2079
+ knowledge: string;
2080
+ modalities: {
2081
+ input: readonly ["text", "image", "pdf", "file", "audio", "video"];
2082
+ output: readonly ["text"];
2083
+ };
2084
+ capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
2085
+ context: number;
2086
+ providers: readonly ["vertex"];
1778
2087
  } & O>];
1779
2088
  readonly "v2.5": readonly [<const O extends {
1780
2089
  name?: string | undefined;
@@ -2163,4 +2472,82 @@ export declare const gemini: {
2163
2472
  context: number;
2164
2473
  providers: readonly ["vertex"];
2165
2474
  } & O>];
2475
+ readonly "v3.1-preview": readonly [<const O extends {
2476
+ name?: string | undefined;
2477
+ created?: string | undefined;
2478
+ knowledge?: string | undefined;
2479
+ modalities?: {
2480
+ input?: readonly ("text" | "file" | "image" | "audio" | "video" | "pdf")[] | undefined;
2481
+ output?: readonly ("text" | "embedding" | "image" | "audio" | "video")[] | undefined;
2482
+ } | undefined;
2483
+ context?: number | undefined;
2484
+ capabilities?: readonly ("temperature" | "reasoning" | "attachments" | "tool_call" | "structured_output")[] | undefined;
2485
+ providers?: readonly ("anthropic" | "azure" | "bedrock" | "cohere" | "groq" | "openai" | "vertex" | "voyage" | {
2486
+ readonly [x: number]: string | undefined;
2487
+ toString?: (() => string) | undefined;
2488
+ charAt?: {} | undefined;
2489
+ charCodeAt?: {} | undefined;
2490
+ concat?: {} | undefined;
2491
+ indexOf?: {} | undefined;
2492
+ lastIndexOf?: {} | undefined;
2493
+ localeCompare?: {} | undefined;
2494
+ match?: {} | undefined;
2495
+ replace?: {} | undefined;
2496
+ search?: {} | undefined;
2497
+ slice?: {} | undefined;
2498
+ split?: {} | undefined;
2499
+ substring?: {} | undefined;
2500
+ toLowerCase?: (() => string) | undefined;
2501
+ toLocaleLowerCase?: {} | undefined;
2502
+ toUpperCase?: (() => string) | undefined;
2503
+ toLocaleUpperCase?: {} | undefined;
2504
+ trim?: (() => string) | undefined;
2505
+ readonly length?: number | undefined;
2506
+ substr?: {} | undefined;
2507
+ valueOf?: (() => string) | undefined;
2508
+ codePointAt?: {} | undefined;
2509
+ includes?: {} | undefined;
2510
+ endsWith?: {} | undefined;
2511
+ normalize?: {} | undefined;
2512
+ repeat?: {} | undefined;
2513
+ startsWith?: {} | undefined;
2514
+ anchor?: {} | undefined;
2515
+ big?: (() => string) | undefined;
2516
+ blink?: (() => string) | undefined;
2517
+ bold?: (() => string) | undefined;
2518
+ fixed?: (() => string) | undefined;
2519
+ fontcolor?: {} | undefined;
2520
+ fontsize?: {} | undefined;
2521
+ italics?: (() => string) | undefined;
2522
+ link?: {} | undefined;
2523
+ small?: (() => string) | undefined;
2524
+ strike?: (() => string) | undefined;
2525
+ sub?: (() => string) | undefined;
2526
+ sup?: (() => string) | undefined;
2527
+ padStart?: {} | undefined;
2528
+ padEnd?: {} | undefined;
2529
+ trimEnd?: (() => string) | undefined;
2530
+ trimStart?: (() => string) | undefined;
2531
+ trimLeft?: (() => string) | undefined;
2532
+ trimRight?: (() => string) | undefined;
2533
+ matchAll?: {} | undefined;
2534
+ replaceAll?: {} | undefined;
2535
+ at?: {} | undefined;
2536
+ [Symbol.iterator]?: (() => StringIterator<string>) | undefined;
2537
+ })[] | undefined;
2538
+ additionalProperties?: {
2539
+ [x: string]: unknown;
2540
+ } | undefined;
2541
+ }>(override?: O | undefined) => Record<"google/gemini-3.1-pro-preview", {
2542
+ name: string;
2543
+ created: string;
2544
+ knowledge: string;
2545
+ modalities: {
2546
+ input: readonly ["text", "image", "pdf", "file", "audio", "video"];
2547
+ output: readonly ["text"];
2548
+ };
2549
+ capabilities: readonly ["attachments", "reasoning", "tool_call", "structured_output", "temperature"];
2550
+ context: number;
2551
+ providers: readonly ["vertex"];
2552
+ } & O>];
2166
2553
  };
@@ -39,6 +39,12 @@ export const gemini3ProPreview = presetFor()("google/gemini-3-pro-preview", {
39
39
  created: "2025-11-18",
40
40
  knowledge: "2025-01",
41
41
  });
42
+ export const gemini31ProPreview = presetFor()("google/gemini-3.1-pro-preview", {
43
+ ...GEMINI_BASE,
44
+ name: "Gemini 3.1 Pro (Preview)",
45
+ created: "2026-02-19",
46
+ knowledge: "2025-01",
47
+ });
42
48
  export const gemini25FlashLite = presetFor()("google/gemini-2.5-flash-lite", {
43
49
  ...GEMINI_BASE,
44
50
  name: "Gemini 2.5 Flash Lite",
@@ -60,17 +66,18 @@ export const gemini25Pro = presetFor()("google/gemini-2.5-pro", {
60
66
  const geminiAtomic = {
61
67
  "v2.5": [gemini25FlashLite, gemini25Flash, gemini25Pro],
62
68
  "v3-preview": [gemini3FlashPreview, gemini3ProPreview],
69
+ "v3.1-preview": [gemini31ProPreview],
63
70
  embeddings: [geminiEmbedding001],
64
71
  };
65
72
  const geminiGroups = {
66
73
  "v2.x": [...geminiAtomic["v2.5"]],
67
- "v3.x": [...geminiAtomic["v3-preview"]],
74
+ "v3.x": [...geminiAtomic["v3-preview"], ...geminiAtomic["v3.1-preview"]],
68
75
  };
69
76
  export const gemini = {
70
77
  ...geminiAtomic,
71
78
  ...geminiGroups,
72
79
  latest: [...geminiAtomic["v2.5"]],
73
- preview: [...geminiAtomic["v3-preview"]],
80
+ preview: [...geminiAtomic["v3-preview"], ...geminiAtomic["v3.1-preview"]],
74
81
  embeddings: [...geminiAtomic["embeddings"]],
75
82
  all: Object.values(geminiAtomic).flat(),
76
83
  };
@@ -21,6 +21,7 @@ function mapGptOssReasoningEffort(effort) {
21
21
  return "medium";
22
22
  case "high":
23
23
  case "xhigh":
24
+ case "max":
24
25
  return "high";
25
26
  default:
26
27
  return "low";
@@ -1,5 +1,5 @@
1
1
  import type { ProviderId } from "../providers/types";
2
- export declare const CANONICAL_MODEL_IDS: readonly ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "anthropic/claude-haiku-4.5", "anthropic/claude-sonnet-4.5", "anthropic/claude-opus-4.5", "anthropic/claude-opus-4.1", "anthropic/claude-opus-4", "anthropic/claude-sonnet-4", "anthropic/claude-sonnet-3.7", "anthropic/claude-sonnet-3.5", "anthropic/claude-haiku-3.5", "anthropic/claude-haiku-3", "openai/gpt-oss-20b", "openai/gpt-oss-120b", "openai/gpt-5", "openai/gpt-5-pro", "openai/gpt-5.2", "openai/gpt-5.2-chat", "openai/gpt-5.2-pro", "openai/gpt-5.2-codex", "openai/gpt-5.3-codex", "openai/gpt-5-mini", "openai/gpt-5-nano", "openai/gpt-5-codex", "openai/gpt-5.1-codex", "openai/gpt-5.1-codex-max", "openai/gpt-5.1-chat", "openai/gpt-5.1", "openai/text-embedding-3-small", "openai/text-embedding-3-large", "amazon/nova-micro", "amazon/nova-lite", "amazon/nova-pro", "amazon/nova-premier", "amazon/nova-2-lite", "amazon/nova-2-multimodal-embeddings", "google/gemini-2.5-flash-lite", "google/gemini-2.5-flash", "google/gemini-2.5-pro", "google/gemini-3-flash-preview", "google/gemini-3-pro-preview", "google/embedding-001", "meta/llama-3.1-8b", "meta/llama-3.1-70b", "meta/llama-3.1-405b", "meta/llama-3.2-1b", "meta/llama-3.2-3b", "meta/llama-3.2-11b", "meta/llama-3.2-90b", "meta/llama-3.3-70b", "meta/llama-4-scout", "meta/llama-4-maverick", "cohere/embed-v4.0", "cohere/embed-english-v3.0", "cohere/embed-english-light-v3.0", "cohere/embed-multilingual-v3.0", "cohere/embed-multilingual-light-v3.0", "cohere/command-a", "cohere/command-r7b", "cohere/command-a-translate", "cohere/command-a-reasoning", "cohere/command-a-vision", "cohere/command-r", "cohere/command-r-plus", "voyage/voyage-2-code", "voyage/voyage-2-law", "voyage/voyage-2-finance", "voyage/voyage-3-code", "voyage/voyage-3-large", "voyage/voyage-3.5-lite", "voyage/voyage-3.5", "voyage/voyage-4-lite", "voyage/voyage-4", "voyage/voyage-4-large"];
2
+ export declare const CANONICAL_MODEL_IDS: readonly ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "anthropic/claude-haiku-4.5", "anthropic/claude-sonnet-4.5", "anthropic/claude-opus-4.5", "anthropic/claude-opus-4.1", "anthropic/claude-opus-4", "anthropic/claude-sonnet-4", "anthropic/claude-sonnet-3.7", "anthropic/claude-sonnet-3.5", "anthropic/claude-haiku-3.5", "anthropic/claude-haiku-3", "openai/gpt-oss-20b", "openai/gpt-oss-120b", "openai/gpt-5", "openai/gpt-5-pro", "openai/gpt-5.2", "openai/gpt-5.2-chat", "openai/gpt-5.2-pro", "openai/gpt-5.2-codex", "openai/gpt-5.3-codex", "openai/gpt-5-mini", "openai/gpt-5-nano", "openai/gpt-5-codex", "openai/gpt-5.1-codex", "openai/gpt-5.1-codex-max", "openai/gpt-5.1-chat", "openai/gpt-5.1", "openai/text-embedding-3-small", "openai/text-embedding-3-large", "amazon/nova-micro", "amazon/nova-lite", "amazon/nova-pro", "amazon/nova-premier", "amazon/nova-2-lite", "amazon/nova-2-multimodal-embeddings", "google/gemini-2.5-flash-lite", "google/gemini-2.5-flash", "google/gemini-2.5-pro", "google/gemini-3-flash-preview", "google/gemini-3-pro-preview", "google/gemini-3.1-pro-preview", "google/embedding-001", "meta/llama-3.1-8b", "meta/llama-3.1-70b", "meta/llama-3.1-405b", "meta/llama-3.2-1b", "meta/llama-3.2-3b", "meta/llama-3.2-11b", "meta/llama-3.2-90b", "meta/llama-3.3-70b", "meta/llama-4-scout", "meta/llama-4-maverick", "cohere/embed-v4.0", "cohere/embed-english-v3.0", "cohere/embed-english-light-v3.0", "cohere/embed-multilingual-v3.0", "cohere/embed-multilingual-light-v3.0", "cohere/command-a", "cohere/command-r7b", "cohere/command-a-translate", "cohere/command-a-reasoning", "cohere/command-a-vision", "cohere/command-r", "cohere/command-r-plus", "voyage/voyage-2-code", "voyage/voyage-2-law", "voyage/voyage-2-finance", "voyage/voyage-3-code", "voyage/voyage-3-large", "voyage/voyage-3.5-lite", "voyage/voyage-3.5", "voyage/voyage-4-lite", "voyage/voyage-4", "voyage/voyage-4-large"];
3
3
  export type CanonicalModelId = (typeof CANONICAL_MODEL_IDS)[number];
4
4
  export type ModelId = CanonicalModelId | (string & {});
5
5
  export type CatalogModel = {
@@ -44,6 +44,7 @@ export const CANONICAL_MODEL_IDS = [
44
44
  "google/gemini-2.5-pro",
45
45
  "google/gemini-3-flash-preview",
46
46
  "google/gemini-3-pro-preview",
47
+ "google/gemini-3.1-pro-preview",
47
48
  "google/embedding-001",
48
49
  // Meta
49
50
  "meta/llama-3.1-8b",
@@ -1 +1,2 @@
1
1
  export * from "./canonical";
2
+ export * from "./middleware";
@@ -1 +1,2 @@
1
1
  export * from "./canonical";
2
+ export * from "./middleware";
@@ -0,0 +1,2 @@
1
+ import type { LanguageModelMiddleware } from "ai";
2
+ export declare const bedrockAnthropicReasoningMiddleware: LanguageModelMiddleware;
@@ -0,0 +1,35 @@
1
+ import { modelMiddlewareMatcher } from "../../middleware/matcher";
2
+ export const bedrockAnthropicReasoningMiddleware = {
3
+ specificationVersion: "v3",
4
+ // eslint-disable-next-line require-await
5
+ transformParams: async ({ params, model }) => {
6
+ if (!model.modelId.includes("claude"))
7
+ return params;
8
+ const bedrock = params.providerOptions?.["bedrock"];
9
+ if (!bedrock || typeof bedrock !== "object")
10
+ return params;
11
+ const bedrockOptions = bedrock;
12
+ const thinking = bedrockOptions["thinking"];
13
+ const effort = bedrockOptions["effort"];
14
+ if (!thinking && effort === undefined)
15
+ return params;
16
+ const target = (bedrockOptions["reasoningConfig"] ??= {});
17
+ if (thinking && typeof thinking === "object") {
18
+ const thinkingOptions = thinking;
19
+ if (thinkingOptions["type"] !== undefined) {
20
+ target["type"] = thinkingOptions["type"];
21
+ }
22
+ if (thinkingOptions["budgetTokens"] !== undefined) {
23
+ target["budgetTokens"] = thinkingOptions["budgetTokens"];
24
+ }
25
+ }
26
+ if (effort !== undefined)
27
+ target["maxReasoningEffort"] = effort;
28
+ delete bedrockOptions["thinking"];
29
+ delete bedrockOptions["effort"];
30
+ return params;
31
+ },
32
+ };
33
+ modelMiddlewareMatcher.useForProvider("amazon-bedrock", {
34
+ language: [bedrockAnthropicReasoningMiddleware],
35
+ });
@@ -1,5 +1,4 @@
1
1
  import {} from "../types";
2
- import { resolveRequestId } from "../utils/headers";
3
2
  const headerArr = (h, k) => (h.has(k) ? [h.get(k)] : undefined);
4
3
  export const getRequestAttributes = (request, signalLevel) => {
5
4
  if (!signalLevel || signalLevel === "off")
@@ -26,8 +25,6 @@ export const getRequestAttributes = (request, signalLevel) => {
26
25
  };
27
26
  if (signalLevel !== "required") {
28
27
  Object.assign(attrs, {
29
- // FUTURE: does ElysiaJS and other frameworks attach request id?
30
- "http.request.id": resolveRequestId(request),
31
28
  "user_agent.original": request.headers.get("user-agent") ?? undefined,
32
29
  });
33
30
  }
package/dist/types.d.ts CHANGED
@@ -6,19 +6,6 @@ import type { Model, ModelList } from "./endpoints/models";
6
6
  import type { Logger, LoggerConfig } from "./logger";
7
7
  import type { ModelCatalog, ModelId } from "./models/types";
8
8
  import type { ProviderId, ProviderRegistry } from "./providers/types";
9
- /**
10
- * Request overrides returned from the `onRequest` hook.
11
- */
12
- export type RequestPatch = {
13
- /**
14
- * Headers to merge into the incoming request.
15
- */
16
- headers?: HeadersInit;
17
- /**
18
- * Body to replace on the incoming request.
19
- */
20
- body?: BodyInit;
21
- };
22
9
  /**
23
10
  * Per-request context shared across handlers and hooks.
24
11
  */
@@ -39,6 +26,10 @@ export type GatewayContext = {
39
26
  * Incoming request for the handler.
40
27
  */
41
28
  request: Request;
29
+ /**
30
+ * Resolved request ID for logging and telemetry.
31
+ */
32
+ requestId: string;
42
33
  /**
43
34
  * Parsed body from the request.
44
35
  */
@@ -80,10 +71,10 @@ export type HookContext = Omit<Readonly<GatewayContext>, "state"> & {
80
71
  };
81
72
  type RequiredHookContext<K extends keyof GatewayContext> = Omit<HookContext, K> & Required<Pick<HookContext, K>>;
82
73
  export type OnRequestHookContext = RequiredHookContext<"request">;
83
- export type BeforeHookContext = RequiredHookContext<"request" | "body" | "operation">;
84
- export type ResolveModelHookContext = RequiredHookContext<"request" | "body" | "modelId">;
85
- export type ResolveProviderHookContext = RequiredHookContext<"request" | "body" | "modelId" | "resolvedModelId" | "operation">;
86
- export type AfterHookContext = RequiredHookContext<"request" | "result" | "provider" | "resolvedModelId" | "operation">;
74
+ export type BeforeHookContext = RequiredHookContext<"request" | "operation" | "body">;
75
+ export type ResolveModelHookContext = RequiredHookContext<"request" | "operation" | "body" | "modelId">;
76
+ export type ResolveProviderHookContext = RequiredHookContext<"request" | "operation" | "body" | "modelId" | "resolvedModelId">;
77
+ export type AfterHookContext = RequiredHookContext<"request" | "operation" | "body" | "modelId" | "resolvedModelId" | "provider" | "resolvedProviderId" | "result">;
87
78
  export type OnResponseHookContext = RequiredHookContext<"request" | "response">;
88
79
  /**
89
80
  * Hooks to plugin to the gateway lifecycle.
@@ -91,10 +82,9 @@ export type OnResponseHookContext = RequiredHookContext<"request" | "response">;
91
82
  export type GatewayHooks = {
92
83
  /**
93
84
  * Runs before any endpoint handler logic.
94
- * @returns Optional RequestPatch to merge into headers / override body,
95
- * or Response to short-circuit the request.
85
+ * @returns Optional Response to short-circuit the request.
96
86
  */
97
- onRequest?: (ctx: OnRequestHookContext) => void | RequestPatch | Response | Promise<void | RequestPatch | Response>;
87
+ onRequest?: (ctx: OnRequestHookContext) => void | Response | Promise<void | Response>;
98
88
  /**
99
89
  * Runs after request JSON is parsed and validated for chat completions / embeddings.
100
90
  * @returns Replacement parsed body, or undefined to keep original.
@@ -1,4 +1,2 @@
1
- import type { RequestPatch } from "../types";
2
- export declare const prepareRequestHeaders: (request: Request) => Headers | undefined;
1
+ export declare const resolveOrCreateRequestId: (request: Request) => string;
3
2
  export declare const prepareForwardHeaders: (request: Request) => Record<string, string>;
4
- export declare const maybeApplyRequestPatch: (request: Request, patch: RequestPatch) => Request;
@@ -1,15 +1,8 @@
1
1
  import pkg from "../../package.json" with { type: "json" };
2
- import { REQUEST_ID_HEADER } from "./headers";
2
+ import { resolveRequestId } from "./headers";
3
3
  const GATEWAY_VERSION = pkg.version;
4
- export const prepareRequestHeaders = (request) => {
5
- const existingRequestId = request.headers.get(REQUEST_ID_HEADER);
6
- if (existingRequestId)
7
- return;
8
- const requestId = "req_" + crypto.getRandomValues(new Uint32Array(2)).reduce((s, n) => s + n.toString(36), "");
9
- const headers = new Headers(request.headers);
10
- headers.set(REQUEST_ID_HEADER, requestId);
11
- return headers;
12
- };
4
+ const createRequestId = () => "req_" + crypto.getRandomValues(new Uint32Array(2)).reduce((s, n) => s + n.toString(36), "");
5
+ export const resolveOrCreateRequestId = (request) => resolveRequestId(request) ?? createRequestId();
13
6
  export const prepareForwardHeaders = (request) => {
14
7
  const userAgent = request.headers.get("user-agent");
15
8
  const appendedUserAgent = userAgent
@@ -19,19 +12,3 @@ export const prepareForwardHeaders = (request) => {
19
12
  "user-agent": appendedUserAgent,
20
13
  };
21
14
  };
22
- export const maybeApplyRequestPatch = (request, patch) => {
23
- if (!patch.headers && patch.body === undefined)
24
- return request;
25
- if (!patch.headers) {
26
- // eslint-disable-next-line no-invalid-fetch-options
27
- return new Request(request, { body: patch.body });
28
- }
29
- const headers = new Headers(request.headers);
30
- for (const [key, value] of new Headers(patch.headers)) {
31
- headers.set(key, value);
32
- }
33
- const init = { headers };
34
- if (patch.body !== undefined)
35
- init.body = patch.body;
36
- return new Request(request, init);
37
- };