From e9ccae4ca1ae555eec669d84385b4a064b457214 Mon Sep 17 00:00:00 2001 From: Ibrahim Ryan Date: Mon, 23 Mar 2026 12:03:11 +0700 Subject: [PATCH] fix(iflow): inject stream_options for usage data in streaming Add stream_options: { include_usage: true } to iFlow streaming requests to get token usage data in the final streaming chunk. This fixes token counts showing as 0 for iFlow streaming requests. Only injected when streaming is enabled and body.messages exists (OpenAI format), and the client hasn't already set stream_options. Note: Applied only to iFlow executor instead of BaseExecutor to avoid affecting all providers globally. This gives us more control and allows testing with iFlow first. Fixes #74 Co-authored-by: Ibrahim Ryan Made-with: Cursor --- open-sse/executors/iflow.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/open-sse/executors/iflow.js b/open-sse/executors/iflow.js index 701c8c9a..899477a8 100644 --- a/open-sse/executors/iflow.js +++ b/open-sse/executors/iflow.js @@ -89,7 +89,7 @@ export class IFlowExecutor extends BaseExecutor { } /** - * Transform request body (passthrough for iFlow) + * Transform request body - inject stream_options for usage data * @param {string} model - Model name * @param {object} body - Request body * @param {boolean} stream - Whether streaming is enabled @@ -97,6 +97,10 @@ export class IFlowExecutor extends BaseExecutor { * @returns {object} Transformed body */ transformRequest(model, body, stream, credentials) { + // Inject stream_options for streaming requests to get usage data + if (stream && body.messages && !body.stream_options) { + body.stream_options = { include_usage: true }; + } return body; } }