Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(go-models): add stream_options.include_usage for DeepSeek and Azure OpenAI streaming (#17756)

jay777213bd1a90b62b8
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)