OpenAI API · api · fg-0142

Streamed chat completions report no token usage, so cost tracking records zero

If you see chunk.usage is null on every streamed chunk, the cause and the fix for OpenAI API are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
chunk.usage is null on every streamed chunkToken counters stay at zero for streamed requests only
Cause
Streaming responses omit usage unless stream_options.include_usage is set, and then only a final extra chunk with empty choices carries the totals. An interrupted stream never sends it.
Fix
Set include_usage, read usage from the last chunk, and guard code that indexes choices[0].
Apply
const stream = await client.chat.completions.create({ model, messages, stream: true, stream_options: { include_usage: true } }); for await (const chunk of stream) { if (chunk.usage) recordUsage(chunk.usage); const delta = chunk.choices[0]?.delta?.content; }
Affected
OpenAI Chat Completions streaming, checked October 2026
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun