vibezcheck 0.4.2 → 0.5.3

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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +249 -273
  3. package/bin/vibezcheck.js +4 -4
  4. package/dist/ai-sdk/index.d.mts +28 -59
  5. package/dist/ai-sdk/index.d.ts +28 -59
  6. package/dist/ai-sdk/index.js +307 -69
  7. package/dist/ai-sdk/index.js.map +1 -1
  8. package/dist/ai-sdk/index.mjs +307 -69
  9. package/dist/ai-sdk/index.mjs.map +1 -1
  10. package/dist/ai-sdk/middleware.d.mts +15 -0
  11. package/dist/ai-sdk/middleware.d.ts +15 -0
  12. package/dist/ai-sdk/middleware.js +1433 -0
  13. package/dist/ai-sdk/middleware.js.map +1 -0
  14. package/dist/ai-sdk/middleware.mjs +1396 -0
  15. package/dist/ai-sdk/middleware.mjs.map +1 -0
  16. package/dist/auth/index.js.map +1 -1
  17. package/dist/auth/index.mjs.map +1 -1
  18. package/dist/billing/index.d.mts +90 -1
  19. package/dist/billing/index.d.ts +90 -1
  20. package/dist/billing/index.js +1542 -2
  21. package/dist/billing/index.js.map +1 -1
  22. package/dist/billing/index.mjs +1537 -1
  23. package/dist/billing/index.mjs.map +1 -1
  24. package/dist/cli/index.js +59 -7
  25. package/dist/cli/index.js.map +1 -1
  26. package/dist/cli/index.mjs +59 -7
  27. package/dist/cli/index.mjs.map +1 -1
  28. package/dist/{client-ynfWcHX6.d.ts → client-BORmJy8s.d.ts} +1 -1
  29. package/dist/{client-w_hWhQ6g.d.mts → client-CbuXmoXz.d.mts} +1 -1
  30. package/dist/compat/stripe-meter.d.mts +21 -0
  31. package/dist/compat/stripe-meter.d.ts +21 -0
  32. package/dist/compat/stripe-meter.js +1451 -0
  33. package/dist/compat/stripe-meter.js.map +1 -0
  34. package/dist/compat/stripe-meter.mjs +1414 -0
  35. package/dist/compat/stripe-meter.mjs.map +1 -0
  36. package/dist/compat/stripe-provider.d.mts +34 -0
  37. package/dist/compat/stripe-provider.d.ts +34 -0
  38. package/dist/compat/stripe-provider.js +1620 -0
  39. package/dist/compat/stripe-provider.js.map +1 -0
  40. package/dist/compat/stripe-provider.mjs +1587 -0
  41. package/dist/compat/stripe-provider.mjs.map +1 -0
  42. package/dist/compat/token-meter.d.mts +28 -0
  43. package/dist/compat/token-meter.d.ts +28 -0
  44. package/dist/compat/token-meter.js +1320 -0
  45. package/dist/compat/token-meter.js.map +1 -0
  46. package/dist/compat/token-meter.mjs +1283 -0
  47. package/dist/compat/token-meter.mjs.map +1 -0
  48. package/dist/customers/index.d.mts +1 -1
  49. package/dist/customers/index.d.ts +1 -1
  50. package/dist/customers/index.js.map +1 -1
  51. package/dist/customers/index.mjs.map +1 -1
  52. package/dist/index.d.mts +25 -11
  53. package/dist/index.d.ts +25 -11
  54. package/dist/index.js +810 -72
  55. package/dist/index.js.map +1 -1
  56. package/dist/index.mjs +798 -72
  57. package/dist/index.mjs.map +1 -1
  58. package/dist/meter/index.d.mts +2 -2
  59. package/dist/meter/index.d.ts +2 -2
  60. package/dist/meter/index.js +176 -42
  61. package/dist/meter/index.js.map +1 -1
  62. package/dist/meter/index.mjs +176 -42
  63. package/dist/meter/index.mjs.map +1 -1
  64. package/dist/pricing/index.d.mts +15 -4
  65. package/dist/pricing/index.d.ts +15 -4
  66. package/dist/pricing/index.js +165 -29
  67. package/dist/pricing/index.js.map +1 -1
  68. package/dist/pricing/index.mjs +164 -29
  69. package/dist/pricing/index.mjs.map +1 -1
  70. package/dist/react/index.d.mts +46 -2
  71. package/dist/react/index.d.ts +46 -2
  72. package/dist/react/index.js +471 -29
  73. package/dist/react/index.js.map +1 -1
  74. package/dist/react/index.mjs +469 -29
  75. package/dist/react/index.mjs.map +1 -1
  76. package/dist/{types-Mozk4-Mr.d.mts → types-6P71CXAD.d.mts} +16 -6
  77. package/dist/{types-Mozk4-Mr.d.ts → types-6P71CXAD.d.ts} +16 -6
  78. package/dist/with-billing-Bj6Ya_Iy.d.ts +49 -0
  79. package/dist/with-billing-DndWGxL8.d.mts +49 -0
  80. package/package.json +35 -10
@@ -259,12 +259,12 @@ function extractOpenAIResponseUsage(response) {
259
259
  function inspectOpenAIStreamChunk(chunk) {
260
260
  if (!chunk || typeof chunk !== "object") return {};
261
261
  const model = chunk.model;
262
- if (chunk.usage) {
263
- const rawUsage = chunk.usage;
264
- const inputTokens = rawUsage.prompt_tokens ?? rawUsage.input_tokens ?? 0;
265
- const outputTokens = rawUsage.completion_tokens ?? rawUsage.output_tokens ?? 0;
266
- const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens ?? rawUsage.output_token_details?.reasoning_tokens ?? 0;
267
- const cachedTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.input_token_details?.cached_tokens ?? 0;
262
+ const rawUsage = chunk.usage || chunk.token_usage || chunk.x_groq?.usage || chunk.usageMetadata;
263
+ if (rawUsage) {
264
+ const inputTokens = rawUsage.prompt_tokens ?? rawUsage.input_tokens ?? rawUsage.promptTokens ?? rawUsage.inputTokens ?? rawUsage.promptTokenCount ?? 0;
265
+ const outputTokens = rawUsage.completion_tokens ?? rawUsage.output_tokens ?? rawUsage.completionTokens ?? rawUsage.outputTokens ?? rawUsage.candidatesTokenCount ?? 0;
266
+ const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens ?? rawUsage.output_token_details?.reasoning_tokens ?? rawUsage.reasoning_tokens ?? rawUsage.reasoningTokens ?? rawUsage.thoughtsTokenCount ?? 0;
267
+ const cachedTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.input_token_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? rawUsage.cachedTokens ?? rawUsage.cachedContentTokenCount ?? 0;
268
268
  return {
269
269
  model,
270
270
  usage: {
@@ -279,11 +279,11 @@ function inspectOpenAIStreamChunk(chunk) {
279
279
  }
280
280
  if (chunk.type === "response.completed" || chunk.type === "response.done") {
281
281
  if (chunk.response?.usage) {
282
- const rawUsage = chunk.response.usage;
283
- const inputTokens = rawUsage.input_tokens ?? 0;
284
- const outputTokens = rawUsage.output_tokens ?? 0;
285
- const reasoningTokens = rawUsage.output_token_details?.reasoning_tokens ?? 0;
286
- const cachedTokens = rawUsage.input_token_details?.cached_tokens ?? 0;
282
+ const rawUsage2 = chunk.response.usage;
283
+ const inputTokens = rawUsage2.input_tokens ?? 0;
284
+ const outputTokens = rawUsage2.output_tokens ?? 0;
285
+ const reasoningTokens = rawUsage2.output_token_details?.reasoning_tokens ?? 0;
286
+ const cachedTokens = rawUsage2.input_token_details?.cached_tokens ?? 0;
287
287
  return {
288
288
  model: chunk.response.model || model,
289
289
  usage: {
@@ -448,7 +448,7 @@ function detectAndExtractUsage(response, fallbackModel, fallbackProvider) {
448
448
 
449
449
  // src/pricing/table.ts
450
450
  var MODEL_PRICING_TABLE = {
451
- // --- OpenAI ---
451
+ // --- OpenAI (Modern & Reasoning) ---
452
452
  "gpt-5.6-sol": { inputPer1M: 4, outputPer1M: 20, cachedInputPer1M: 0.4 },
453
453
  "gpt-5.6-terra": { inputPer1M: 2, outputPer1M: 12, cachedInputPer1M: 0.2 },
454
454
  "gpt-5.6-luna": { inputPer1M: 0.2, outputPer1M: 1.2, cachedInputPer1M: 0.02 },
@@ -460,11 +460,22 @@ var MODEL_PRICING_TABLE = {
460
460
  "o3-mini": { inputPer1M: 1.1, outputPer1M: 4.4, cachedInputPer1M: 0.55 },
461
461
  "gpt-4o": { inputPer1M: 2.5, outputPer1M: 10, cachedInputPer1M: 1.25 },
462
462
  "gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6, cachedInputPer1M: 0.075 },
463
+ "gpt-4.5": { inputPer1M: 75, outputPer1M: 150, cachedInputPer1M: 37.5 },
464
+ "gpt-4.5-preview": { inputPer1M: 75, outputPer1M: 150, cachedInputPer1M: 37.5 },
465
+ "chatgpt-4o-latest": { inputPer1M: 5, outputPer1M: 15 },
463
466
  "gpt-4.1": { inputPer1M: 2, outputPer1M: 8, cachedInputPer1M: 1 },
464
467
  "gpt-4.1-nano": { inputPer1M: 0.1, outputPer1M: 0.4, cachedInputPer1M: 0.05 },
468
+ // --- OpenAI (Legacy & Backward Compatibility) ---
469
+ "gpt-4-turbo": { inputPer1M: 10, outputPer1M: 30, cachedInputPer1M: 5 },
470
+ "gpt-4-turbo-preview": { inputPer1M: 10, outputPer1M: 30, cachedInputPer1M: 5 },
471
+ "gpt-4": { inputPer1M: 30, outputPer1M: 60 },
472
+ "gpt-4-32k": { inputPer1M: 60, outputPer1M: 120 },
473
+ "gpt-3.5-turbo": { inputPer1M: 0.5, outputPer1M: 1.5 },
474
+ "gpt-3.5-turbo-16k": { inputPer1M: 3, outputPer1M: 4 },
465
475
  "text-embedding-3-small": { inputPer1M: 0.02, outputPer1M: 0 },
466
476
  "text-embedding-3-large": { inputPer1M: 0.13, outputPer1M: 0 },
467
- // --- Anthropic ---
477
+ "text-embedding-ada-002": { inputPer1M: 0.1, outputPer1M: 0 },
478
+ // --- Anthropic (Modern & Extended Thinking) ---
468
479
  "claude-3-7-sonnet": { inputPer1M: 0.59, outputPer1M: 2.93, cachedInputPer1M: 0.3 },
469
480
  "claude-sonnet-5": { inputPer1M: 2, outputPer1M: 10, cachedInputPer1M: 0.3 },
470
481
  "claude-3-5-sonnet": { inputPer1M: 3, outputPer1M: 15, cachedInputPer1M: 0.3 },
@@ -472,48 +483,145 @@ var MODEL_PRICING_TABLE = {
472
483
  "haiku-4.5": { inputPer1M: 1, outputPer1M: 5, cachedInputPer1M: 0.1 },
473
484
  "claude-opus-5": { inputPer1M: 5, outputPer1M: 25, cachedInputPer1M: 1.5 },
474
485
  "claude-3-opus": { inputPer1M: 15, outputPer1M: 75, cachedInputPer1M: 1.5 },
475
- // --- Google Gemini ---
486
+ // --- Anthropic (Legacy & Backward Compatibility) ---
487
+ "claude-3-sonnet": { inputPer1M: 3, outputPer1M: 15, cachedInputPer1M: 0.3 },
488
+ "claude-3-haiku": { inputPer1M: 0.25, outputPer1M: 1.25, cachedInputPer1M: 0.025 },
489
+ "claude-2.1": { inputPer1M: 8, outputPer1M: 24 },
490
+ "claude-2.0": { inputPer1M: 8, outputPer1M: 24 },
491
+ "claude-instant-1.2": { inputPer1M: 1.63, outputPer1M: 5.51 },
492
+ // --- Google Gemini (Modern & Thoughts) ---
476
493
  "gemini-3.7-flash": { inputPer1M: 0.75, outputPer1M: 3.75, cachedInputPer1M: 0.18 },
477
494
  "gemini-3.1-pro": { inputPer1M: 2, outputPer1M: 12, cachedInputPer1M: 0.5 },
478
495
  "gemini-3.5-flash": { inputPer1M: 1.5, outputPer1M: 9, cachedInputPer1M: 0.38 },
479
496
  "gemini-3.1-flash-lite": { inputPer1M: 0.25, outputPer1M: 1.5, cachedInputPer1M: 0.06 },
497
+ "gemini-2.5-pro": { inputPer1M: 1.25, outputPer1M: 5, cachedInputPer1M: 0.3125 },
498
+ "gemini-2.5-flash": { inputPer1M: 0.15, outputPer1M: 0.6, cachedInputPer1M: 0.0375 },
480
499
  "gemini-2.0-flash": { inputPer1M: 0.1, outputPer1M: 0.4, cachedInputPer1M: 0.025 },
500
+ "gemini-2.0-flash-lite": { inputPer1M: 0.075, outputPer1M: 0.3, cachedInputPer1M: 0.01875 },
501
+ "gemini-2.0-pro": { inputPer1M: 1.25, outputPer1M: 5, cachedInputPer1M: 0.3125 },
502
+ // --- Google Gemini (Legacy & Backward Compatibility) ---
481
503
  "gemini-1.5-pro": { inputPer1M: 1.25, outputPer1M: 5, cachedInputPer1M: 0.3125 },
482
504
  "gemini-1.5-flash": { inputPer1M: 0.075, outputPer1M: 0.3, cachedInputPer1M: 0.01875 },
505
+ "gemini-1.5-flash-8b": { inputPer1M: 0.0375, outputPer1M: 0.15, cachedInputPer1M: 9375e-6 },
506
+ "gemini-1.0-pro": { inputPer1M: 0.5, outputPer1M: 1.5 },
483
507
  // --- xAI Grok ---
484
508
  "grok-4.6": { inputPer1M: 3, outputPer1M: 15 },
509
+ "grok-3": { inputPer1M: 3, outputPer1M: 15 },
510
+ "grok-3-mini": { inputPer1M: 0.3, outputPer1M: 1.5 },
485
511
  "grok-2": { inputPer1M: 2, outputPer1M: 10 },
486
512
  "grok-2-vision": { inputPer1M: 2, outputPer1M: 10 },
487
513
  "grok-beta": { inputPer1M: 5, outputPer1M: 15 },
488
514
  // --- Mistral ---
489
515
  "mistral-large-3": { inputPer1M: 2, outputPer1M: 6 },
490
516
  "mistral-large-latest": { inputPer1M: 2, outputPer1M: 6 },
517
+ "mistral-large-2411": { inputPer1M: 2, outputPer1M: 6 },
491
518
  "codestral-latest": { inputPer1M: 0.3, outputPer1M: 0.9 },
519
+ "mistral-medium-latest": { inputPer1M: 2.7, outputPer1M: 8.1 },
492
520
  "mistral-small-latest": { inputPer1M: 0.2, outputPer1M: 0.6 },
493
521
  "ministral-8b-latest": { inputPer1M: 0.1, outputPer1M: 0.1 },
494
- // --- Groq LPUs ---
522
+ "ministral-3b-latest": { inputPer1M: 0.04, outputPer1M: 0.04 },
523
+ "open-mistral-7b": { inputPer1M: 0.2, outputPer1M: 0.2 },
524
+ "open-mixtral-8x7b": { inputPer1M: 0.7, outputPer1M: 0.7 },
525
+ "open-mixtral-8x22b": { inputPer1M: 2, outputPer1M: 6 },
526
+ // --- Groq & Meta Llama LPUs ---
495
527
  "llama-3.3-70b-versatile": { inputPer1M: 0.59, outputPer1M: 0.79 },
528
+ "llama-3.1-405b": { inputPer1M: 3, outputPer1M: 3 },
529
+ "llama-3.1-70b-versatile": { inputPer1M: 0.59, outputPer1M: 0.79 },
496
530
  "llama-3.1-8b-instant": { inputPer1M: 0.05, outputPer1M: 0.08 },
531
+ "llama-3.2-1b-preview": { inputPer1M: 0.04, outputPer1M: 0.04 },
532
+ "llama-3.2-3b-preview": { inputPer1M: 0.06, outputPer1M: 0.06 },
533
+ "llama-3.2-11b-vision": { inputPer1M: 0.18, outputPer1M: 0.18 },
534
+ "llama-3.2-90b-vision": { inputPer1M: 0.9, outputPer1M: 0.9 },
497
535
  "deepseek-r1-distill-llama-70b": { inputPer1M: 0.75, outputPer1M: 0.99 },
536
+ "deepseek-r1-distill-qwen-32b": { inputPer1M: 0.49, outputPer1M: 0.49 },
498
537
  "qwen-2.5-32b": { inputPer1M: 0.29, outputPer1M: 0.39 },
538
+ "qwen-2.5-72b": { inputPer1M: 0.35, outputPer1M: 0.4 },
539
+ "mixtral-8x7b-32768": { inputPer1M: 0.24, outputPer1M: 0.24 },
540
+ "gemma2-9b-it": { inputPer1M: 0.2, outputPer1M: 0.2 },
499
541
  // --- DeepSeek ---
500
542
  "deepseek-v4-pro": { inputPer1M: 0.66, outputPer1M: 1.98, cachedInputPer1M: 0.15 },
501
543
  "deepseek-v4-flash": { inputPer1M: 0.22, outputPer1M: 0.66, cachedInputPer1M: 0.05 },
502
- "deepseek-chat": { inputPer1M: 0.22, outputPer1M: 0.66, cachedInputPer1M: 0.05 },
503
- "deepseek-reasoner": { inputPer1M: 0.66, outputPer1M: 1.98, cachedInputPer1M: 0.15 },
544
+ "deepseek-v3": { inputPer1M: 0.14, outputPer1M: 0.28, cachedInputPer1M: 0.014 },
545
+ "deepseek-chat": { inputPer1M: 0.14, outputPer1M: 0.28, cachedInputPer1M: 0.014 },
546
+ "deepseek-r1": { inputPer1M: 0.55, outputPer1M: 2.19, cachedInputPer1M: 0.14 },
547
+ "deepseek-reasoner": { inputPer1M: 0.55, outputPer1M: 2.19, cachedInputPer1M: 0.14 },
504
548
  // --- Cohere ---
505
549
  "command-r-plus": { inputPer1M: 2.5, outputPer1M: 10 },
506
- "command-r": { inputPer1M: 0.15, outputPer1M: 0.6 }
550
+ "command-r": { inputPer1M: 0.15, outputPer1M: 0.6 },
551
+ "command": { inputPer1M: 1, outputPer1M: 2 },
552
+ "command-light": { inputPer1M: 0.3, outputPer1M: 0.6 },
553
+ "embed-english-v3.0": { inputPer1M: 0.1, outputPer1M: 0 },
554
+ // --- Perplexity ---
555
+ "sonar": { inputPer1M: 1, outputPer1M: 1 },
556
+ "sonar-pro": { inputPer1M: 3, outputPer1M: 15 },
557
+ "sonar-reasoning": { inputPer1M: 1, outputPer1M: 5 },
558
+ "sonar-reasoning-pro": { inputPer1M: 2, outputPer1M: 8 }
559
+ };
560
+ var MODEL_ALIASES = {
561
+ // OpenAI Shorthands & Aliases
562
+ "gpt4": "gpt-4",
563
+ "gpt4o": "gpt-4o",
564
+ "gpt-4-preview": "gpt-4-turbo",
565
+ "gpt-4-0125-preview": "gpt-4-turbo",
566
+ "gpt-4-1106-preview": "gpt-4-turbo",
567
+ "gpt-3.5": "gpt-3.5-turbo",
568
+ "gpt-3.5-turbo-0125": "gpt-3.5-turbo",
569
+ "gpt-3.5-turbo-1106": "gpt-3.5-turbo",
570
+ "gpt-3.5-turbo-16k-0613": "gpt-3.5-turbo-16k",
571
+ // Anthropic Shorthands
572
+ "sonnet": "claude-3-5-sonnet",
573
+ "sonnet-3.7": "claude-3-7-sonnet",
574
+ "sonnet-3.5": "claude-3-5-sonnet",
575
+ "haiku": "claude-3-5-haiku",
576
+ "haiku-3.5": "claude-3-5-haiku",
577
+ "opus": "claude-3-opus",
578
+ "claude-2": "claude-2.0",
579
+ "claude-instant": "claude-instant-1.2",
580
+ // DeepSeek Shorthands
581
+ "r1": "deepseek-r1",
582
+ "v3": "deepseek-v3",
583
+ // Gemini Shorthands
584
+ "flash": "gemini-2.0-flash",
585
+ "pro": "gemini-1.5-pro",
586
+ // Meta / Groq Shorthands
587
+ "llama-3.3-70b": "llama-3.3-70b-versatile",
588
+ "llama-3.1-70b": "llama-3.1-70b-versatile",
589
+ "llama-3.1-8b": "llama-3.1-8b-instant",
590
+ "llama-3-70b": "llama-3.1-70b-versatile",
591
+ "llama-3-8b": "llama-3.1-8b-instant",
592
+ // Mistral Shorthands
593
+ "codestral": "codestral-latest",
594
+ "mistral-large": "mistral-large-latest",
595
+ "mistral-small": "mistral-small-latest"
507
596
  };
508
597
  var customPricingRegistry = {};
509
598
  function normalizeModelKey(rawModel) {
510
599
  if (!rawModel) return "unknown";
511
600
  let model = rawModel.toLowerCase().trim();
601
+ model = model.replace(/^[a-z0-9_-]+\.(anthropic|meta|amazon|cohere|mistral|ai21)\./i, "");
602
+ model = model.replace(/^(anthropic|meta|amazon|cohere|mistral|ai21)\./i, "");
603
+ model = model.replace(/-v\d+(:\d+)?$/, "");
604
+ model = model.replace(/:\d+$/, "");
512
605
  if (model.includes("/")) {
513
- model = model.split("/")[1] || model;
606
+ model = model.split("/").slice(1).join("/");
514
607
  }
608
+ model = model.replace(/:(latest|free|beta)$/, "");
515
609
  model = model.replace(/-\d{8}$/, "");
516
610
  model = model.replace(/-\d{4}-\d{2}-\d{2}$/, "");
611
+ model = model.replace(/llama(\d+)-(\d+)-/g, "llama-$1.$2-");
612
+ model = model.replace(/llama(\d+)\.(\d+)-/g, "llama-$1.$2-");
613
+ if (MODEL_ALIASES[model]) {
614
+ return MODEL_ALIASES[model];
615
+ }
616
+ if (!MODEL_PRICING_TABLE[model]) {
617
+ const withoutInstruct = model.replace(/-(instruct|chat|preview)$/, "");
618
+ if (MODEL_PRICING_TABLE[withoutInstruct]) {
619
+ return withoutInstruct;
620
+ }
621
+ if (MODEL_ALIASES[withoutInstruct]) {
622
+ return MODEL_ALIASES[withoutInstruct];
623
+ }
624
+ }
517
625
  return model;
518
626
  }
519
627
  function getModelPricing(modelName) {
@@ -530,6 +638,10 @@ function getModelPricing(modelName) {
530
638
  if (MODEL_PRICING_TABLE[modelName]) {
531
639
  return MODEL_PRICING_TABLE[modelName];
532
640
  }
641
+ const alias = MODEL_ALIASES[modelName.toLowerCase().trim()];
642
+ if (alias && MODEL_PRICING_TABLE[alias]) {
643
+ return MODEL_PRICING_TABLE[alias];
644
+ }
533
645
  return {
534
646
  inputPer1M: 1,
535
647
  outputPer1M: 3,
@@ -552,35 +664,57 @@ function calculateCost(params) {
552
664
  } else {
553
665
  rates = getModelPricing(params.model);
554
666
  }
555
- const inputTokens = params.inputTokens ?? 0;
556
- const outputTokens = params.outputTokens ?? 0;
557
- const reasoningTokens = params.reasoningTokens ?? 0;
558
- const cachedTokens = params.cachedTokens ?? 0;
559
- const regularInputTokens = Math.max(0, inputTokens - cachedTokens);
560
- const regularInputCost = regularInputTokens / 1e6 * rates.inputPer1M;
561
- const cachedRate = rates.cachedInputPer1M ?? rates.inputPer1M * 0.15;
562
- const cachedInputCost = cachedTokens / 1e6 * cachedRate;
563
- const inputCostUSD = regularInputCost + cachedInputCost;
564
- const outputCostUSD = outputTokens / 1e6 * rates.outputPer1M;
565
- const reasoningRate = rates.reasoningPer1M ?? rates.outputPer1M;
566
- const reasoningCostUSD = reasoningTokens / 1e6 * reasoningRate;
567
- const standardCacheCost = cachedTokens / 1e6 * rates.inputPer1M;
568
- const cachedDiscountUSD = Math.max(0, standardCacheCost - cachedInputCost);
569
- let totalUSD = inputCostUSD + outputCostUSD;
667
+ const inputTokens = BigInt(Math.max(0, params.inputTokens ?? 0));
668
+ const outputTokens = BigInt(Math.max(0, params.outputTokens ?? 0));
669
+ const reasoningTokens = BigInt(Math.max(0, params.reasoningTokens ?? 0));
670
+ const cachedTokens = BigInt(Math.max(0, params.cachedTokens ?? 0));
671
+ const regularInputTokens = inputTokens > cachedTokens ? inputTokens - cachedTokens : 0n;
672
+ const rateInputNano = BigInt(Math.round(rates.inputPer1M * 1e3));
673
+ const cachedPer1M = rates.cachedInputPer1M ?? rates.inputPer1M * 0.15;
674
+ const rateCachedNano = BigInt(Math.round(cachedPer1M * 1e3));
675
+ const rateOutputNano = BigInt(Math.round(rates.outputPer1M * 1e3));
676
+ const reasoningPer1M = rates.reasoningPer1M ?? rates.outputPer1M;
677
+ const rateReasoningNano = BigInt(Math.round(reasoningPer1M * 1e3));
678
+ const regularInputCostNano = regularInputTokens * rateInputNano;
679
+ const cachedInputCostNano = cachedTokens * rateCachedNano;
680
+ const inputCostNano = regularInputCostNano + cachedInputCostNano;
681
+ const outputCostNano = outputTokens * rateOutputNano;
682
+ const reasoningCostNano = reasoningTokens * rateReasoningNano;
683
+ const standardCacheCostNano = cachedTokens * rateInputNano;
684
+ const cachedDiscountNano = standardCacheCostNano > cachedInputCostNano ? standardCacheCostNano - cachedInputCostNano : 0n;
685
+ const wholesaleNano = inputCostNano + outputCostNano;
570
686
  const markup = params.markupMultiplier ?? 1;
571
- let retailUSD = void 0;
687
+ let billedNano = wholesaleNano;
688
+ let hasRetail = false;
572
689
  if (markup !== 1 || params.minimumChargeUSD !== void 0) {
573
- retailUSD = totalUSD * markup;
574
- if (params.minimumChargeUSD !== void 0 && retailUSD < params.minimumChargeUSD) {
575
- retailUSD = params.minimumChargeUSD;
690
+ hasRetail = true;
691
+ const markupMultiplierNano = BigInt(Math.round(markup * 1e3));
692
+ billedNano = wholesaleNano * markupMultiplierNano / 1000n;
693
+ if (params.minimumChargeUSD !== void 0 && params.minimumChargeUSD > 0) {
694
+ const minChargeNano = BigInt(Math.round(params.minimumChargeUSD * 1e9));
695
+ if (billedNano < minChargeNano) {
696
+ billedNano = minChargeNano;
697
+ }
576
698
  }
577
699
  }
700
+ const inputCostUSD = Number(inputCostNano) / 1e9;
701
+ const outputCostUSD = Number(outputCostNano) / 1e9;
702
+ const reasoningCostUSD = Number(reasoningCostNano) / 1e9;
703
+ const cachedDiscountUSD = Number(cachedDiscountNano) / 1e9;
704
+ const totalUSD = Number(wholesaleNano) / 1e9;
705
+ const wholesaleTotalUSD = totalUSD;
706
+ const billedUSD = Number(billedNano) / 1e9;
707
+ const profitUSD = Math.max(0, billedUSD - wholesaleTotalUSD);
708
+ const retailUSD = hasRetail ? billedUSD : void 0;
578
709
  return {
579
710
  inputCostUSD: Number(inputCostUSD.toFixed(8)),
580
711
  outputCostUSD: Number(outputCostUSD.toFixed(8)),
581
- reasoningCostUSD: reasoningTokens > 0 ? Number(reasoningCostUSD.toFixed(8)) : void 0,
582
- cachedDiscountUSD: cachedTokens > 0 ? Number(cachedDiscountUSD.toFixed(8)) : void 0,
712
+ reasoningCostUSD: reasoningTokens > 0n ? Number(reasoningCostUSD.toFixed(8)) : void 0,
713
+ cachedDiscountUSD: cachedTokens > 0n ? Number(cachedDiscountUSD.toFixed(8)) : void 0,
583
714
  totalUSD: Number(totalUSD.toFixed(8)),
715
+ wholesaleTotalUSD: Number(wholesaleTotalUSD.toFixed(8)),
716
+ billedUSD: Number(billedUSD.toFixed(8)),
717
+ profitUSD: Number(profitUSD.toFixed(8)),
584
718
  retailUSD: retailUSD !== void 0 ? Number(retailUSD.toFixed(8)) : void 0,
585
719
  currency: rates.currency || "USD"
586
720
  };
@@ -786,7 +920,7 @@ function wrapUniversalStream(stream, options = {}, onComplete) {
786
920
  return wrapGeminiStream(stream, options, onComplete);
787
921
  }
788
922
  if (Symbol.asyncIterator in stream) {
789
- if (options.provider === "anthropic") {
923
+ if (options.provider === "anthropic" || options.model?.toLowerCase().includes("claude")) {
790
924
  return wrapAnthropicStream(stream, options, onComplete);
791
925
  }
792
926
  return wrapOpenAIStream(stream, options, onComplete);
@@ -808,7 +942,7 @@ var VibezMeter = class {
808
942
  this.stripeClient = new Stripe(key, {
809
943
  appInfo: {
810
944
  name: "vibezcheck",
811
- version: "0.4.2",
945
+ version: "0.5.3",
812
946
  url: "https://vibezcheck.xyz"
813
947
  }
814
948
  });