|
1 | 1 | # @tanstack/ai-devtools-core |
2 | 2 |
|
| 3 | +## 0.4.4 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- [#242](https://github.com/TanStack/ai/pull/242) [`c251038`](https://github.com/TanStack/ai/commit/c251038c6d8aa84e498f89e314ce5bb233bc689f) - Enhanced token usage reporting for every provider. |
| 8 | + |
| 9 | + `TokenUsage` is now the single canonical run-usage type. It is defined once in |
| 10 | + `@tanstack/ai-event-client` (the dependency-free leaf package) and re-exported by |
| 11 | + `@tanstack/ai`, so the two packages can no longer drift. It carries optional |
| 12 | + detailed breakdowns alongside the core token counts: `promptTokensDetails` / |
| 13 | + `completionTokensDetails` (cached, reasoning, audio, and per-modality tokens), |
| 14 | + `durationSeconds` for duration-billed models (e.g. Whisper transcription), |
| 15 | + `providerUsageDetails` for provider-specific metrics, and `cost` / `costDetails` |
| 16 | + for provider-reported cost — so a single `usage` shape covers counts, detailed |
| 17 | + breakdowns, and cost. |
| 18 | + |
| 19 | + `TokenUsage` is generic over its provider details bag — |
| 20 | + `TokenUsage<TProviderDetails = ProviderUsageDetails>` — so adapters return a |
| 21 | + strongly-typed `providerUsageDetails` (e.g. `TokenUsage<AnthropicProviderUsageDetails>`) |
| 22 | + while generic consumers keep the open-record default. The default, |
| 23 | + `ProviderUsageDetails` (`Record<string, NonNullable<unknown>>`), is now exported and |
| 24 | + uses non-nullish values rather than `unknown` so `TokenUsage` stays assignable across |
| 25 | + JSON-serialization boundaries (e.g. TanStack Start server-fn return types). Each |
| 26 | + provider's usage |
| 27 | + extractor now returns `undefined` (rather than fabricating zeroed totals) when |
| 28 | + the provider reports no usage object, so an absent `usage` is distinguishable |
| 29 | + from a genuine zero-token run. |
| 30 | + |
| 31 | + `@tanstack/ai` still exports `UsageTotals` as a `@deprecated` alias of |
| 32 | + `TokenUsage` for backward compatibility; it will be removed in a future release. |
| 33 | + |
| 34 | + Detailed usage is extracted in one place per SDK surface: OpenAI-compatible |
| 35 | + providers (OpenAI, Grok, Groq) share the extractors in `@tanstack/openai-base`, |
| 36 | + while Anthropic, Gemini, Ollama, and OpenRouter normalize their own provider |
| 37 | + usage. The devtools surface cached and reasoning token badges per iteration. |
| 38 | + |
| 39 | + Usage is now unified across **every modality**, not just text/chat. Image, audio, |
| 40 | + and text-to-speech results report the same canonical `TokenUsage` (with |
| 41 | + per-modality breakdowns) instead of a minimal `inputTokens`/`outputTokens` shape: |
| 42 | + - `ImageGenerationResult.usage`, `AudioGenerationResult.usage`, and the new |
| 43 | + `TTSResult.usage` are now typed as `TokenUsage`. **Breaking:** consumers of |
| 44 | + these fields should read `promptTokens`/`completionTokens` instead of |
| 45 | + `inputTokens`/`outputTokens`. `@tanstack/ai-event-client`'s `ImageUsage` is now |
| 46 | + a `@deprecated` alias of `TokenUsage`. |
| 47 | + - OpenAI/Grok image generation surface the text-vs-image input token breakdown |
| 48 | + (`promptTokensDetails`), Gemini image/audio/TTS now surface their full |
| 49 | + `usageMetadata` (previously dropped), and OpenRouter image generation surfaces |
| 50 | + the chat usage it already returns. |
| 51 | + - Bug fixes: Ollama no longer produces `NaN` totals or discards duration-only |
| 52 | + usage; Anthropic defaults missing `output_tokens` and no longer emits empty |
| 53 | + `promptTokensDetails`/`providerUsageDetails` objects; OpenAI GPT-4o |
| 54 | + transcription reads the real audio/text input token breakdown and never falls |
| 55 | + back to duration billing. |
| 56 | + |
| 57 | + Cross-adapter usage parity fixes: |
| 58 | + - `PromptTokensDetails`/`CompletionTokensDetails` gain a `documentTokens` field, |
| 59 | + and Gemini now surfaces `DOCUMENT` modality token counts (e.g. PDF inputs) |
| 60 | + instead of silently dropping them. |
| 61 | + - OpenAI-compatible chat (OpenAI/Grok/Groq via `@tanstack/openai-base`) now |
| 62 | + surfaces Predicted-Outputs `acceptedPredictionTokens`/`rejectedPredictionTokens` |
| 63 | + under `providerUsageDetails`, matching the OpenRouter adapter (rejected |
| 64 | + prediction tokens are billed). |
| 65 | + - Grok transcription (`/v1/stt`) now reports `durationSeconds`, mirroring the |
| 66 | + Whisper-1 path in the OpenAI transcription adapter. |
| 67 | + |
| 68 | +- Updated dependencies [[`c251038`](https://github.com/TanStack/ai/commit/c251038c6d8aa84e498f89e314ce5bb233bc689f)]: |
| 69 | + - @tanstack/ai@0.25.0 |
| 70 | + - @tanstack/ai-event-client@0.5.0 |
| 71 | + |
3 | 72 | ## 0.4.3 |
4 | 73 |
|
5 | 74 | ### Patch Changes |
|
0 commit comments