The Vercel AI SDK has released an update, version @ai-sdk/openai-compatible@3.0.31, that modifies how usage fields are handled for OpenAI-compatible models. This patch specifically focuses on preserving detailed usage information that providers return in the usage.raw field.
Previously, while the top-level usage object was parsed loosely, nested objects such as prompt_tokens_details and completion_tokens_details were strict. This strictness caused specific details reported by providers, like audio_tokens, image_tokens, and text_tokens, to be discarded. The update ensures that both nested objects and the completion model's usage schema are now parsed loosely, allowing these distinguishing details to be retained.
Key Points
- The Vercel AI SDK version @ai-sdk/openai-compatible@3.0.31 was released.
- The update preserves unmapped usage fields within the
usage.rawobject. - Previously,
prompt_tokens_detailsandcompletion_tokens_detailsobjects were strictly parsed. - This strict parsing led to the loss of provider-specific details such as
audio_tokens,image_tokens, andtext_tokens. - Both nested objects are now parsed loosely, as is the completion model's usage schema.
- Only the
usage.rawfield is affected by this change. - Mapped token counts remain unaffected.
Context
According to the Vercel AI SDK Changelog, the usage.raw field is intended to reflect usage "in the shape that the provider returns." The previous implementation, despite loosely parsing the main usage object, had strict parsing for nested detail fields, leading to data loss for specific token types.
Why It Matters
This update is significant for developers who rely on detailed usage metrics from OpenAI-compatible providers. By preserving specific token counts like audio_tokens or image_tokens, builders gain a more complete understanding of resource consumption, which can inform cost analysis and model optimization strategies.
What To Do
- Review the
usage.rawfield in your applications if you use Vercel AI SDK with OpenAI-compatible providers. - Note that
audio_tokens,image_tokens, andtext_tokensmay now be present inusage.raw. - Compare the detailed usage information now available to previous logs to understand the impact on your specific use cases.
- Update your @ai-sdk/openai-compatible package to version 3.0.31 or later to benefit from these changes.
