mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-13 05:05:52 +00:00
77a80680ff
CalculateCost previously ignored usage.ThinkingTokens entirely, causing cost underestimation for every reasoning-capable model (OpenAI o3/o4-mini, Codex/GPT-5, Anthropic extended thinking). Thinking tokens are reported by providers as a sub-count of completion tokens — OpenAI completion_tokens already includes reasoning_tokens, Codex output_tokens likewise, and Anthropic output_tokens counts thinking at the output rate. Default behaviour (ReasoningPerMillion=0) now matches provider billing semantics: full CompletionTokens priced at OutputPerMillion, no double-counting. When ReasoningPerMillion is explicitly configured, the completion bucket is split into visible output + thinking and each priced independently. Defensive clamp to zero when Anthropic's thinkingChars/4 estimate exceeds reported OutputTokens. Adds ReasoningPerMillion field to ModelPricing and 7 regression tests covering the double-count gate, distinct-rate split, Anthropic estimate overrun, and backward compatibility for non-reasoning models.