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