Skip to content

[Bug]: Anthropic thinking_tokens dropped from usage, so reasoning_tokens is always 0 on Chat/Responses #6719

Closed

Description

@daehwanahn

Client or integration

Direct HTTP/API client (also affects pi/omo, which call OCX through openai-completions)

Area

Provider adapter

Summary

For Anthropic routes, thinking_tokens from the upstream usage block is dropped, so OCX always reports zero reasoning tokens on the Chat Completions surface (usage.completion_tokens_details.reasoning_tokens: 0). The responses bridge emits the same 0 default (output_tokens_details.reasoning_tokens).

Thinking itself does run. On the Chat surface, message.reasoning_content is present, and the same prompt sent to /v1/messages returns a thinking block with a non-zero usage.output_tokens_details.thinking_tokens.

Expected: map Anthropic output_tokens_details.thinking_tokens to OcxUsage.reasoningOutputTokens, so Chat and Responses clients report it as reasoning_tokens. Anthropic counts thinking inside output_tokens, which matches OpenAI's reasoning_tokens semantics.

Reproduction

Use a prompt that makes adaptive thinking engage. With trivial prompts the model skips thinking and upstream reports thinking_tokens: 0.

PROMPT="Find the number of ordered pairs (a,b) of positive integers with a,b <= 2000 such that a^2 + b^2 is divisible by 7*13 and gcd(a,b)=1. Give only the integer."
  1. Chat surface:
    POST /v1/chat/completions with {"model":"anthropic/claude-sonnet-5-5","reasoning_effort":"medium","max_tokens":32000,"messages":[{"role":"user","content":PROMPT}]}
    • choices[0].message.reasoning_content: 179 characters (non-empty)
    • usage.completion_tokens: 292
    • usage.completion_tokens_details.reasoning_tokens: 0
  2. Messages surface, same prompt:
    POST /v1/messages with thinking: {type:"adaptive", display:"summarized"}, output_config: {effort:"medium"}
    • content: thinking block, then text
    • usage.output_tokens_details.thinking_tokens: 156

The same pattern shows up on claude-opus-5-5 and claude-haiku-5-5 at high effort (Messages: thinking_tokens 75 and 436). Their Chat-surface value was not captured separately. They take the same adapter path.

Suspected cause

usageFromAnthropic() in src/adapters/anthropic.ts (2.80.0 installed copy, roughly L608-636) maps input_tokens, output_tokens, cache_read_input_tokens and cache_creation_input_tokens. It never reads output_tokens_details.thinking_tokens, so reasoningOutputTokens stays unset. Downstream, src/chat/outbound.ts (L55-56) and src/bridge/internal.ts (L96) fill in the 0 default. The function is unchanged on main and dev as of 2026-10-07.

Possible fix (sketch, untested):

// inside usageFromAnthropic(), after the existing token reads
const details = isAnthropicRecord(usage.output_tokens_details) ? usage.output_tokens_details : undefined;
const thinking = details?.thinking_tokens;
const reasoningOutputTokens =
  typeof thinking === "number" && Number.isFinite(thinking) && thinking >= 0 ? thinking : undefined;

return {
  inputTokens,
  outputTokens: output,
  ...(reasoningOutputTokens !== undefined ? { reasoningOutputTokens } : {}),
  ...(hasCache ? { /* unchanged */ } : {}),
};

Not verified: whether mergeAnthropicUsage carries output_tokens_details through streaming message_delta frames. The streaming path may need the same field merged.

Version

2.80.0 (npm latest at time of report)

Operating system

Windows 11 (10.0.26200)

Provider and model

anthropic (OAuth) / claude-sonnet-5-5 (also claude-opus-5-5, claude-haiku-5-5)

Logs or error output

# /v1/chat/completions, anthropic/claude-sonnet-5-5, reasoning_effort=medium
reasoning_content chars 179
usage {"prompt_tokens":107,"completion_tokens":292,"completion_tokens_details":{"reasoning_tokens":0}}

# /v1/messages, same prompt, effort=medium
blocks ["thinking","text"]  usage.output_tokens_details.thinking_tokens 156

Impact

Chat and Responses clients can't tell whether Claude reasoned, and usage or cost reporting shows zero reasoning for every Anthropic route. While comparing models we first concluded that Sonnet 5.5 was not reasoning at all. That conclusion was wrong and came from this zero.

Checks

Activity

  1. added
    bug
    provider
    on Oct 7, 2026
  2. Ingwannu commented on Oct 8, 2026

    @Ingwannu
    Owner

    Independently reproduced against dev bbab02a and opened draft fix #6721 at e0f539a. The mapper drops this optional breakdown; the existing streaming cumulative merge already retains the final message_delta object, so the fix needs no second streaming merge rule. Anthropic's official usage contract confirms thinking_tokens is a subset of output_tokens, not additional output.

    Final regression on unchanged source:10pass/8fail. Patched focused suite:150pass/0fail(1035assertions,7files), covering JSON/SSE Chat/Responses, cumulative final usage, EOF terminal, refusal/error, explicit zero and malformed optional detail without total/cache changes. Structure/diff checks pass. Whole-root typecheck hit the180s cgroup deadline and remains unverified; docs build/broader suite/current-head CI and independent review are outstanding, so this is Draft, not a landed/released fix. No live provider call, security/privacy scan or runtime modification. Your diagnosis/projection is credited in the commit.

  3. lidge-jun commented on Oct 8, 2026

    @lidge-jun
    Owner

    Fixed by #6721 (merged to dev as 1a8377d). Anthropic's reported usage.output_tokens_details.thinking_tokens is now carried through as reasoning_tokens in translated Responses and Chat usage, for buffered and streamed replies. Output totals and spend are unchanged because thinking tokens are already a subset of output_tokens. Thanks for the clear report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugprovider

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions