Skip to content

feat: type ResultMessage.model_usage as dict[str, ModelUsage]#1143

Merged
qing-ant merged 1 commit into
anthropics:mainfrom
benlehrburger-ant:benlehrburger/modelusage-ids
Jul 22, 2026
Merged

feat: type ResultMessage.model_usage as dict[str, ModelUsage]#1143
qing-ant merged 1 commit into
anthropics:mainfrom
benlehrburger-ant:benlehrburger/modelusage-ids

Conversation

@benlehrburger-ant

Copy link
Copy Markdown
Contributor

Adds a ModelUsage TypedDict mirroring the TypeScript SDK's ModelUsage shape and tightens ResultMessage.model_usage from dict[str, Any] to dict[str, ModelUsage]. The value is passed through verbatim from the CLI's modelUsage field, so this is type-only — no runtime behavior change.

The two new NotRequired fields (canonicalModel, provider) are emitted by the CLI once anthropics/claude-cli-internal#50283 lands. They give callers a stable key for their own rate-table lookups across provider-specific model ids and aliases (e.g. Bedrock ARNs → claude-opus-4-7), so cost drift like "Opus 4.6/4.7 priced as 4.5" is detectable client-side. Per-token rates were intentionally left out of this pass (not authoritative); may follow separately with a source marker.

Verification: type-annotation-only; py_compile clean on changed files; existing test_parse_result_message_with_model_usage covers the passthrough shape.

Adds a ModelUsage TypedDict mirroring the TypeScript SDK's ModelUsage
shape and tightens ResultMessage.model_usage from dict[str, Any] to
dict[str, ModelUsage]. The value is passed through verbatim from the
CLI's modelUsage field, so this is a type-only change.

The two new NotRequired fields (canonicalModel, provider) are emitted
by the CLI once anthropics/claude-cli-internal#50283 lands; they give
callers a stable key for their own rate-table lookups across
provider-specific model ids and aliases.

Co-authored-by: benlehrburger-ant <benlehrburger-ant@users.noreply.github.com>

No-Verification-Needed: type-annotation-only (TypedDict + __all__ export), no runtime behavior change
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@4dedce6). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1143   +/-   ##
=======================================
  Coverage        ?   89.97%           
=======================================
  Files           ?       23           
  Lines           ?     4131           
  Branches        ?        0           
=======================================
  Hits            ?     3717           
  Misses          ?      414           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@benlehrburger-ant
benlehrburger-ant marked this pull request as ready for review July 22, 2026 01:50
@qing-ant
qing-ant merged commit 9c27ca8 into anthropics:main Jul 22, 2026
8 checks passed
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.

4 participants