Fix/token usage dto cached write tool use 3586576
Summary
-
Added support for two additional AI token usage types:
- Cache write tokens (
cachedWrite) - Tool use tokens (
toolUse)
- Cache write tokens (
-
This ensures token usage data from AI providers is captured more completely for observability.
Changes
-
Added
cachedWrite: ?intandtoolUse: ?intfields toTokenUsageDtowithNULLdefaults to maintain backward compatibility. -
Updated
StreamedChatMessageInterfaceby adding:setCachedWriteTokenUsage()getCachedWriteTokenUsage()setToolUseTokenUsage()getToolUseTokenUsage()
-
Implemented all four new methods in
StreamedChatMessagewith corresponding private properties. -
Added
$cachedWriteTokenUsageand$toolUseTokenUsageproperties toStreamedChatMessageIterator. -
Updated
StreamedChatMessageIteratorto propagate the new token types through:setTokenUsageFromChunk()setTokenUsageOnChatOutput()
-
Updated
OpenAiBasedProviderClientBase::setChatTokenUsage()to populate:cachedWritefromprompt_tokens_details.cache_write_tokenstoolUsefromcompletion_tokens_details.tool_use_tokens
-
Updated the
cachedfield documentation to clarify that it represents cache read tokens. -
No changes were required in
ai_observability, asDtoBaseMethodsTrait::toArray()automatically includes the new DTO properties viaget_object_vars().