mirror of
https://github.com/cline/cline.git
synced 2026-09-02 07:42:19 +08:00
fix: restore cost calculation for Anthropic API requests (#7943)
The taskMetrics.totalCost was incorrectly initialized to 0 instead of
undefined in commit 09692d7d3. This broke cost display for providers
like Anthropic that don't return totalCost in their usage chunks.
When totalCost is 0, the fallback to calculateApiCostAnthropic() in
updateApiReqMsg doesn't trigger because the nullish coalescing operator
(??) only falls back for null/undefined, not 0.
By initializing totalCost to undefined:
- Providers that return totalCost (like OpenRouter) use that value
- Providers that don't (like Anthropic) fall back to calculating cost
from token counts and model pricing info
This commit is contained in:
@@ -2708,7 +2708,13 @@ export class Task {
|
||||
await this.postStateToWebview()
|
||||
|
||||
try {
|
||||
const taskMetrics = { cacheWriteTokens: 0, cacheReadTokens: 0, inputTokens: 0, outputTokens: 0, totalCost: 0 }
|
||||
const taskMetrics: {
|
||||
cacheWriteTokens: number
|
||||
cacheReadTokens: number
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
totalCost: number | undefined
|
||||
} = { cacheWriteTokens: 0, cacheReadTokens: 0, inputTokens: 0, outputTokens: 0, totalCost: undefined }
|
||||
|
||||
const abortStream = async (cancelReason: ClineApiReqCancelReason, streamingFailedMessage?: string) => {
|
||||
if (this.diffViewProvider.isEditing) {
|
||||
|
||||
Reference in New Issue
Block a user