Skip to content

Issue: Extended thinking tokens (Anthropic) not captured in usage.raw_data #629

Description

@SantiagoDePolonia

Describe the bug
When a request to an Anthropic model uses extended thinking ("thinking": {"type": "adaptive"} with output_config.effort, or the older "thinking": {"type": "enabled", "budget_tokens": N} shape), Anthropic's native API reports a distinct usage.output_tokens_details.thinking_tokens count in its response. GoModel does not capture this into the usage entry's raw_data, so how many output tokens were spent thinking is invisible in GoModel's usage and cost accounting - only the total output_tokens is recorded.

Root cause: anthropicUsage (internal/providers/anthropic/types.go, around lines 99-104) does not parse output_tokens_details at all, so the field is silently dropped at JSON unmarshal time before buildAnthropicRawUsage (internal/providers/anthropic/anthropic.go, around lines 344-356) ever runs. That function currently only extracts cache_creation_input_tokens and cache_read_input_tokens into raw_data.

GoModel version
v0.1.68 (commit 9d54827, built 2026-08-03)

Steps To Reproduce

  1. Start GoModel with an ANTHROPIC_API_KEY configured.
  2. POST to /v1/chat/completions with a Claude model, e.g.:
    { "model": "anthropic/", "max_tokens": 2000, "messages": [...], "thinking": {"type": "adaptive"}, "output_config": {"effort": "high"} }
  3. Inspect the resulting usage entry's raw_data column (e.g. via sqlite: SELECT raw_data FROM usage ORDER BY rowid DESC LIMIT 1;) - it is empty.
  4. For comparison, send the same prompt directly through GoModel's Anthropic passthrough route (/p/anthropic/v1/messages) - the raw upstream response includes usage.output_tokens_details.thinking_tokens, confirming Anthropic does report this distinctly and GoModel is dropping it during translation, not that Anthropic omits it.

Screenshots/Logs
Direct passthrough response for the same kind of prompt:

"usage": {
  "input_tokens": 31,
  "output_tokens": 311,
  "output_tokens_details": {
    "thinking_tokens": 27
  }
}

The corresponding /v1/chat/completions usage entry's raw_data is empty.

Additional context
Fix looks well scoped: add an OutputTokensDetails field (with a ThinkingTokens int, tagged json:"thinking_tokens") to anthropicUsage, and add a corresponding key (for example completion_thinking_tokens) to buildAnthropicRawUsage when present, following the same pattern already used for the two cache-token fields. Good first issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions