SIGN IN SIGN UP

fix: preserve complete Cohere Chat raw usage objects (#19777)

## Background

Cohere Chat JSON and SSE results discarded billed, cached, and
additional provider usage data from final-step usage.raw, preventing
access to billing and cache information.

## Root Cause

Both response paths passed only usage.tokens to the converter, while
strict schemas removed undeclared fields. Live provider-boundary
comparisons confirmed normalized counts were correct but usage.raw was
flattened and incomplete; review also confirmed billed_units must remain
optional for streaming compatibility.

## Summary

The Cohere provider now loosely parses complete usage objects, passes
them through JSON and SSE paths, normalizes counts from usage.tokens,
returns the complete object as raw, permits absent/null billed_units,
and includes a patch changeset.

## Testing

JSON and SSE regressions cover billed units, cached tokens, unknown
top-level and nested fields, unchanged normalized counts, known-field
validation, and streaming usage without billed units. Cohere Node and
Edge suites each passed 81 tests; workspace tests, type checking,
formatting, linting, and targeted builds passed.

## End-to-end Validation

- `pnpm -C examples/ai-functions exec tsx
src/reproduction/issue-19736-cohere-raw-usage.ts` via immutable replay —
live generateText and streamText reproduction exited 0 with no bug
signal.

## Related Issues

Fixes #19736

Closes #19753

---------

Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com>
Co-authored-by: gr2m <39992+gr2m@users.noreply.github.com>
Co-authored-by: ai-sdk-factory[bot] <305873210+ai-sdk-factory[bot]@users.noreply.github.com>
A
ai-sdk-factory[bot] committed
0599400dd48dcdb6a39ef7bb486b380b0656818e
Parent: 1f7835c
Committed by GitHub <noreply@github.com> on 8/26/2026, 8:45:17 PM