@@ -741,7 +741,9 @@ export class OpenAI {
741741
742742 const security = options . __security ?? { bearerAuth : true } ;
743743 const controller = new AbortController ( ) ;
744- const response = await this . fetchWithAuth ( url , req , timeout , controller , security ) . catch ( castToError ) ;
744+ const response = await this . fetchWithAuth ( url , req , timeout , controller , security , options . stream ) . catch (
745+ castToError ,
746+ ) ;
745747 const headersTime = Date . now ( ) ;
746748
747749 if ( response instanceof globalThis . Error ) {
@@ -924,6 +926,7 @@ export class OpenAI {
924926 bearerAuth : true ,
925927 adminAPIKeyAuth : true ,
926928 } ,
929+ keepAbortListener = false ,
927930 ) : Promise < Response > {
928931 if ( this . _workloadIdentityAuth && schemes . bearerAuth ) {
929932 const headers = init . headers as Headers ;
@@ -934,7 +937,7 @@ export class OpenAI {
934937 }
935938 }
936939
937- const response = await this . fetchWithTimeout ( url , init , timeout , controller ) ;
940+ const response = await this . fetchWithTimeout ( url , init , timeout , controller , keepAbortListener ) ;
938941
939942 return response ;
940943 }
@@ -944,6 +947,7 @@ export class OpenAI {
944947 init : RequestInit | undefined ,
945948 ms : number ,
946949 controller : AbortController ,
950+ keepAbortListener = false ,
947951 ) : Promise < Response > {
948952 const { signal, method, ...options } = init || { } ;
949953 const abort = this . _makeAbort ( controller ) ;
@@ -972,7 +976,7 @@ export class OpenAI {
972976 return await this . fetch . call ( undefined , url , fetchOptions ) ;
973977 } finally {
974978 clearTimeout ( timeout ) ;
975- if ( signal ) signal . removeEventListener ( 'abort' , abort ) ;
979+ if ( signal && ! keepAbortListener ) signal . removeEventListener ( 'abort' , abort ) ;
976980 }
977981 }
978982
0 commit comments