Changesets · Branches · Tags · Compare
| Changeset | 5191f4d3357dda694e8217107d825c064e8e0e38d3cfefed36f28b6b52f4850a |
|---|---|
| Author | Ting-Wai To <40179554+tingwai@users.noreply.github.com> · 2025-09-05 00:33 -07:00 |
| Committer | Ting-Wai To <40179554+tingwai@users.noreply.github.com> · 2025-09-05 00:46 -07:00 |
| Parents | f36b1d9edc80 |
2 files changed
modified packages/openai-adapters/src/apis/OpenAI.ts +5 −0
| @@ -35,6 +35,11 @@ | ||
| 35 | 35 | }); |
| 36 | 36 | } |
| 37 | 37 | 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 | + | |
| 38 | 43 | // o-series models - only apply for official OpenAI API |
| 39 | 44 | const isOfficialOpenAIAPI = this.apiBase === "https://api.openai.com/v1/"; |
| 40 | 45 | if (isOfficialOpenAIAPI) { |
modified packages/openai-adapters/src/test/adapter-test-utils.ts +1 −0
| @@ -258,6 +258,7 @@ | ||
| 258 | 258 | model: "gpt-4", |
| 259 | 259 | messages: [{ role: "user", content: "hello" }], |
| 260 | 260 | stream: true, |
| 261 | + stream_options: { include_usage: true }, | |
| 261 | 262 | ...testConfig.customBodyOptions, |
| 262 | 263 | }, |
| 263 | 264 | }, |