88 openAiNativeModels ,
99 OPENAI_NATIVE_DEFAULT_TEMPERATURE ,
1010 type ReasoningEffort ,
11+ type VerbosityLevel ,
1112} from "@roo-code/types"
1213
1314import type { ApiHandlerOptions } from "../../shared/api"
@@ -24,7 +25,6 @@ import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from ".
2425export type OpenAiNativeModel = ReturnType < OpenAiNativeHandler [ "getModel" ] >
2526
2627// GPT-5 specific types for Responses API
27- type Verbosity = "low" | "medium" | "high"
2828type ReasoningEffortWithMinimal = ReasoningEffort | "minimal"
2929
3030interface GPT5ResponsesAPIParams {
@@ -34,7 +34,7 @@ interface GPT5ResponsesAPIParams {
3434 effort : ReasoningEffortWithMinimal
3535 }
3636 text ?: {
37- verbosity : Verbosity
37+ verbosity : VerbosityLevel
3838 }
3939}
4040
@@ -53,7 +53,6 @@ interface GPT5ResponseChunk {
5353export class OpenAiNativeHandler extends BaseProvider implements SingleCompletionHandler {
5454 protected options : ApiHandlerOptions
5555 private client : OpenAI
56- private gpt5Verbosity : Verbosity = "medium" // Default verbosity for GPT-5
5756
5857 constructor ( options : ApiHandlerOptions ) {
5958 super ( )
@@ -146,18 +145,35 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
146145 systemPrompt : string ,
147146 messages : Anthropic . Messages . MessageParam [ ] ,
148147 ) : ApiStream {
149- const { reasoning } = this . getModel ( )
148+ const { reasoning, verbosity } = this . getModel ( )
150149
151- const stream = await this . client . chat . completions . create ( {
150+ // Prepare the request parameters
151+ const params : any = {
152152 model : model . id ,
153153 temperature : this . options . modelTemperature ?? OPENAI_NATIVE_DEFAULT_TEMPERATURE ,
154154 messages : [ { role : "system" , content : systemPrompt } , ...convertToOpenAiMessages ( messages ) ] ,
155155 stream : true ,
156156 stream_options : { include_usage : true } ,
157157 ...( reasoning && reasoning ) ,
158- } )
158+ }
159159
160- yield * this . handleStreamResponse ( stream , model )
160+ // Add verbosity if supported (for future GPT-5 models)
161+ if ( verbosity && model . id . startsWith ( "gpt-5" ) ) {
162+ params . verbosity = verbosity
163+ }
164+
165+ const stream = await this . client . chat . completions . create ( params )
166+
167+ if ( typeof ( stream as any ) [ Symbol . asyncIterator ] !== "function" ) {
168+ throw new Error (
169+ "OpenAI SDK did not return an AsyncIterable for streaming response. Please check SDK version and usage." ,
170+ )
171+ }
172+
173+ yield * this . handleStreamResponse (
174+ stream as unknown as AsyncIterable < OpenAI . Chat . Completions . ChatCompletionChunk > ,
175+ model ,
176+ )
161177 }
162178
163179 private async * handleGpt5Message (
@@ -172,6 +188,9 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
172188 // Get reasoning effort, supporting the new "minimal" option for GPT-5
173189 const reasoningEffort = this . getGpt5ReasoningEffort ( model )
174190
191+ // Get verbosity from model settings, default to "medium" if not specified
192+ const verbosity = model . verbosity || "medium"
193+
175194 // Prepare the request parameters for Responses API
176195 const params : GPT5ResponsesAPIParams = {
177196 model : model . id ,
@@ -182,7 +201,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
182201 } ,
183202 } ) ,
184203 text : {
185- verbosity : this . gpt5Verbosity ,
204+ verbosity : verbosity ,
186205 } ,
187206 }
188207
@@ -332,16 +351,6 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
332351 }
333352 }
334353
335- // Method to set verbosity for GPT-5 models
336- setGpt5Verbosity ( verbosity : Verbosity ) {
337- this . gpt5Verbosity = verbosity
338- }
339-
340- // Method to get current verbosity setting
341- getGpt5Verbosity ( ) : Verbosity {
342- return this . gpt5Verbosity
343- }
344-
345354 private isGpt5Model ( modelId : string ) : boolean {
346355 return modelId . startsWith ( "gpt-5" )
347356 }
@@ -411,23 +420,25 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
411420
412421 // The o3 models are named like "o3-mini-[reasoning-effort]", which are
413422 // not valid model ids, so we need to strip the suffix.
414- return { id : id . startsWith ( "o3-mini" ) ? "o3-mini" : id , info, ...params }
423+ return { id : id . startsWith ( "o3-mini" ) ? "o3-mini" : id , info, ...params , verbosity : params . verbosity }
415424 }
416425
417426 async completePrompt ( prompt : string ) : Promise < string > {
418427 try {
419- const { id, temperature, reasoning } = this . getModel ( )
428+ const { id, temperature, reasoning, verbosity } = this . getModel ( )
420429
421- const params : OpenAI . Chat . Completions . ChatCompletionCreateParamsNonStreaming & { verbosity ?: Verbosity } = {
430+ const params : OpenAI . Chat . Completions . ChatCompletionCreateParamsNonStreaming & {
431+ verbosity ?: VerbosityLevel
432+ } = {
422433 model : id ,
423434 messages : [ { role : "user" , content : prompt } ] ,
424435 temperature,
425436 ...( reasoning && reasoning ) ,
426437 }
427438
428439 // Add verbosity for GPT-5 models
429- if ( this . isGpt5Model ( id ) ) {
430- params . verbosity = this . gpt5Verbosity
440+ if ( this . isGpt5Model ( id ) && verbosity ) {
441+ params . verbosity = verbosity
431442 }
432443
433444 const response = await this . client . chat . completions . create ( params as any )
0 commit comments