Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export function ErrorDetailsDialog({
</span>
<span className="font-mono">{formatTokenAmount(outputTokens)} tokens</span>
</div>
{cacheCreation5mInputTokens && cacheCreation5mInputTokens > 0 && (
{(cacheCreation5mInputTokens ?? 0) > 0 && (
<div className="flex justify-between">
<span className="text-muted-foreground">
{t("logs.billingDetails.cacheWrite5m")}:
Expand All @@ -391,7 +391,7 @@ export function ErrorDetailsDialog({
</span>
</div>
)}
{cacheCreation1hInputTokens && cacheCreation1hInputTokens > 0 && (
{(cacheCreation1hInputTokens ?? 0) > 0 && (
<div className="flex justify-between">
<span className="text-muted-foreground">
{t("logs.billingDetails.cacheWrite1h")}:
Expand All @@ -402,7 +402,7 @@ export function ErrorDetailsDialog({
</span>
</div>
)}
{cacheReadInputTokens && cacheReadInputTokens > 0 && (
{(cacheReadInputTokens ?? 0) > 0 && (
<div className="flex justify-between">
<span className="text-muted-foreground">
{t("logs.billingDetails.cacheRead")}:
Expand Down
29 changes: 13 additions & 16 deletions src/app/[locale]/dashboard/logs/_components/usage-logs-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,19 @@ export function UsageLogsTable({
{t("logs.billingDetails.output")}:{" "}
{formatTokenAmount(log.outputTokens)} tokens
</div>
{log.cacheCreation5mInputTokens &&
log.cacheCreation5mInputTokens > 0 && (
<div>
{t("logs.billingDetails.cacheWrite5m")}:{" "}
{formatTokenAmount(log.cacheCreation5mInputTokens)} tokens
(1.25x)
</div>
)}
{log.cacheCreation1hInputTokens &&
log.cacheCreation1hInputTokens > 0 && (
<div>
{t("logs.billingDetails.cacheWrite1h")}:{" "}
{formatTokenAmount(log.cacheCreation1hInputTokens)} tokens (2x)
</div>
)}
{log.cacheReadInputTokens && log.cacheReadInputTokens > 0 && (
{(log.cacheCreation5mInputTokens ?? 0) > 0 && (
<div>
{t("logs.billingDetails.cacheWrite5m")}:{" "}
{formatTokenAmount(log.cacheCreation5mInputTokens)} tokens (1.25x)
</div>
)}
{(log.cacheCreation1hInputTokens ?? 0) > 0 && (
<div>
{t("logs.billingDetails.cacheWrite1h")}:{" "}
{formatTokenAmount(log.cacheCreation1hInputTokens)} tokens (2x)
</div>
)}
{(log.cacheReadInputTokens ?? 0) > 0 && (
<div>
{t("logs.billingDetails.cacheRead")}:{" "}
{formatTokenAmount(log.cacheReadInputTokens)} tokens (0.1x)
Expand Down
15 changes: 13 additions & 2 deletions src/app/v1/_lib/proxy/response-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ export class ProxyResponseHandler {
outputTokens: usageMetrics?.output_tokens,
cacheCreationInputTokens: usageMetrics?.cache_creation_input_tokens,
cacheReadInputTokens: usageMetrics?.cache_read_input_tokens,
cacheCreation5mInputTokens: usageMetrics?.cache_creation_5m_input_tokens,
cacheCreation1hInputTokens: usageMetrics?.cache_creation_1h_input_tokens,
cacheTtlApplied: usageMetrics?.cache_ttl ?? null,
providerChain: session.getProviderChain(),
model: session.getCurrentModel() ?? undefined, // ⭐ 更新重定向后的模型
providerId: session.provider?.id, // ⭐ 更新最终供应商ID(重试切换后)
Expand Down Expand Up @@ -897,6 +900,9 @@ export class ProxyResponseHandler {
outputTokens: usageForCost?.output_tokens,
cacheCreationInputTokens: usageForCost?.cache_creation_input_tokens,
cacheReadInputTokens: usageForCost?.cache_read_input_tokens,
cacheCreation5mInputTokens: usageForCost?.cache_creation_5m_input_tokens,
cacheCreation1hInputTokens: usageForCost?.cache_creation_1h_input_tokens,
cacheTtlApplied: usageForCost?.cache_ttl ?? null,
providerChain: session.getProviderChain(),
model: session.getCurrentModel() ?? undefined, // ⭐ 更新重定向后的模型
providerId: session.provider?.id, // ⭐ 更新最终供应商ID(重试切换后)
Expand Down Expand Up @@ -1107,7 +1113,10 @@ export class ProxyResponseHandler {
try {
reader.releaseLock();
} catch (releaseError) {
logger.warn("Failed to release reader lock", { taskId, releaseError });
logger.warn("Failed to release reader lock", {
taskId,
releaseError,
});
}
AsyncTaskManager.cleanup(taskId);
}
Expand Down Expand Up @@ -1422,7 +1431,9 @@ async function updateRequestCostFromUsage(
costMultiplier: number = 1.0
): Promise<void> {
if (!usage) {
logger.warn("[CostCalculation] No usage data, skipping cost update", { messageId });
logger.warn("[CostCalculation] No usage data, skipping cost update", {
messageId,
});
return;
}

Expand Down
Loading