Skip to content

Commit e98120e

Browse files
committed
feat(ai): allow provider-specific numeric fields on UsageTotals.costDetails
The JSDoc promised "loosely typed" costDetails to accommodate provider divergence (BYOK upstream costs, cache discounts, per-tier rates) but the declared shape only allowed two OpenRouter-specific keys, so any other adapter would have been forced to `as any`-cast to report its own breakdown. Add a numeric index signature so additional keys are type-legal without a cast, matching the documented intent. Picked up in CodeRabbit review of TanStack#469.
1 parent 4c5aca1 commit e98120e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/typescript/ai/src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,14 @@ export interface UsageTotals {
829829
* Provider-reported cost breakdown. Loosely typed because providers
830830
* disagree on what to expose (BYOK upstream costs, cache discounts,
831831
* per-tier rates, ...) and locking the shape down would force every
832-
* new adapter to either lie or back-fill.
832+
* new adapter to either lie or back-fill. The named fields are
833+
* whatever OpenRouter currently reports; other adapters may report
834+
* numeric fields under their own keys via the index signature.
833835
*/
834836
costDetails?: {
835837
upstreamInferenceCost?: number | null
836838
cacheDiscount?: number | null
839+
[key: string]: number | null | undefined
837840
}
838841
}
839842

0 commit comments

Comments
 (0)