@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.cjs +29 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -481,6 +481,7 @@ function resolveChatGptServiceTier(model) {
|
|
|
481
481
|
// src/openai/pricing.ts
|
|
482
482
|
var OPENAI_GPT_55_FAST_MODEL_IDS = ["gpt-5.5-fast", "chatgpt-gpt-5.5-fast"];
|
|
483
483
|
var OPENAI_GPT_55_STANDARD_MODEL_IDS = ["gpt-5.5", "chatgpt-gpt-5.5"];
|
|
484
|
+
var OPENAI_GPT_55_CONCRETE_MODEL_ID_RE = /^(?:chatgpt-)?gpt-5\.5-\d{4}-\d{2}-\d{2}$/u;
|
|
484
485
|
var OPENAI_GPT_54_FAST_MODEL_IDS = ["gpt-5.4-fast", "chatgpt-gpt-5.4-fast"];
|
|
485
486
|
var OPENAI_GPT_54_MINI_MODEL_IDS = ["gpt-5.4-mini", "chatgpt-gpt-5.4-mini"];
|
|
486
487
|
var OPENAI_GPT_54_NANO_MODEL_IDS = ["gpt-5.4-nano"];
|
|
@@ -547,7 +548,7 @@ function getOpenAiPricing(modelId) {
|
|
|
547
548
|
if (OPENAI_GPT_55_FAST_MODEL_IDS.includes(modelId)) {
|
|
548
549
|
return OPENAI_GPT_55_PRIORITY_PRICING;
|
|
549
550
|
}
|
|
550
|
-
if (OPENAI_GPT_55_STANDARD_MODEL_IDS.includes(modelId)) {
|
|
551
|
+
if (OPENAI_GPT_55_STANDARD_MODEL_IDS.includes(modelId) || OPENAI_GPT_55_CONCRETE_MODEL_ID_RE.test(modelId)) {
|
|
551
552
|
return OPENAI_GPT_55_PRICING;
|
|
552
553
|
}
|
|
553
554
|
if (OPENAI_GPT_54_FAST_MODEL_IDS.includes(modelId)) {
|
|
@@ -580,12 +581,14 @@ function resolveUsageNumber(value) {
|
|
|
580
581
|
}
|
|
581
582
|
function estimateCallCostUsd({
|
|
582
583
|
modelId,
|
|
584
|
+
pricingModelId,
|
|
583
585
|
tokens,
|
|
584
586
|
responseImages,
|
|
585
587
|
imageSize,
|
|
586
588
|
imageQuality
|
|
587
589
|
}) {
|
|
588
|
-
const
|
|
590
|
+
const pricingModelIds = resolvePricingModelIds(modelId, pricingModelId);
|
|
591
|
+
const openAiImagePricing = resolvePricing(pricingModelIds, getOpenAiImagePricing);
|
|
589
592
|
if (openAiImagePricing) {
|
|
590
593
|
return estimateOpenAiImageCostUsd({
|
|
591
594
|
pricing: openAiImagePricing,
|
|
@@ -605,7 +608,7 @@ function estimateCallCostUsd({
|
|
|
605
608
|
const toolUsePromptTokens = resolveUsageNumber(tokens.toolUsePromptTokens);
|
|
606
609
|
const promptTokenTotal = promptTokens + toolUsePromptTokens;
|
|
607
610
|
const nonCachedPrompt = Math.max(0, promptTokenTotal - cachedTokens);
|
|
608
|
-
const imagePreviewPricing = getGeminiImagePricing
|
|
611
|
+
const imagePreviewPricing = resolvePricing(pricingModelIds, getGeminiImagePricing);
|
|
609
612
|
if (imagePreviewPricing) {
|
|
610
613
|
const resolvedImageSize = imageSize && imagePreviewPricing.imagePrices[imageSize] ? imageSize : "2K";
|
|
611
614
|
const imageRate = imagePreviewPricing.imagePrices[resolvedImageSize] ?? 0;
|
|
@@ -625,7 +628,7 @@ function estimateCallCostUsd({
|
|
|
625
628
|
const imageOutputCost = imageTokensForPricing * imagePreviewPricing.outputImageRate;
|
|
626
629
|
return inputCost + cachedCost + textOutputCost + imageOutputCost;
|
|
627
630
|
}
|
|
628
|
-
const geminiPricing = getGeminiProPricing
|
|
631
|
+
const geminiPricing = resolvePricing(pricingModelIds, getGeminiProPricing);
|
|
629
632
|
if (geminiPricing) {
|
|
630
633
|
const useHighTier = promptTokenTotal > geminiPricing.threshold;
|
|
631
634
|
const inputRate = useHighTier ? geminiPricing.inputRateHigh : geminiPricing.inputRateLow;
|
|
@@ -637,7 +640,7 @@ function estimateCallCostUsd({
|
|
|
637
640
|
const outputCost = outputTokens * outputRate;
|
|
638
641
|
return inputCost + cachedCost + outputCost;
|
|
639
642
|
}
|
|
640
|
-
const fireworksPricing = getFireworksPricing
|
|
643
|
+
const fireworksPricing = resolvePricing(pricingModelIds, getFireworksPricing);
|
|
641
644
|
if (fireworksPricing) {
|
|
642
645
|
const inputCost = nonCachedPrompt * fireworksPricing.inputRate;
|
|
643
646
|
const cachedCost = cachedTokens * fireworksPricing.cachedRate;
|
|
@@ -645,7 +648,7 @@ function estimateCallCostUsd({
|
|
|
645
648
|
const outputCost = outputTokens * fireworksPricing.outputRate;
|
|
646
649
|
return inputCost + cachedCost + outputCost;
|
|
647
650
|
}
|
|
648
|
-
const openAiPricing = getOpenAiPricing
|
|
651
|
+
const openAiPricing = resolvePricing(pricingModelIds, getOpenAiPricing);
|
|
649
652
|
if (openAiPricing) {
|
|
650
653
|
const inputCost = nonCachedPrompt * openAiPricing.inputRate;
|
|
651
654
|
const cachedCost = cachedTokens * openAiPricing.cachedRate;
|
|
@@ -655,6 +658,21 @@ function estimateCallCostUsd({
|
|
|
655
658
|
}
|
|
656
659
|
return 0;
|
|
657
660
|
}
|
|
661
|
+
function resolvePricingModelIds(modelId, pricingModelId) {
|
|
662
|
+
if (pricingModelId && pricingModelId !== modelId) {
|
|
663
|
+
return [pricingModelId, modelId];
|
|
664
|
+
}
|
|
665
|
+
return [modelId];
|
|
666
|
+
}
|
|
667
|
+
function resolvePricing(modelIds, resolve) {
|
|
668
|
+
for (const modelId of modelIds) {
|
|
669
|
+
const pricing = resolve(modelId);
|
|
670
|
+
if (pricing) {
|
|
671
|
+
return pricing;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return void 0;
|
|
675
|
+
}
|
|
658
676
|
function estimateOpenAiImageCostUsd({
|
|
659
677
|
pricing,
|
|
660
678
|
responseImages,
|
|
@@ -8466,6 +8484,7 @@ async function runTextCall(params) {
|
|
|
8466
8484
|
const outputAttachments = collectLoggedAttachmentsFromLlmParts(mergedParts, "output");
|
|
8467
8485
|
const costUsd = estimateCallCostUsd({
|
|
8468
8486
|
modelId: modelVersion,
|
|
8487
|
+
pricingModelId: request.model,
|
|
8469
8488
|
tokens: latestUsage,
|
|
8470
8489
|
responseImages,
|
|
8471
8490
|
imageSize: request.imageSize
|
|
@@ -9209,6 +9228,7 @@ async function runToolLoop(request) {
|
|
|
9209
9228
|
const modelCompletedAtMs = Date.now();
|
|
9210
9229
|
const stepCostUsd = estimateCallCostUsd({
|
|
9211
9230
|
modelId: modelVersion,
|
|
9231
|
+
pricingModelId: request.model,
|
|
9212
9232
|
tokens: usageTokens,
|
|
9213
9233
|
responseImages: 0
|
|
9214
9234
|
});
|
|
@@ -9540,6 +9560,7 @@ async function runToolLoop(request) {
|
|
|
9540
9560
|
usageTokens = extractChatGptUsageTokens(response.usage);
|
|
9541
9561
|
const stepCostUsd = estimateCallCostUsd({
|
|
9542
9562
|
modelId: modelVersion,
|
|
9563
|
+
pricingModelId: request.model,
|
|
9543
9564
|
tokens: usageTokens,
|
|
9544
9565
|
responseImages: 0
|
|
9545
9566
|
});
|
|
@@ -9868,6 +9889,7 @@ async function runToolLoop(request) {
|
|
|
9868
9889
|
usageTokens = extractFireworksUsageTokens(response.usage);
|
|
9869
9890
|
const stepCostUsd = estimateCallCostUsd({
|
|
9870
9891
|
modelId: modelVersion,
|
|
9892
|
+
pricingModelId: request.model,
|
|
9871
9893
|
tokens: usageTokens,
|
|
9872
9894
|
responseImages: 0
|
|
9873
9895
|
});
|
|
@@ -10230,6 +10252,7 @@ async function runToolLoop(request) {
|
|
|
10230
10252
|
);
|
|
10231
10253
|
const stepCostUsd = estimateCallCostUsd({
|
|
10232
10254
|
modelId: modelVersion,
|
|
10255
|
+
pricingModelId: request.model,
|
|
10233
10256
|
tokens: usageTokens,
|
|
10234
10257
|
responseImages: 0
|
|
10235
10258
|
});
|