mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-09 22:31:08 +00:00
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
This commit is contained in:
parent
4dd1ae6ca4
commit
76575aa174
1 changed files with 3 additions and 15 deletions
|
|
@ -10,7 +10,6 @@ import { ApiStreamUsageChunk, type ApiStream } from "../transform/stream"
|
|||
import { runClaudeCode } from "../../integrations/claude-code/run"
|
||||
import { ClaudeCodeMessage } from "../../integrations/claude-code/types"
|
||||
import { BaseProvider } from "./base-provider"
|
||||
import { calculateApiCostAnthropic } from "../../shared/cost"
|
||||
|
||||
export class ClaudeCodeHandler extends BaseProvider implements ApiHandler {
|
||||
private options: ApiHandlerOptions
|
||||
|
|
@ -133,20 +132,9 @@ export class ClaudeCodeHandler extends BaseProvider implements ApiHandler {
|
|||
}
|
||||
|
||||
if (chunk.type === "result" && "result" in chunk) {
|
||||
// Use the cost from the CLI if available, otherwise calculate it
|
||||
if (chunk.cost_usd !== undefined && chunk.cost_usd !== null) {
|
||||
usage.totalCost = chunk.cost_usd
|
||||
} else {
|
||||
// Calculate cost based on token usage and model pricing
|
||||
const modelInfo = this.getModel().info
|
||||
usage.totalCost = calculateApiCostAnthropic(
|
||||
modelInfo,
|
||||
usage.inputTokens,
|
||||
usage.outputTokens,
|
||||
usage.cacheWriteTokens,
|
||||
usage.cacheReadTokens,
|
||||
)
|
||||
}
|
||||
// Only use the cost from the CLI if provided
|
||||
// Don't calculate cost as it may be $0 for subscription users
|
||||
usage.totalCost = chunk.cost_usd ?? 0
|
||||
|
||||
yield usage
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue