From d8984e8b39a4c5d3dc30c36c6ed66b3912639bc3 Mon Sep 17 00:00:00 2001 From: Ibrahim Ryan Date: Wed, 18 Mar 2026 16:20:56 +0300 Subject: [PATCH] fix: inject stream_options to get usage data from providers Add stream_options: { include_usage: true } to OpenAI-format streaming requests in BaseExecutor. This tells providers to include token usage in the final streaming chunk, fixing token counts showing as 0. Only injected when body.messages exists (OpenAI format) and the client hasn't already set stream_options. Providers using non-OpenAI formats (Gemini, Claude, Kiro) are unaffected since their bodies lack messages. --- open-sse/executors/base.js | 4 ++++ open-sse/executors/iflow.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/open-sse/executors/base.js b/open-sse/executors/base.js index 61fb0f6e..0f9c4a27 100644 --- a/open-sse/executors/base.js +++ b/open-sse/executors/base.js @@ -54,6 +54,10 @@ export class BaseExecutor { // Override in subclass for provider-specific transformations transformRequest(model, body, stream, credentials) { + // Inject stream_options for OpenAI-format streaming requests to get usage data + if (stream && body.messages && !body.stream_options) { + body.stream_options = { include_usage: true }; + } return body; } diff --git a/open-sse/executors/iflow.js b/open-sse/executors/iflow.js index 701c8c9a..318a2d9e 100644 --- a/open-sse/executors/iflow.js +++ b/open-sse/executors/iflow.js @@ -97,7 +97,7 @@ export class IFlowExecutor extends BaseExecutor { * @returns {object} Transformed body */ transformRequest(model, body, stream, credentials) { - return body; + return super.transformRequest(model, body, stream, credentials); } }