Commit 9c27ca8
feat: type ResultMessage.model_usage as dict[str, ModelUsage] (#1143)
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.
Co-authored-by: Claude <noreply@anthropic.com>1 parent 07b46c6 commit 9c27ca8
2 files changed
Lines changed: 28 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
555 | 556 | | |
556 | 557 | | |
557 | 558 | | |
| 559 | + | |
558 | 560 | | |
559 | 561 | | |
560 | 562 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1197 | 1197 | | |
1198 | 1198 | | |
1199 | 1199 | | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
1200 | 1225 | | |
1201 | 1226 | | |
1202 | 1227 | | |
| |||
1212 | 1237 | | |
1213 | 1238 | | |
1214 | 1239 | | |
1215 | | - | |
| 1240 | + | |
1216 | 1241 | | |
1217 | 1242 | | |
1218 | 1243 | | |
| |||
0 commit comments