Delete src/api/providers/utils/USAGE_NORMALIZATION.md

This commit is contained in:
Daniel 2026-02-11 22:06:41 -05:00 committed by GitHub
parent ba08cc7420
commit 1bd58e034c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,54 +0,0 @@
# Usage Normalization (AI SDK Providers)
This folder centralizes usage/cache normalization for AI-SDK-backed providers.
## Canonical Contract
The normalizer derives a canonical usage shape before emitting stream chunks:
- `inputTokensTotal`
- `inputTokensNonCached` (optional)
- `outputTokens`
- `cacheWriteTokens`
- `cacheReadTokens`
- `reasoningTokens` (optional)
- `totalCostCandidate` (optional, provider-reported)
`ApiStreamUsageChunk` then carries:
- `inputTokens` (always total input tokens)
- `nonCachedInputTokens?`
- `outputTokens`
- `cacheWriteTokens?`
- `cacheReadTokens?`
- `reasoningTokens?`
- `totalCost?`
## Precedence Policy
For each metric, extraction precedence is:
1. `providerMetadata`
2. AI SDK `usage`
3. `usage.raw` fallback
This is implemented in `normalize-provider-usage.ts`.
## Profiles
`usage-profiles.ts` defines per-provider extraction profiles:
- The profile specifies candidate paths per metric for `providerMetadata`, `usage`, and `raw`.
- Profiles should contain field mapping only (no provider-specific arithmetic).
- Exceptions (e.g., custom pricing behavior) should be applied at call sites via `totalCostOverride`.
## New Provider Checklist
1. Add/confirm a profile in `usage-profiles.ts`.
2. Wire provider usage handling to `normalizeProviderUsage(...)`.
3. Ensure `inputTokens` emitted to stream remains total input tokens.
4. Add/extend provider usage tests for:
- first-turn cache write heavy payload
- second-turn cache read heavy payload
- metadata vs usage conflicts
5. If provider has custom pricing logic, pass `totalCostOverride` explicitly and test it.