floe-guard 0.5.0 → 0.7.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.
- package/dist/index.cjs +256 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +254 -85
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cost_map.json +216 -84
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,8 @@ __export(index_exports, {
|
|
|
29
29
|
budgetGuardMiddleware: () => budgetGuardMiddleware,
|
|
30
30
|
priceTokens: () => priceTokens,
|
|
31
31
|
pricing: () => pricing_exports,
|
|
32
|
-
resolvePrice: () => resolvePrice
|
|
32
|
+
resolvePrice: () => resolvePrice,
|
|
33
|
+
withBudgetRetry: () => withBudgetRetry
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(index_exports);
|
|
35
36
|
|
|
@@ -304,6 +305,222 @@ var cost_map_default = {
|
|
|
304
305
|
litellm_provider: "openai",
|
|
305
306
|
mode: "chat"
|
|
306
307
|
},
|
|
308
|
+
"gemini-2.0-flash": {
|
|
309
|
+
input_cost_per_token: 1e-7,
|
|
310
|
+
output_cost_per_token: 4e-7,
|
|
311
|
+
litellm_provider: "gemini",
|
|
312
|
+
mode: "chat"
|
|
313
|
+
},
|
|
314
|
+
"gemini-2.0-flash-001": {
|
|
315
|
+
input_cost_per_token: 1e-7,
|
|
316
|
+
output_cost_per_token: 4e-7,
|
|
317
|
+
litellm_provider: "gemini",
|
|
318
|
+
mode: "chat"
|
|
319
|
+
},
|
|
320
|
+
"gemini-2.0-flash-lite": {
|
|
321
|
+
input_cost_per_token: 75e-9,
|
|
322
|
+
output_cost_per_token: 3e-7,
|
|
323
|
+
litellm_provider: "gemini",
|
|
324
|
+
mode: "chat"
|
|
325
|
+
},
|
|
326
|
+
"gemini-2.0-flash-lite-001": {
|
|
327
|
+
input_cost_per_token: 75e-9,
|
|
328
|
+
output_cost_per_token: 3e-7,
|
|
329
|
+
litellm_provider: "gemini",
|
|
330
|
+
mode: "chat"
|
|
331
|
+
},
|
|
332
|
+
"gemini-2.5-computer-use-preview-10-2025": {
|
|
333
|
+
input_cost_per_token: 125e-8,
|
|
334
|
+
output_cost_per_token: 1e-5,
|
|
335
|
+
litellm_provider: "gemini",
|
|
336
|
+
mode: "chat"
|
|
337
|
+
},
|
|
338
|
+
"gemini-2.5-flash": {
|
|
339
|
+
input_cost_per_token: 3e-7,
|
|
340
|
+
output_cost_per_token: 25e-7,
|
|
341
|
+
litellm_provider: "gemini",
|
|
342
|
+
mode: "chat"
|
|
343
|
+
},
|
|
344
|
+
"gemini-2.5-flash-lite": {
|
|
345
|
+
input_cost_per_token: 1e-7,
|
|
346
|
+
output_cost_per_token: 4e-7,
|
|
347
|
+
litellm_provider: "gemini",
|
|
348
|
+
mode: "chat"
|
|
349
|
+
},
|
|
350
|
+
"gemini-2.5-flash-lite-preview-06-17": {
|
|
351
|
+
input_cost_per_token: 1e-7,
|
|
352
|
+
output_cost_per_token: 4e-7,
|
|
353
|
+
litellm_provider: "gemini",
|
|
354
|
+
mode: "chat"
|
|
355
|
+
},
|
|
356
|
+
"gemini-2.5-flash-lite-preview-09-2025": {
|
|
357
|
+
input_cost_per_token: 1e-7,
|
|
358
|
+
output_cost_per_token: 4e-7,
|
|
359
|
+
litellm_provider: "gemini",
|
|
360
|
+
mode: "chat"
|
|
361
|
+
},
|
|
362
|
+
"gemini-2.5-flash-native-audio-latest": {
|
|
363
|
+
input_cost_per_token: 3e-7,
|
|
364
|
+
output_cost_per_token: 25e-7,
|
|
365
|
+
litellm_provider: "gemini",
|
|
366
|
+
mode: "chat"
|
|
367
|
+
},
|
|
368
|
+
"gemini-2.5-flash-native-audio-preview-09-2025": {
|
|
369
|
+
input_cost_per_token: 3e-7,
|
|
370
|
+
output_cost_per_token: 25e-7,
|
|
371
|
+
litellm_provider: "gemini",
|
|
372
|
+
mode: "chat"
|
|
373
|
+
},
|
|
374
|
+
"gemini-2.5-flash-native-audio-preview-12-2025": {
|
|
375
|
+
input_cost_per_token: 3e-7,
|
|
376
|
+
output_cost_per_token: 25e-7,
|
|
377
|
+
litellm_provider: "gemini",
|
|
378
|
+
mode: "chat"
|
|
379
|
+
},
|
|
380
|
+
"gemini-2.5-flash-preview-09-2025": {
|
|
381
|
+
input_cost_per_token: 3e-7,
|
|
382
|
+
output_cost_per_token: 25e-7,
|
|
383
|
+
litellm_provider: "gemini",
|
|
384
|
+
mode: "chat"
|
|
385
|
+
},
|
|
386
|
+
"gemini-2.5-pro": {
|
|
387
|
+
input_cost_per_token: 125e-8,
|
|
388
|
+
output_cost_per_token: 1e-5,
|
|
389
|
+
litellm_provider: "gemini",
|
|
390
|
+
mode: "chat"
|
|
391
|
+
},
|
|
392
|
+
"gemini-2.5-pro-preview-tts": {
|
|
393
|
+
input_cost_per_token: 125e-8,
|
|
394
|
+
output_cost_per_token: 1e-5,
|
|
395
|
+
litellm_provider: "gemini",
|
|
396
|
+
mode: "chat"
|
|
397
|
+
},
|
|
398
|
+
"gemini-3-flash-preview": {
|
|
399
|
+
input_cost_per_token: 5e-7,
|
|
400
|
+
output_cost_per_token: 3e-6,
|
|
401
|
+
litellm_provider: "gemini",
|
|
402
|
+
mode: "chat"
|
|
403
|
+
},
|
|
404
|
+
"gemini-3-pro-preview": {
|
|
405
|
+
input_cost_per_token: 2e-6,
|
|
406
|
+
output_cost_per_token: 12e-6,
|
|
407
|
+
litellm_provider: "gemini",
|
|
408
|
+
mode: "chat"
|
|
409
|
+
},
|
|
410
|
+
"gemini-3.1-flash-lite": {
|
|
411
|
+
input_cost_per_token: 25e-8,
|
|
412
|
+
output_cost_per_token: 15e-7,
|
|
413
|
+
litellm_provider: "gemini",
|
|
414
|
+
mode: "chat"
|
|
415
|
+
},
|
|
416
|
+
"gemini-3.1-flash-lite-preview": {
|
|
417
|
+
input_cost_per_token: 25e-8,
|
|
418
|
+
output_cost_per_token: 15e-7,
|
|
419
|
+
litellm_provider: "gemini",
|
|
420
|
+
mode: "chat"
|
|
421
|
+
},
|
|
422
|
+
"gemini-3.1-flash-live-preview": {
|
|
423
|
+
input_cost_per_token: 75e-8,
|
|
424
|
+
output_cost_per_token: 45e-7,
|
|
425
|
+
litellm_provider: "gemini",
|
|
426
|
+
mode: "chat"
|
|
427
|
+
},
|
|
428
|
+
"gemini-3.1-pro-preview": {
|
|
429
|
+
input_cost_per_token: 2e-6,
|
|
430
|
+
output_cost_per_token: 12e-6,
|
|
431
|
+
litellm_provider: "gemini",
|
|
432
|
+
mode: "chat"
|
|
433
|
+
},
|
|
434
|
+
"gemini-3.1-pro-preview-customtools": {
|
|
435
|
+
input_cost_per_token: 2e-6,
|
|
436
|
+
output_cost_per_token: 12e-6,
|
|
437
|
+
litellm_provider: "gemini",
|
|
438
|
+
mode: "chat"
|
|
439
|
+
},
|
|
440
|
+
"gemini-3.5-flash": {
|
|
441
|
+
input_cost_per_token: 15e-7,
|
|
442
|
+
output_cost_per_token: 9e-6,
|
|
443
|
+
litellm_provider: "gemini",
|
|
444
|
+
mode: "chat"
|
|
445
|
+
},
|
|
446
|
+
"gemini-3.5-flash-lite": {
|
|
447
|
+
input_cost_per_token: 3e-7,
|
|
448
|
+
output_cost_per_token: 25e-7,
|
|
449
|
+
litellm_provider: "gemini",
|
|
450
|
+
mode: "chat"
|
|
451
|
+
},
|
|
452
|
+
"gemini-3.6-flash": {
|
|
453
|
+
input_cost_per_token: 15e-7,
|
|
454
|
+
output_cost_per_token: 75e-7,
|
|
455
|
+
litellm_provider: "gemini",
|
|
456
|
+
mode: "chat"
|
|
457
|
+
},
|
|
458
|
+
"gemini-embedding-001": {
|
|
459
|
+
input_cost_per_token: 15e-8,
|
|
460
|
+
output_cost_per_token: 0,
|
|
461
|
+
litellm_provider: "gemini",
|
|
462
|
+
mode: "embedding"
|
|
463
|
+
},
|
|
464
|
+
"gemini-embedding-2": {
|
|
465
|
+
input_cost_per_token: 2e-7,
|
|
466
|
+
output_cost_per_token: 0,
|
|
467
|
+
litellm_provider: "gemini",
|
|
468
|
+
mode: "embedding"
|
|
469
|
+
},
|
|
470
|
+
"gemini-embedding-2-preview": {
|
|
471
|
+
input_cost_per_token: 2e-7,
|
|
472
|
+
output_cost_per_token: 0,
|
|
473
|
+
litellm_provider: "gemini",
|
|
474
|
+
mode: "embedding"
|
|
475
|
+
},
|
|
476
|
+
"gemini-exp-1206": {
|
|
477
|
+
input_cost_per_token: 3e-7,
|
|
478
|
+
output_cost_per_token: 25e-7,
|
|
479
|
+
litellm_provider: "gemini",
|
|
480
|
+
mode: "chat"
|
|
481
|
+
},
|
|
482
|
+
"gemini-flash-latest": {
|
|
483
|
+
input_cost_per_token: 3e-7,
|
|
484
|
+
output_cost_per_token: 25e-7,
|
|
485
|
+
litellm_provider: "gemini",
|
|
486
|
+
mode: "chat"
|
|
487
|
+
},
|
|
488
|
+
"gemini-flash-lite-latest": {
|
|
489
|
+
input_cost_per_token: 1e-7,
|
|
490
|
+
output_cost_per_token: 4e-7,
|
|
491
|
+
litellm_provider: "gemini",
|
|
492
|
+
mode: "chat"
|
|
493
|
+
},
|
|
494
|
+
"gemini-gemma-2-27b-it": {
|
|
495
|
+
input_cost_per_token: 35e-8,
|
|
496
|
+
output_cost_per_token: 105e-8,
|
|
497
|
+
litellm_provider: "gemini",
|
|
498
|
+
mode: "chat"
|
|
499
|
+
},
|
|
500
|
+
"gemini-gemma-2-9b-it": {
|
|
501
|
+
input_cost_per_token: 35e-8,
|
|
502
|
+
output_cost_per_token: 105e-8,
|
|
503
|
+
litellm_provider: "gemini",
|
|
504
|
+
mode: "chat"
|
|
505
|
+
},
|
|
506
|
+
"gemini-omni-flash-preview": {
|
|
507
|
+
input_cost_per_token: 15e-7,
|
|
508
|
+
output_cost_per_token: 9e-6,
|
|
509
|
+
litellm_provider: "gemini",
|
|
510
|
+
mode: "chat"
|
|
511
|
+
},
|
|
512
|
+
"gemini-pro-latest": {
|
|
513
|
+
input_cost_per_token: 125e-8,
|
|
514
|
+
output_cost_per_token: 1e-5,
|
|
515
|
+
litellm_provider: "gemini",
|
|
516
|
+
mode: "chat"
|
|
517
|
+
},
|
|
518
|
+
"gemini-robotics-er-1.5-preview": {
|
|
519
|
+
input_cost_per_token: 3e-7,
|
|
520
|
+
output_cost_per_token: 25e-7,
|
|
521
|
+
litellm_provider: "gemini",
|
|
522
|
+
mode: "chat"
|
|
523
|
+
},
|
|
307
524
|
"gpt-3.5-turbo": {
|
|
308
525
|
input_cost_per_token: 5e-7,
|
|
309
526
|
output_cost_per_token: 15e-7,
|
|
@@ -478,18 +695,6 @@ var cost_map_default = {
|
|
|
478
695
|
litellm_provider: "openai",
|
|
479
696
|
mode: "chat"
|
|
480
697
|
},
|
|
481
|
-
"gpt-4o-mini-realtime-preview": {
|
|
482
|
-
input_cost_per_token: 6e-7,
|
|
483
|
-
output_cost_per_token: 24e-7,
|
|
484
|
-
litellm_provider: "openai",
|
|
485
|
-
mode: "chat"
|
|
486
|
-
},
|
|
487
|
-
"gpt-4o-mini-realtime-preview-2024-12-17": {
|
|
488
|
-
input_cost_per_token: 6e-7,
|
|
489
|
-
output_cost_per_token: 24e-7,
|
|
490
|
-
litellm_provider: "openai",
|
|
491
|
-
mode: "chat"
|
|
492
|
-
},
|
|
493
698
|
"gpt-4o-mini-search-preview": {
|
|
494
699
|
input_cost_per_token: 15e-8,
|
|
495
700
|
output_cost_per_token: 6e-7,
|
|
@@ -502,24 +707,6 @@ var cost_map_default = {
|
|
|
502
707
|
litellm_provider: "openai",
|
|
503
708
|
mode: "chat"
|
|
504
709
|
},
|
|
505
|
-
"gpt-4o-realtime-preview": {
|
|
506
|
-
input_cost_per_token: 5e-6,
|
|
507
|
-
output_cost_per_token: 2e-5,
|
|
508
|
-
litellm_provider: "openai",
|
|
509
|
-
mode: "chat"
|
|
510
|
-
},
|
|
511
|
-
"gpt-4o-realtime-preview-2024-12-17": {
|
|
512
|
-
input_cost_per_token: 5e-6,
|
|
513
|
-
output_cost_per_token: 2e-5,
|
|
514
|
-
litellm_provider: "openai",
|
|
515
|
-
mode: "chat"
|
|
516
|
-
},
|
|
517
|
-
"gpt-4o-realtime-preview-2025-06-03": {
|
|
518
|
-
input_cost_per_token: 5e-6,
|
|
519
|
-
output_cost_per_token: 2e-5,
|
|
520
|
-
litellm_provider: "openai",
|
|
521
|
-
mode: "chat"
|
|
522
|
-
},
|
|
523
710
|
"gpt-4o-search-preview": {
|
|
524
711
|
input_cost_per_token: 25e-7,
|
|
525
712
|
output_cost_per_token: 1e-5,
|
|
@@ -742,60 +929,6 @@ var cost_map_default = {
|
|
|
742
929
|
litellm_provider: "openai",
|
|
743
930
|
mode: "chat"
|
|
744
931
|
},
|
|
745
|
-
"gpt-realtime": {
|
|
746
|
-
input_cost_per_token: 4e-6,
|
|
747
|
-
output_cost_per_token: 16e-6,
|
|
748
|
-
litellm_provider: "openai",
|
|
749
|
-
mode: "chat"
|
|
750
|
-
},
|
|
751
|
-
"gpt-realtime-1.5": {
|
|
752
|
-
input_cost_per_token: 4e-6,
|
|
753
|
-
output_cost_per_token: 16e-6,
|
|
754
|
-
litellm_provider: "openai",
|
|
755
|
-
mode: "chat"
|
|
756
|
-
},
|
|
757
|
-
"gpt-realtime-2": {
|
|
758
|
-
input_cost_per_token: 4e-6,
|
|
759
|
-
output_cost_per_token: 16e-6,
|
|
760
|
-
litellm_provider: "openai",
|
|
761
|
-
mode: "chat"
|
|
762
|
-
},
|
|
763
|
-
"gpt-realtime-2.1": {
|
|
764
|
-
input_cost_per_token: 4e-6,
|
|
765
|
-
output_cost_per_token: 24e-6,
|
|
766
|
-
litellm_provider: "openai",
|
|
767
|
-
mode: "chat"
|
|
768
|
-
},
|
|
769
|
-
"gpt-realtime-2.1-mini": {
|
|
770
|
-
input_cost_per_token: 6e-7,
|
|
771
|
-
output_cost_per_token: 24e-7,
|
|
772
|
-
litellm_provider: "openai",
|
|
773
|
-
mode: "chat"
|
|
774
|
-
},
|
|
775
|
-
"gpt-realtime-2025-08-28": {
|
|
776
|
-
input_cost_per_token: 4e-6,
|
|
777
|
-
output_cost_per_token: 16e-6,
|
|
778
|
-
litellm_provider: "openai",
|
|
779
|
-
mode: "chat"
|
|
780
|
-
},
|
|
781
|
-
"gpt-realtime-mini": {
|
|
782
|
-
input_cost_per_token: 6e-7,
|
|
783
|
-
output_cost_per_token: 24e-7,
|
|
784
|
-
litellm_provider: "openai",
|
|
785
|
-
mode: "chat"
|
|
786
|
-
},
|
|
787
|
-
"gpt-realtime-mini-2025-10-06": {
|
|
788
|
-
input_cost_per_token: 6e-7,
|
|
789
|
-
output_cost_per_token: 24e-7,
|
|
790
|
-
litellm_provider: "openai",
|
|
791
|
-
mode: "chat"
|
|
792
|
-
},
|
|
793
|
-
"gpt-realtime-mini-2025-12-15": {
|
|
794
|
-
input_cost_per_token: 6e-7,
|
|
795
|
-
output_cost_per_token: 24e-7,
|
|
796
|
-
litellm_provider: "openai",
|
|
797
|
-
mode: "chat"
|
|
798
|
-
},
|
|
799
932
|
"llama-3.1-8b-instant": {
|
|
800
933
|
input_cost_per_token: 5e-8,
|
|
801
934
|
output_cost_per_token: 8e-8,
|
|
@@ -1521,6 +1654,42 @@ function budgetGuardMiddleware(guard) {
|
|
|
1521
1654
|
}
|
|
1522
1655
|
};
|
|
1523
1656
|
}
|
|
1657
|
+
|
|
1658
|
+
// src/retry.ts
|
|
1659
|
+
function defaultRetryIf(error) {
|
|
1660
|
+
return !(error instanceof BudgetExceeded);
|
|
1661
|
+
}
|
|
1662
|
+
async function withBudgetRetry(guard, call, options = {}) {
|
|
1663
|
+
const maxAttempts = options.maxAttempts ?? 2;
|
|
1664
|
+
if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {
|
|
1665
|
+
throw new RangeError(`maxAttempts must be an integer >= 1, got ${maxAttempts}`);
|
|
1666
|
+
}
|
|
1667
|
+
const retryIf = options.retryIf ?? defaultRetryIf;
|
|
1668
|
+
let plan = { call, estimatedCost: options.estimatedCost };
|
|
1669
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
1670
|
+
try {
|
|
1671
|
+
return await plan.call();
|
|
1672
|
+
} catch (error) {
|
|
1673
|
+
if (attempt >= maxAttempts || !retryIf(error)) {
|
|
1674
|
+
throw error;
|
|
1675
|
+
}
|
|
1676
|
+
plan = await nextPlan(guard, error, plan, options.onDegrade);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
throw new Error("unreachable");
|
|
1680
|
+
}
|
|
1681
|
+
async function nextPlan(guard, error, current, onDegrade) {
|
|
1682
|
+
const advisory = guard.advisory();
|
|
1683
|
+
if (advisory.nearLimit && onDegrade !== void 0) {
|
|
1684
|
+
const degraded = await onDegrade(error, advisory);
|
|
1685
|
+
if (degraded !== void 0) {
|
|
1686
|
+
guard.check(degraded.estimatedCost);
|
|
1687
|
+
return degraded;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
guard.check(current.estimatedCost);
|
|
1691
|
+
return current;
|
|
1692
|
+
}
|
|
1524
1693
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1525
1694
|
0 && (module.exports = {
|
|
1526
1695
|
BudgetExceeded,
|
|
@@ -1532,6 +1701,7 @@ function budgetGuardMiddleware(guard) {
|
|
|
1532
1701
|
budgetGuardMiddleware,
|
|
1533
1702
|
priceTokens,
|
|
1534
1703
|
pricing,
|
|
1535
|
-
resolvePrice
|
|
1704
|
+
resolvePrice,
|
|
1705
|
+
withBudgetRetry
|
|
1536
1706
|
});
|
|
1537
1707
|
//# sourceMappingURL=index.cjs.map
|