@discomedia/utils 1.0.61 → 1.0.62
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-frontend.cjs +82 -19
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +82 -19
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +82 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +82 -19
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/types/llm-config.d.ts +3 -3
- package/dist/types/llm-config.d.ts.map +1 -1
- package/dist/types/llm-images.d.ts.map +1 -1
- package/dist/types/llm-openai.d.ts.map +1 -1
- package/dist/types/types/llm-types.d.ts +3 -3
- package/dist/types/types/llm-types.d.ts.map +1 -1
- package/dist/types-frontend/llm-config.d.ts +3 -3
- package/dist/types-frontend/llm-config.d.ts.map +1 -1
- package/dist/types-frontend/llm-images.d.ts.map +1 -1
- package/dist/types-frontend/llm-openai.d.ts.map +1 -1
- package/dist/types-frontend/types/llm-types.d.ts +3 -3
- package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1150,6 +1150,8 @@ function isOpenRouterModel(model) {
|
|
|
1150
1150
|
'openai/gpt-5-mini',
|
|
1151
1151
|
'openai/gpt-5-nano',
|
|
1152
1152
|
'openai/gpt-5.1',
|
|
1153
|
+
'openai/gpt-5.4',
|
|
1154
|
+
'openai/gpt-5.4-pro',
|
|
1153
1155
|
'openai/gpt-5.2',
|
|
1154
1156
|
'openai/gpt-5.2-pro',
|
|
1155
1157
|
'openai/gpt-5.1-codex',
|
|
@@ -8826,78 +8828,107 @@ OpenAI.Videos = Videos;
|
|
|
8826
8828
|
|
|
8827
8829
|
// llm-openai-config.ts
|
|
8828
8830
|
const DEFAULT_MODEL = 'gpt-4.1-mini';
|
|
8829
|
-
|
|
8831
|
+
const GPT_5_4_HIGH_CONTEXT_THRESHOLD_TOKENS = 272_000;
|
|
8832
|
+
const GPT_5_4_HIGH_CONTEXT_INPUT_MULTIPLIER = 2;
|
|
8833
|
+
const GPT_5_4_HIGH_CONTEXT_OUTPUT_MULTIPLIER = 1.5;
|
|
8834
|
+
/** Token costs in USD per 1M tokens. Last updated Mar 2026. */
|
|
8830
8835
|
const openAiModelCosts = {
|
|
8831
8836
|
'gpt-4o': {
|
|
8832
8837
|
inputCost: 2.5 / 1_000_000,
|
|
8838
|
+
cacheHitCost: 1.25 / 1_000_000,
|
|
8833
8839
|
outputCost: 10 / 1_000_000,
|
|
8834
8840
|
},
|
|
8835
8841
|
'gpt-4o-mini': {
|
|
8836
8842
|
inputCost: 0.15 / 1_000_000,
|
|
8843
|
+
cacheHitCost: 0.075 / 1_000_000,
|
|
8837
8844
|
outputCost: 0.6 / 1_000_000,
|
|
8838
8845
|
},
|
|
8839
8846
|
'o1-mini': {
|
|
8840
8847
|
inputCost: 1.1 / 1_000_000,
|
|
8848
|
+
cacheHitCost: 0.55 / 1_000_000,
|
|
8841
8849
|
outputCost: 4.4 / 1_000_000,
|
|
8842
8850
|
},
|
|
8843
8851
|
'o1': {
|
|
8844
8852
|
inputCost: 15 / 1_000_000,
|
|
8853
|
+
cacheHitCost: 7.5 / 1_000_000,
|
|
8845
8854
|
outputCost: 60 / 1_000_000,
|
|
8846
8855
|
},
|
|
8847
8856
|
'o3-mini': {
|
|
8848
8857
|
inputCost: 1.1 / 1_000_000,
|
|
8858
|
+
cacheHitCost: 0.55 / 1_000_000,
|
|
8849
8859
|
outputCost: 4.4 / 1_000_000,
|
|
8850
8860
|
},
|
|
8851
8861
|
'o3': {
|
|
8852
8862
|
inputCost: 2 / 1_000_000,
|
|
8863
|
+
cacheHitCost: 0.5 / 1_000_000,
|
|
8853
8864
|
outputCost: 8 / 1_000_000,
|
|
8854
8865
|
},
|
|
8855
8866
|
'gpt-4.1': {
|
|
8856
8867
|
inputCost: 2 / 1_000_000,
|
|
8868
|
+
cacheHitCost: 0.5 / 1_000_000,
|
|
8857
8869
|
outputCost: 8 / 1_000_000,
|
|
8858
8870
|
},
|
|
8859
8871
|
'gpt-4.1-mini': {
|
|
8860
8872
|
inputCost: 0.4 / 1_000_000,
|
|
8873
|
+
cacheHitCost: 0.1 / 1_000_000,
|
|
8861
8874
|
outputCost: 1.6 / 1_000_000,
|
|
8862
8875
|
},
|
|
8863
8876
|
'gpt-4.1-nano': {
|
|
8864
8877
|
inputCost: 0.1 / 1_000_000,
|
|
8878
|
+
cacheHitCost: 0.025 / 1_000_000,
|
|
8865
8879
|
outputCost: 0.4 / 1_000_000,
|
|
8866
8880
|
},
|
|
8867
8881
|
'gpt-5': {
|
|
8868
8882
|
inputCost: 1.25 / 1_000_000,
|
|
8883
|
+
cacheHitCost: 0.125 / 1_000_000,
|
|
8869
8884
|
outputCost: 10 / 1_000_000,
|
|
8870
8885
|
},
|
|
8871
8886
|
'gpt-5-mini': {
|
|
8872
8887
|
inputCost: 0.25 / 1_000_000,
|
|
8888
|
+
cacheHitCost: 0.025 / 1_000_000,
|
|
8873
8889
|
outputCost: 2 / 1_000_000,
|
|
8874
8890
|
},
|
|
8875
8891
|
'gpt-5-nano': {
|
|
8876
8892
|
inputCost: 0.05 / 1_000_000,
|
|
8893
|
+
cacheHitCost: 0.005 / 1_000_000,
|
|
8877
8894
|
outputCost: 0.4 / 1_000_000,
|
|
8878
8895
|
},
|
|
8879
8896
|
'gpt-5.1': {
|
|
8880
8897
|
inputCost: 1.25 / 1_000_000,
|
|
8898
|
+
cacheHitCost: 0.125 / 1_000_000,
|
|
8881
8899
|
outputCost: 10 / 1_000_000,
|
|
8882
8900
|
},
|
|
8901
|
+
'gpt-5.4': {
|
|
8902
|
+
inputCost: 2.5 / 1_000_000,
|
|
8903
|
+
cacheHitCost: 0.25 / 1_000_000,
|
|
8904
|
+
outputCost: 15 / 1_000_000,
|
|
8905
|
+
},
|
|
8906
|
+
'gpt-5.4-pro': {
|
|
8907
|
+
inputCost: 30 / 1_000_000,
|
|
8908
|
+
outputCost: 180 / 1_000_000,
|
|
8909
|
+
},
|
|
8883
8910
|
'gpt-5.2': {
|
|
8884
|
-
inputCost: 1.
|
|
8885
|
-
|
|
8911
|
+
inputCost: 1.75 / 1_000_000,
|
|
8912
|
+
cacheHitCost: 0.175 / 1_000_000,
|
|
8913
|
+
outputCost: 14 / 1_000_000,
|
|
8886
8914
|
},
|
|
8887
8915
|
'gpt-5.2-pro': {
|
|
8888
|
-
inputCost:
|
|
8889
|
-
outputCost:
|
|
8916
|
+
inputCost: 21 / 1_000_000,
|
|
8917
|
+
outputCost: 168 / 1_000_000,
|
|
8890
8918
|
},
|
|
8891
8919
|
'gpt-5.1-codex': {
|
|
8892
|
-
inputCost: 1.
|
|
8893
|
-
|
|
8920
|
+
inputCost: 1.25 / 1_000_000,
|
|
8921
|
+
cacheHitCost: 0.125 / 1_000_000,
|
|
8922
|
+
outputCost: 10 / 1_000_000,
|
|
8894
8923
|
},
|
|
8895
8924
|
'gpt-5.1-codex-max': {
|
|
8896
|
-
inputCost: 1.
|
|
8897
|
-
|
|
8925
|
+
inputCost: 1.25 / 1_000_000,
|
|
8926
|
+
cacheHitCost: 0.125 / 1_000_000,
|
|
8927
|
+
outputCost: 10 / 1_000_000,
|
|
8898
8928
|
},
|
|
8899
8929
|
'o4-mini': {
|
|
8900
8930
|
inputCost: 1.1 / 1_000_000,
|
|
8931
|
+
cacheHitCost: 0.275 / 1_000_000,
|
|
8901
8932
|
outputCost: 4.4 / 1_000_000,
|
|
8902
8933
|
},
|
|
8903
8934
|
};
|
|
@@ -8913,6 +8944,9 @@ const deepseekModelCosts = {
|
|
|
8913
8944
|
outputCost: 2.19 / 1_000_000, // $2.19 per 1M tokens
|
|
8914
8945
|
},
|
|
8915
8946
|
};
|
|
8947
|
+
function shouldUseGPT54HighContextPricing(model, inputTokens) {
|
|
8948
|
+
return (model === 'gpt-5.4' || model === 'gpt-5.4-pro') && inputTokens > GPT_5_4_HIGH_CONTEXT_THRESHOLD_TOKENS;
|
|
8949
|
+
}
|
|
8916
8950
|
/** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
|
|
8917
8951
|
const openAiImageCosts = {
|
|
8918
8952
|
'gpt-image-1': 0.0075, // $0.0075 per image for gpt-image-1
|
|
@@ -8941,8 +8975,8 @@ function calculateImageCost(model, imageCount) {
|
|
|
8941
8975
|
* @param model The name of the language model. Supported models are listed in the `openAiModelCosts` and `deepseekModelCosts` objects.
|
|
8942
8976
|
* @param inputTokens The number of input tokens passed to the language model.
|
|
8943
8977
|
* @param outputTokens The number of output tokens generated by the language model.
|
|
8944
|
-
* @param reasoningTokens The number of output tokens generated by the language model for reasoning.
|
|
8945
|
-
* @param cacheHitTokens The number of input tokens
|
|
8978
|
+
* @param reasoningTokens The number of output tokens generated by the language model for reasoning.
|
|
8979
|
+
* @param cacheHitTokens The number of input tokens billed at cached-input rates.
|
|
8946
8980
|
* @returns The cost of calling the language model in USD.
|
|
8947
8981
|
*/
|
|
8948
8982
|
function calculateCost(provider, model, inputTokens, outputTokens, reasoningTokens, cacheHitTokens) {
|
|
@@ -8957,12 +8991,18 @@ function calculateCost(provider, model, inputTokens, outputTokens, reasoningToke
|
|
|
8957
8991
|
const modelCosts = provider === 'deepseek' ? deepseekModelCosts[model] : openAiModelCosts[model];
|
|
8958
8992
|
if (!modelCosts)
|
|
8959
8993
|
return 0;
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
8994
|
+
const boundedCacheHitTokens = Math.min(Math.max(cacheHitTokens || 0, 0), inputTokens);
|
|
8995
|
+
let inputCost = inputTokens * modelCosts.inputCost;
|
|
8996
|
+
if (typeof modelCosts.cacheHitCost === 'number' && boundedCacheHitTokens > 0) {
|
|
8997
|
+
inputCost = boundedCacheHitTokens * modelCosts.cacheHitCost + (inputTokens - boundedCacheHitTokens) * modelCosts.inputCost;
|
|
8998
|
+
}
|
|
8999
|
+
let outputCost = outputTokens * modelCosts.outputCost;
|
|
9000
|
+
let reasoningCost = (reasoningTokens || 0) * modelCosts.outputCost;
|
|
9001
|
+
if (provider === 'openai' && shouldUseGPT54HighContextPricing(model, inputTokens)) {
|
|
9002
|
+
inputCost *= GPT_5_4_HIGH_CONTEXT_INPUT_MULTIPLIER;
|
|
9003
|
+
outputCost *= GPT_5_4_HIGH_CONTEXT_OUTPUT_MULTIPLIER;
|
|
9004
|
+
reasoningCost *= GPT_5_4_HIGH_CONTEXT_OUTPUT_MULTIPLIER;
|
|
9005
|
+
}
|
|
8966
9006
|
return inputCost + outputCost + reasoningCost;
|
|
8967
9007
|
}
|
|
8968
9008
|
|
|
@@ -9360,6 +9400,8 @@ const isSupportedModel = (model) => {
|
|
|
9360
9400
|
'gpt-5-mini',
|
|
9361
9401
|
'gpt-5-nano',
|
|
9362
9402
|
'gpt-5.1',
|
|
9403
|
+
'gpt-5.4',
|
|
9404
|
+
'gpt-5.4-pro',
|
|
9363
9405
|
'gpt-5.2',
|
|
9364
9406
|
'gpt-5.2-pro',
|
|
9365
9407
|
'gpt-5.1-codex',
|
|
@@ -9386,6 +9428,8 @@ function supportsTemperature(model) {
|
|
|
9386
9428
|
'gpt-5-mini',
|
|
9387
9429
|
'gpt-5-nano',
|
|
9388
9430
|
'gpt-5.1',
|
|
9431
|
+
'gpt-5.4',
|
|
9432
|
+
'gpt-5.4-pro',
|
|
9389
9433
|
'gpt-5.2',
|
|
9390
9434
|
'gpt-5.2-pro',
|
|
9391
9435
|
'gpt-5.1-codex',
|
|
@@ -9413,6 +9457,8 @@ function isGPT5Model(model) {
|
|
|
9413
9457
|
'gpt-5-mini',
|
|
9414
9458
|
'gpt-5-nano',
|
|
9415
9459
|
'gpt-5.1',
|
|
9460
|
+
'gpt-5.4',
|
|
9461
|
+
'gpt-5.4-pro',
|
|
9416
9462
|
'gpt-5.2',
|
|
9417
9463
|
'gpt-5.2-pro',
|
|
9418
9464
|
'gpt-5.1-codex',
|
|
@@ -9420,6 +9466,12 @@ function isGPT5Model(model) {
|
|
|
9420
9466
|
];
|
|
9421
9467
|
return gpt5Models.includes(model);
|
|
9422
9468
|
}
|
|
9469
|
+
function supportsStructuredOutputs(model) {
|
|
9470
|
+
return normalizeModelName(model) !== 'gpt-5.4-pro';
|
|
9471
|
+
}
|
|
9472
|
+
function supportsDistillation(model) {
|
|
9473
|
+
return normalizeModelName(model) !== 'gpt-5.4-pro';
|
|
9474
|
+
}
|
|
9423
9475
|
/**
|
|
9424
9476
|
* Makes a call to OpenAI's Responses API for more advanced use cases with built-in tools.
|
|
9425
9477
|
*
|
|
@@ -9462,8 +9514,15 @@ const makeResponsesAPICall = async (input, options = {}) => {
|
|
|
9462
9514
|
input,
|
|
9463
9515
|
...cleanOptions,
|
|
9464
9516
|
};
|
|
9517
|
+
if (requestBody.text?.format?.type === 'json_schema' && !supportsStructuredOutputs(normalizedModel)) {
|
|
9518
|
+
throw new Error(`Model ${normalizedModel} does not support structured outputs`);
|
|
9519
|
+
}
|
|
9520
|
+
if (requestBody.store && !supportsDistillation(normalizedModel)) {
|
|
9521
|
+
throw new Error(`Model ${normalizedModel} does not support distillation`);
|
|
9522
|
+
}
|
|
9465
9523
|
// Make the API call to the Responses endpoint
|
|
9466
9524
|
const response = await openai.responses.create(requestBody);
|
|
9525
|
+
const cacheHitTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
|
|
9467
9526
|
// Extract tool calls from the output
|
|
9468
9527
|
const toolCalls = response.output
|
|
9469
9528
|
?.filter((item) => item.type === 'function_call')
|
|
@@ -9503,7 +9562,8 @@ const makeResponsesAPICall = async (input, options = {}) => {
|
|
|
9503
9562
|
reasoning_tokens: response.usage?.output_tokens_details?.reasoning_tokens || 0,
|
|
9504
9563
|
provider: 'openai',
|
|
9505
9564
|
model: normalizedModel,
|
|
9506
|
-
|
|
9565
|
+
cache_hit_tokens: cacheHitTokens,
|
|
9566
|
+
cost: calculateCost('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0, cacheHitTokens),
|
|
9507
9567
|
},
|
|
9508
9568
|
tool_calls: toolCalls,
|
|
9509
9569
|
...(codeInterpreterOutputs ? { code_interpreter_outputs: codeInterpreterOutputs } : {}),
|
|
@@ -9535,7 +9595,8 @@ const makeResponsesAPICall = async (input, options = {}) => {
|
|
|
9535
9595
|
reasoning_tokens: response.usage?.output_tokens_details?.reasoning_tokens || 0,
|
|
9536
9596
|
provider: 'openai',
|
|
9537
9597
|
model: normalizedModel,
|
|
9538
|
-
|
|
9598
|
+
cache_hit_tokens: cacheHitTokens,
|
|
9599
|
+
cost: calculateCost('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0, cacheHitTokens),
|
|
9539
9600
|
},
|
|
9540
9601
|
tool_calls: toolCalls,
|
|
9541
9602
|
...(codeInterpreterOutputs ? { code_interpreter_outputs: codeInterpreterOutputs } : {}),
|
|
@@ -9667,6 +9728,8 @@ const MULTIMODAL_VISION_MODELS = new Set([
|
|
|
9667
9728
|
'gpt-5-mini',
|
|
9668
9729
|
'gpt-5-nano',
|
|
9669
9730
|
'gpt-5.1',
|
|
9731
|
+
'gpt-5.4',
|
|
9732
|
+
'gpt-5.4-pro',
|
|
9670
9733
|
'gpt-5.2',
|
|
9671
9734
|
'gpt-5.2-pro',
|
|
9672
9735
|
'gpt-5.1-codex',
|