From 3bd1a90b62b89099e03f5756adea73d4b4910718 Mon Sep 17 00:00:00 2001 From: jay77721 <164177721+jay77721@users.noreply.github.com> Date: Tue, 4 Aug 2026 14:07:17 +0800 Subject: [PATCH] fix(go-models): add stream_options.include_usage for DeepSeek and Azure OpenAI streaming (#17756) ## Summary DeepSeek and Azure OpenAI require `stream_options.include_usage=true` to return token usage in streaming responses. Without it, all streaming calls report zero usage to ClickHouse and the UI shows no token stats. - [x] Verify DeepSeek streaming calls now report usage - [x] Verify Azure OpenAI streaming calls now report usage --- internal/entity/models/azure_openai.go | 5 +++++ internal/entity/models/deepseek.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/internal/entity/models/azure_openai.go b/internal/entity/models/azure_openai.go index 250da4eddc..27224edad6 100644 --- a/internal/entity/models/azure_openai.go +++ b/internal/entity/models/azure_openai.go @@ -201,6 +201,11 @@ func (a *AzureOpenAIModel) ChatStreamlyWithSender(ctx context.Context, modelName } } + // Request token usage in streaming response. Azure OpenAI only + // includes usage in the final chunk when stream_options.include_usage + // is set. + reqBody["stream_options"] = map[string]any{"include_usage": true} + jsonData, err := json.Marshal(reqBody) if err != nil { return fmt.Errorf("failed to marshal request: %w", err) diff --git a/internal/entity/models/deepseek.go b/internal/entity/models/deepseek.go index 0b332713b1..4c77eae453 100644 --- a/internal/entity/models/deepseek.go +++ b/internal/entity/models/deepseek.go @@ -192,6 +192,10 @@ func (d *DeepSeekModel) ChatStreamlyWithSender(ctx context.Context, modelName st } } + // Request token usage in streaming response. DeepSeek only includes + // usage when stream_options.include_usage is set. + reqBody["stream_options"] = map[string]any{"include_usage": true} + jsonData, err := json.Marshal(reqBody) if err != nil { return fmt.Errorf("failed to marshal request: %w", err)