Skip to content

fix(cohere): record reasoning tokens as completion_reasoning_tokens - #2841

Open
BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
braintrustdata:mainfrom
basil-k-aji-dev:fix/cohere-reasoning-tokens
Open

BASIL K AJI (basil-k-aji-dev) wants to merge 1 commit into
braintrustdata:mainfrom
basil-k-aji-dev:fix/cohere-reasoning-tokens

Conversation

@basil-k-aji-dev

Copy link
Copy Markdown

Summary

The Cohere instrumentation logged reasoning tokens under the metric name reasoning_tokens. The canonical name, read by Braintrust for cost and usage and used by every other JS provider (anthropic, google-genai, openai-agents, langchain, mastra and others), is completion_reasoning_tokens, as in #2813 for Genkit. mergeUsageMetrics now emits completion_reasoning_tokens and no longer emits reasoning_tokens. The input aliases (thinkingTokens, reasoningTokens and their snake_case forms) are handled as before, and zero values are still recorded.

Tests

In cohere-instrumentation.test.ts the two existing reasoning_tokens expectations now use the canonical name, .not.toHaveProperty("reasoning_tokens") is added on the aggregated stream metrics, and a new test covers a usage that reports thinkingTokens. The expectation in e2e/scenarios/cohere-instrumentation/assertions.ts is updated too.

  • Without the change: 3 tests fail (reasoning_tokens: 6 where completion_reasoning_tokens: 6 is expected, and undefined for the new test).
  • With the change: the file's 7 tests pass and the whole providers directory passes (57 files, 1373 tests). check:typings, lint and the formatting check are clean, and validate-changesets passes.
  • Emitting both names, or a misspelt key, each fail the tests.

Not covered

The e2e thinking assertion sits behind supportsThinking, which is false for every Cohere scenario spec today, so the e2e edit is not exercised by CI. I did not run the e2e scenarios.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant