feat: gemini-2.5-flash-image-preview 文本和图片输出计费

This commit is contained in:
creamlike1024
2025-08-27 21:30:52 +08:00
parent 3401abe4d2
commit a45513a7a6
9 changed files with 111 additions and 20 deletions

View File

@@ -1080,7 +1080,7 @@ export function renderModelPrice(
cacheRatio = 1.0,
image = false,
imageRatio = 1.0,
imageOutputTokens = 0,
imageInputTokens = 0,
webSearch = false,
webSearchCallCount = 0,
webSearchPrice = 0,
@@ -1090,6 +1090,8 @@ export function renderModelPrice(
audioInputSeperatePrice = false,
audioInputTokens = 0,
audioInputPrice = 0,
imageOutputTokens = 0,
imageOutputPrice = 0,
) {
const { ratio: effectiveGroupRatio, label: ratioLabel } = getEffectiveRatio(groupRatio, user_group_ratio);
groupRatio = effectiveGroupRatio;
@@ -1117,9 +1119,9 @@ export function renderModelPrice(
let effectiveInputTokens =
inputTokens - cacheTokens + cacheTokens * cacheRatio;
// Handle image tokens if present
if (image && imageOutputTokens > 0) {
if (image && imageInputTokens > 0) {
effectiveInputTokens =
inputTokens - imageOutputTokens + imageOutputTokens * imageRatio;
inputTokens - imageInputTokens + imageInputTokens * imageRatio;
}
if (audioInputTokens > 0) {
effectiveInputTokens -= audioInputTokens;
@@ -1129,7 +1131,8 @@ export function renderModelPrice(
(audioInputTokens / 1000000) * audioInputPrice * groupRatio +
(completionTokens / 1000000) * completionRatioPrice * groupRatio +
(webSearchCallCount / 1000) * webSearchPrice * groupRatio +
(fileSearchCallCount / 1000) * fileSearchPrice * groupRatio;
(fileSearchCallCount / 1000) * fileSearchPrice * groupRatio +
(imageOutputTokens / 1000000) * imageOutputPrice * groupRatio;
return (
<>
@@ -1164,7 +1167,7 @@ export function renderModelPrice(
)}
</p>
)}
{image && imageOutputTokens > 0 && (
{image && imageInputTokens > 0 && (
<p>
{i18next.t(
'图片输入价格:${{price}} * {{ratio}} = ${{total}} / 1M tokens (图片倍率: {{imageRatio}})',
@@ -1191,17 +1194,26 @@ export function renderModelPrice(
})}
</p>
)}
{imageOutputPrice > 0 && imageOutputTokens > 0 && (
<p>
{i18next.t('图片输出价格:${{price}} * 分组倍率{{ratio}} = ${{total}} / 1M tokens', {
price: imageOutputPrice,
ratio: groupRatio,
total: imageOutputPrice * groupRatio,
})}
</p>
)}
<p></p>
<p>
{(() => {
// 构建输入部分描述
let inputDesc = '';
if (image && imageOutputTokens > 0) {
if (image && imageInputTokens > 0) {
inputDesc = i18next.t(
'(输入 {{nonImageInput}} tokens + 图片输入 {{imageInput}} tokens * {{imageRatio}} / 1M tokens * ${{price}}',
{
nonImageInput: inputTokens - imageOutputTokens,
imageInput: imageOutputTokens,
nonImageInput: inputTokens - imageInputTokens,
imageInput: imageInputTokens,
imageRatio: imageRatio,
price: inputRatioPrice,
},
@@ -1271,6 +1283,16 @@ export function renderModelPrice(
},
)
: '',
imageOutputPrice > 0 && imageOutputTokens > 0
? i18next.t(
' + 图片输出 {{tokenCounts}} tokens * ${{price}} / 1M tokens * 分组倍率{{ratio}}',
{
tokenCounts: imageOutputTokens,
price: imageOutputPrice,
ratio: groupRatio,
},
)
: '',
].join('');
return i18next.t(