@ljoukov/llm 7.0.17 → 7.0.18

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.d.cts CHANGED
@@ -15,8 +15,9 @@ type LlmUsageTokens = {
15
15
  readonly totalTokens?: number;
16
16
  readonly toolUsePromptTokens?: number;
17
17
  };
18
- declare function estimateCallCostUsd({ modelId, tokens, responseImages, imageSize, imageQuality, }: {
18
+ declare function estimateCallCostUsd({ modelId, pricingModelId, tokens, responseImages, imageSize, imageQuality, }: {
19
19
  modelId: string;
20
+ pricingModelId?: string;
20
21
  tokens: LlmUsageTokens | undefined;
21
22
  responseImages: number;
22
23
  imageSize?: string;
package/dist/index.d.ts CHANGED
@@ -15,8 +15,9 @@ type LlmUsageTokens = {
15
15
  readonly totalTokens?: number;
16
16
  readonly toolUsePromptTokens?: number;
17
17
  };
18
- declare function estimateCallCostUsd({ modelId, tokens, responseImages, imageSize, imageQuality, }: {
18
+ declare function estimateCallCostUsd({ modelId, pricingModelId, tokens, responseImages, imageSize, imageQuality, }: {
19
19
  modelId: string;
20
+ pricingModelId?: string;
20
21
  tokens: LlmUsageTokens | undefined;
21
22
  responseImages: number;
22
23
  imageSize?: string;
package/dist/index.js CHANGED
@@ -344,6 +344,7 @@ function resolveChatGptServiceTier(model) {
344
344
  // src/openai/pricing.ts
345
345
  var OPENAI_GPT_55_FAST_MODEL_IDS = ["gpt-5.5-fast", "chatgpt-gpt-5.5-fast"];
346
346
  var OPENAI_GPT_55_STANDARD_MODEL_IDS = ["gpt-5.5", "chatgpt-gpt-5.5"];
347
+ var OPENAI_GPT_55_CONCRETE_MODEL_ID_RE = /^(?:chatgpt-)?gpt-5\.5-\d{4}-\d{2}-\d{2}$/u;
347
348
  var OPENAI_GPT_54_FAST_MODEL_IDS = ["gpt-5.4-fast", "chatgpt-gpt-5.4-fast"];
348
349
  var OPENAI_GPT_54_MINI_MODEL_IDS = ["gpt-5.4-mini", "chatgpt-gpt-5.4-mini"];
349
350
  var OPENAI_GPT_54_NANO_MODEL_IDS = ["gpt-5.4-nano"];
@@ -410,7 +411,7 @@ function getOpenAiPricing(modelId) {
410
411
  if (OPENAI_GPT_55_FAST_MODEL_IDS.includes(modelId)) {
411
412
  return OPENAI_GPT_55_PRIORITY_PRICING;
412
413
  }
413
- if (OPENAI_GPT_55_STANDARD_MODEL_IDS.includes(modelId)) {
414
+ if (OPENAI_GPT_55_STANDARD_MODEL_IDS.includes(modelId) || OPENAI_GPT_55_CONCRETE_MODEL_ID_RE.test(modelId)) {
414
415
  return OPENAI_GPT_55_PRICING;
415
416
  }
416
417
  if (OPENAI_GPT_54_FAST_MODEL_IDS.includes(modelId)) {
@@ -443,12 +444,14 @@ function resolveUsageNumber(value) {
443
444
  }
444
445
  function estimateCallCostUsd({
445
446
  modelId,
447
+ pricingModelId,
446
448
  tokens,
447
449
  responseImages,
448
450
  imageSize,
449
451
  imageQuality
450
452
  }) {
451
- const openAiImagePricing = getOpenAiImagePricing(modelId);
453
+ const pricingModelIds = resolvePricingModelIds(modelId, pricingModelId);
454
+ const openAiImagePricing = resolvePricing(pricingModelIds, getOpenAiImagePricing);
452
455
  if (openAiImagePricing) {
453
456
  return estimateOpenAiImageCostUsd({
454
457
  pricing: openAiImagePricing,
@@ -468,7 +471,7 @@ function estimateCallCostUsd({
468
471
  const toolUsePromptTokens = resolveUsageNumber(tokens.toolUsePromptTokens);
469
472
  const promptTokenTotal = promptTokens + toolUsePromptTokens;
470
473
  const nonCachedPrompt = Math.max(0, promptTokenTotal - cachedTokens);
471
- const imagePreviewPricing = getGeminiImagePricing(modelId);
474
+ const imagePreviewPricing = resolvePricing(pricingModelIds, getGeminiImagePricing);
472
475
  if (imagePreviewPricing) {
473
476
  const resolvedImageSize = imageSize && imagePreviewPricing.imagePrices[imageSize] ? imageSize : "2K";
474
477
  const imageRate = imagePreviewPricing.imagePrices[resolvedImageSize] ?? 0;
@@ -488,7 +491,7 @@ function estimateCallCostUsd({
488
491
  const imageOutputCost = imageTokensForPricing * imagePreviewPricing.outputImageRate;
489
492
  return inputCost + cachedCost + textOutputCost + imageOutputCost;
490
493
  }
491
- const geminiPricing = getGeminiProPricing(modelId);
494
+ const geminiPricing = resolvePricing(pricingModelIds, getGeminiProPricing);
492
495
  if (geminiPricing) {
493
496
  const useHighTier = promptTokenTotal > geminiPricing.threshold;
494
497
  const inputRate = useHighTier ? geminiPricing.inputRateHigh : geminiPricing.inputRateLow;
@@ -500,7 +503,7 @@ function estimateCallCostUsd({
500
503
  const outputCost = outputTokens * outputRate;
501
504
  return inputCost + cachedCost + outputCost;
502
505
  }
503
- const fireworksPricing = getFireworksPricing(modelId);
506
+ const fireworksPricing = resolvePricing(pricingModelIds, getFireworksPricing);
504
507
  if (fireworksPricing) {
505
508
  const inputCost = nonCachedPrompt * fireworksPricing.inputRate;
506
509
  const cachedCost = cachedTokens * fireworksPricing.cachedRate;
@@ -508,7 +511,7 @@ function estimateCallCostUsd({
508
511
  const outputCost = outputTokens * fireworksPricing.outputRate;
509
512
  return inputCost + cachedCost + outputCost;
510
513
  }
511
- const openAiPricing = getOpenAiPricing(modelId);
514
+ const openAiPricing = resolvePricing(pricingModelIds, getOpenAiPricing);
512
515
  if (openAiPricing) {
513
516
  const inputCost = nonCachedPrompt * openAiPricing.inputRate;
514
517
  const cachedCost = cachedTokens * openAiPricing.cachedRate;
@@ -518,6 +521,21 @@ function estimateCallCostUsd({
518
521
  }
519
522
  return 0;
520
523
  }
524
+ function resolvePricingModelIds(modelId, pricingModelId) {
525
+ if (pricingModelId && pricingModelId !== modelId) {
526
+ return [pricingModelId, modelId];
527
+ }
528
+ return [modelId];
529
+ }
530
+ function resolvePricing(modelIds, resolve) {
531
+ for (const modelId of modelIds) {
532
+ const pricing = resolve(modelId);
533
+ if (pricing) {
534
+ return pricing;
535
+ }
536
+ }
537
+ return void 0;
538
+ }
521
539
  function estimateOpenAiImageCostUsd({
522
540
  pricing,
523
541
  responseImages,
@@ -8329,6 +8347,7 @@ async function runTextCall(params) {
8329
8347
  const outputAttachments = collectLoggedAttachmentsFromLlmParts(mergedParts, "output");
8330
8348
  const costUsd = estimateCallCostUsd({
8331
8349
  modelId: modelVersion,
8350
+ pricingModelId: request.model,
8332
8351
  tokens: latestUsage,
8333
8352
  responseImages,
8334
8353
  imageSize: request.imageSize
@@ -9072,6 +9091,7 @@ async function runToolLoop(request) {
9072
9091
  const modelCompletedAtMs = Date.now();
9073
9092
  const stepCostUsd = estimateCallCostUsd({
9074
9093
  modelId: modelVersion,
9094
+ pricingModelId: request.model,
9075
9095
  tokens: usageTokens,
9076
9096
  responseImages: 0
9077
9097
  });
@@ -9403,6 +9423,7 @@ async function runToolLoop(request) {
9403
9423
  usageTokens = extractChatGptUsageTokens(response.usage);
9404
9424
  const stepCostUsd = estimateCallCostUsd({
9405
9425
  modelId: modelVersion,
9426
+ pricingModelId: request.model,
9406
9427
  tokens: usageTokens,
9407
9428
  responseImages: 0
9408
9429
  });
@@ -9731,6 +9752,7 @@ async function runToolLoop(request) {
9731
9752
  usageTokens = extractFireworksUsageTokens(response.usage);
9732
9753
  const stepCostUsd = estimateCallCostUsd({
9733
9754
  modelId: modelVersion,
9755
+ pricingModelId: request.model,
9734
9756
  tokens: usageTokens,
9735
9757
  responseImages: 0
9736
9758
  });
@@ -10093,6 +10115,7 @@ async function runToolLoop(request) {
10093
10115
  );
10094
10116
  const stepCostUsd = estimateCallCostUsd({
10095
10117
  modelId: modelVersion,
10118
+ pricingModelId: request.model,
10096
10119
  tokens: usageTokens,
10097
10120
  responseImages: 0
10098
10121
  });