openai stream include_usage=true

This commit is contained in:
Ting-Wai To 2025-09-05 00:33:02 -07:00
parent 261d181362
commit cbbebe276b
2 changed files with 6 additions and 0 deletions

View file

@ -35,6 +35,11 @@ export class OpenAIApi implements BaseLlmApi {
});
}
modifyChatBody<T extends ChatCompletionCreateParams>(body: T): T {
// Add stream_options to include usage in streaming responses
if (body.stream) {
(body as any).stream_options = { include_usage: true };
}
// o-series models - only apply for official OpenAI API
const isOfficialOpenAIAPI = this.apiBase === "https://api.openai.com/v1/";
if (isOfficialOpenAIAPI) {

View file

@ -258,6 +258,7 @@ export const createAdapterTests = (testConfig: AdapterTestConfig) => {
model: "gpt-4",
messages: [{ role: "user", content: "hello" }],
stream: true,
stream_options: { include_usage: true },
...testConfig.customBodyOptions,
},
},