Elffuss BraidHub

kikocis/continue public

openai stream include_usage=true
Changeset5191f4d3357dda694e8217107d825c064e8e0e38d3cfefed36f28b6b52f4850a
AuthorTing-Wai To <40179554+tingwai@users.noreply.github.com> · 2025-09-05 00:33 -07:00
CommitterTing-Wai To <40179554+tingwai@users.noreply.github.com> · 2025-09-05 00:46 -07:00
Parentsf36b1d9edc80

Browse the files at this changeset

2 files changed

modified packages/openai-adapters/src/apis/OpenAI.ts +5 −0
@@ -35,6 +35,11 @@
3535 });
3636 }
3737 modifyChatBody<T extends ChatCompletionCreateParams>(body: T): T {
38+ // Add stream_options to include usage in streaming responses
39+ if (body.stream) {
40+ (body as any).stream_options = { include_usage: true };
41+ }
42+
3843 // o-series models - only apply for official OpenAI API
3944 const isOfficialOpenAIAPI = this.apiBase === "https://api.openai.com/v1/";
4045 if (isOfficialOpenAIAPI) {
modified packages/openai-adapters/src/test/adapter-test-utils.ts +1 −0
@@ -258,6 +258,7 @@
258258 model: "gpt-4",
259259 messages: [{ role: "user", content: "hello" }],
260260 stream: true,
261+ stream_options: { include_usage: true },
261262 ...testConfig.customBodyOptions,
262263 },
263264 },