From 4a71e0672f7433f2e29df16fa2865f2702a64db2 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sun, 21 Jun 2026 22:07:37 +0900 Subject: fix(openai-stream): add stream_options.include_usage to all requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without stream_options.include_usage, OpenAI-compatible providers omit the usage field from the SSE stream entirely. Umans returned 0 tokens for everything; OpenCode's proxy happened to include usage without it. Now both providers return proper prompt_tokens + completion_tokens. Note: Umans does not report cache_read_tokens or prompt_tokens_details.cached_tokens — cache hit rate will be 0% for Umans regardless. This is a provider limitation, not a parsing issue. --- packages/openai-stream/src/provider.test.ts | 1 + packages/openai-stream/src/stream.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/openai-stream/src/provider.test.ts b/packages/openai-stream/src/provider.test.ts index 7b2d938..434c405 100644 --- a/packages/openai-stream/src/provider.test.ts +++ b/packages/openai-stream/src/provider.test.ts @@ -145,6 +145,7 @@ describe("transformBody", () => { model: "test-model", messages: [{ role: "user", content: "Hello" }], stream: true, + stream_options: { include_usage: true }, temperature: 0.5, max_tokens: 42, }); diff --git a/packages/openai-stream/src/stream.ts b/packages/openai-stream/src/stream.ts index 2916432..e801cc5 100644 --- a/packages/openai-stream/src/stream.ts +++ b/packages/openai-stream/src/stream.ts @@ -69,6 +69,7 @@ export async function* streamChat( model: opts?.model ?? config.model, messages: finalMessages, stream: true, + stream_options: { include_usage: true }, }; if (openaiTools.length > 0) { -- cgit v1.2.3