mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
941f1daf0b
Remove the StepUsageEvent handler from subscribeSDKEvents. It was calling UpdateUsage() for every individual tool-calling step as it streamed, then updateUsageFromTurnResult() called UpdateUsage() again with TotalUsage (fantasy's own aggregate of all steps). A turn with N tool calls was counting every token N+1 times. Fix updateUsageFromTurnResult to use a single, clean code path: - UpdateUsage() called exactly once per turn using TotalUsage - SetContextTokens() uses FinalUsage.InputTokens only (not +OutputTokens) since input tokens of the last call = actual context window fill; output tokens are the response length, not context occupancy - Estimate fallback no longer early-returns before SetContextTokens Verified with opencode/kimi-k2.5: cost accumulates linearly across simple and multi-step tool-calling turns with no double-counting. anthropic/claude-sonnet-4-6 correctly shows $0.00 for OAuth sessions.