Skip to content

Commit e6d7eb4

Browse files
committed
fix: session total token accounting for ai sdk anthropic, bedrock, and vertex
1 parent ceb2bf6 commit e6d7eb4

1 file changed

Lines changed: 1 addition & 13 deletions

File tree

packages/opencode/src/session/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { ModelID, ProviderID } from "@/provider/schema"
3232
import { Permission } from "@/permission"
3333
import { Global } from "@/global"
3434
import type { LanguageModelV2Usage } from "@ai-sdk/provider"
35-
import { iife } from "@/util/iife"
3635
import { Effect, Layer, Scope, ServiceMap } from "effect"
3736
import { makeRuntime } from "@/effect/run-service"
3837

@@ -270,18 +269,7 @@ export namespace Session {
270269
// tokens to get the non-cached input count for separate cost calculation.
271270
const adjustedInputTokens = safe(inputTokens - cacheReadInputTokens - cacheWriteInputTokens)
272271

273-
const total = iife(() => {
274-
// Anthropic doesn't provide total_tokens, also ai sdk will vastly undercount if we
275-
// don't compute from components
276-
if (
277-
input.model.api.npm === "@ai-sdk/anthropic" ||
278-
input.model.api.npm === "@ai-sdk/amazon-bedrock" ||
279-
input.model.api.npm === "@ai-sdk/google-vertex/anthropic"
280-
) {
281-
return adjustedInputTokens + outputTokens + cacheReadInputTokens + cacheWriteInputTokens
282-
}
283-
return input.usage.totalTokens
284-
})
272+
const total = input.usage.totalTokens
285273

286274
const tokens = {
287275
total,

0 commit comments

Comments
 (0)