From 8c60f940bcce41879b2fc5e83cae8808af5892f6 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Tue, 20 Oct 2026 22:50:37 -0500 Subject: [PATCH] refactor(ai): use typed choice.usage in openai-chat parser (#57596) --- packages/ai/src/protocols/openai-chat.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ai/src/protocols/openai-chat.ts b/packages/ai/src/protocols/openai-chat.ts index 6440a78ed01..9ce6f9d9c55 100644 --- a/packages/ai/src/protocols/openai-chat.ts +++ b/packages/ai/src/protocols/openai-chat.ts @@ -1028,10 +1028,9 @@ const step = (state: ParserState, event: OpenAIChatEvent) => const choice = event.choices?.[0] // Moonshot (and a few other OpenAI-compatible providers) attach usage to // `choice.usage` instead of the top-level `usage` field. - const choiceUsage = (choice as unknown as { usage?: OpenAIChatEvent["usage"] })?.usage const usage = mapUsage(event.usage, state.providerMetadataKey) ?? - (choiceUsage ? mapUsage(choiceUsage, state.providerMetadataKey) : undefined) ?? + mapUsage(choice?.usage, state.providerMetadataKey) ?? state.usage const rawFinishReason = choice?.finish_reason const finishReason = rawFinishReason