Skip to content

Commit a03d6b6

Browse files
author
AlexandruSmirnov
committed
feat: add max_completion_tokens support for O3 family models
- O3 models now include max_completion_tokens when includeMaxTokens is true - Updated tests to reflect that O3 models support max_completion_tokens - This addresses PR feedback that O3 models should use addMaxTokensIfNeeded()
1 parent 50d3825 commit a03d6b6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/api/providers/__tests__/openai.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ describe("OpenAiHandler", () => {
566566
},
567567
}
568568

569-
it("should handle O3 model with streaming and NOT include max_tokens even when includeMaxTokens is true", async () => {
569+
it("should handle O3 model with streaming and include max_completion_tokens when includeMaxTokens is true", async () => {
570570
const o3Handler = new OpenAiHandler({
571571
...o3Options,
572572
includeMaxTokens: true,
@@ -601,7 +601,8 @@ describe("OpenAiHandler", () => {
601601
stream_options: { include_usage: true },
602602
reasoning_effort: "medium",
603603
temperature: 0.5,
604-
// O3 models do not support max_tokens
604+
// O3 models do not support deprecated max_tokens but do support max_completion_tokens
605+
max_completion_tokens: 32000,
605606
}),
606607
{},
607608
)
@@ -650,7 +651,7 @@ describe("OpenAiHandler", () => {
650651
expect(callArgs).not.toHaveProperty("max_completion_tokens")
651652
})
652653

653-
it("should handle O3 model non-streaming with reasoning_effort but NO max_tokens", async () => {
654+
it("should handle O3 model non-streaming with reasoning_effort and max_completion_tokens when includeMaxTokens is true", async () => {
654655
const o3Handler = new OpenAiHandler({
655656
...o3Options,
656657
openAiStreamingEnabled: false,
@@ -683,7 +684,8 @@ describe("OpenAiHandler", () => {
683684
],
684685
reasoning_effort: "medium",
685686
temperature: 0.3,
686-
// O3 models do not support max_tokens
687+
// O3 models do not support deprecated max_tokens but do support max_completion_tokens
688+
max_completion_tokens: 65536, // Using default maxTokens from o3Options
687689
}),
688690
{},
689691
)

src/api/providers/openai.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
310310
}
311311

312312
// O3 family models do not support max_tokens parameter
313+
// but they do support max_completion_tokens
314+
this.addMaxTokensIfNeeded(requestOptions, modelInfo)
313315

314316
const stream = await this.client.chat.completions.create(
315317
requestOptions,
@@ -332,6 +334,8 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
332334
}
333335

334336
// O3 family models do not support max_tokens parameter
337+
// but they do support max_completion_tokens
338+
this.addMaxTokensIfNeeded(requestOptions, modelInfo)
335339

336340
const response = await this.client.chat.completions.create(
337341
requestOptions,

0 commit comments

Comments
 (0)