Skip to content

Commit 1020c62

Browse files
hannesrudolphdaniel-lxs
authored andcommitted
fix: revert cost calculation for Claude Code provider
- Only use cost_usd from CLI response when provided - Default to 0 when CLI doesn't provide cost (e.g., subscription users) - Don't calculate cost based on token usage as it may not apply to all users
1 parent 0e2306b commit 1020c62

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

src/api/providers/claude-code.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ApiStreamUsageChunk, type ApiStream } from "../transform/stream"
1010
import { runClaudeCode } from "../../integrations/claude-code/run"
1111
import { ClaudeCodeMessage } from "../../integrations/claude-code/types"
1212
import { BaseProvider } from "./base-provider"
13-
import { calculateApiCostAnthropic } from "../../shared/cost"
1413

1514
export class ClaudeCodeHandler extends BaseProvider implements ApiHandler {
1615
private options: ApiHandlerOptions
@@ -133,20 +132,9 @@ export class ClaudeCodeHandler extends BaseProvider implements ApiHandler {
133132
}
134133

135134
if (chunk.type === "result" && "result" in chunk) {
136-
// Use the cost from the CLI if available, otherwise calculate it
137-
if (chunk.cost_usd !== undefined && chunk.cost_usd !== null) {
138-
usage.totalCost = chunk.cost_usd
139-
} else {
140-
// Calculate cost based on token usage and model pricing
141-
const modelInfo = this.getModel().info
142-
usage.totalCost = calculateApiCostAnthropic(
143-
modelInfo,
144-
usage.inputTokens,
145-
usage.outputTokens,
146-
usage.cacheWriteTokens,
147-
usage.cacheReadTokens,
148-
)
149-
}
135+
// Only use the cost from the CLI if provided
136+
// Don't calculate cost as it may be $0 for subscription users
137+
usage.totalCost = chunk.cost_usd ?? 0
150138

151139
yield usage
152140
}

0 commit comments

Comments
 (0)