[PR #10514] fix(session): enhance compatibility with Anthropic SDK for token usage #13467

Closed
opened 2026-02-16 18:18:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10514

State: closed
Merged: No


What does this PR do?

fix: https://github.com/anomalyco/opencode/issues/7481

The ai-sdk anthropic only read input_tokens and cache_read_input_tokens from message_start block, but a lot of compatible providers only return real tokens in message_delta block, try to read from the metadata anthropic usage.

Since the main branch of the ai-sdk anthropic package has already adopted the v3 protocol, and the usage object in v3 is incompatible with v2, we have decided to fix it on the opencode side.

https://github.com/vercel/ai/blob/%40ai-sdk/anthropic%402.0.57/packages/anthropic/src/anthropic-messages-language-model.ts#L1389

How did you verify your code works?

  1. unit test
  2. build opencode, perform integration testing
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10514 **State:** closed **Merged:** No --- ### What does this PR do? fix: https://github.com/anomalyco/opencode/issues/7481 The ai-sdk anthropic only read input_tokens and cache_read_input_tokens from message_start block, but a lot of compatible providers only return real tokens in message_delta block, try to read from the metadata anthropic usage. Since the main branch of the ai-sdk anthropic package has already adopted the v3 protocol, and the usage object in v3 is incompatible with v2, we have decided to fix it on the opencode side. https://github.com/vercel/ai/blob/%40ai-sdk/anthropic%402.0.57/packages/anthropic/src/anthropic-messages-language-model.ts#L1389 ### How did you verify your code works? 1. unit test 2. build opencode, perform integration testing
yindo added the pull-request label 2026-02-16 18:18:19 -05:00
yindo closed this issue 2026-02-16 18:18:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13467