@@ -16,10 +16,13 @@ export class AzureApi extends OpenAIApi {
16
16
provider : "openai" ,
17
17
} ) ;
18
18
19
+ const { baseURL, defaultQuery } = this . _getAzureBaseURL ( azureConfig ) ;
20
+
19
21
this . openai = new OpenAI ( {
20
22
apiKey : azureConfig . apiKey ,
21
- baseURL : this . _getAzureBaseURL ( azureConfig ) ,
23
+ baseURL,
22
24
fetch : customFetch ( azureConfig . requestOptions ) ,
25
+ defaultQuery,
23
26
} ) ;
24
27
}
25
28
@@ -32,8 +35,20 @@ export class AzureApi extends OpenAIApi {
32
35
return apiType === "azure-openai" || apiType === "azure" ;
33
36
}
34
37
35
- private _getAzureBaseURL ( config : z . infer < typeof AzureConfigSchema > ) : string {
36
- const baseURL = new URL ( this . apiBase ) . toString ( ) . replace ( / \/ $ / , "" ) ;
38
+ private _getAzureBaseURL ( config : z . infer < typeof AzureConfigSchema > ) : {
39
+ baseURL : string ;
40
+ defaultQuery : Record < string , string > ;
41
+ } {
42
+ const url = new URL ( this . apiBase ) ;
43
+
44
+ // Copy search params to separate object for OpenAI
45
+ const queryParams : Record < string , string > = { } ;
46
+ for ( const [ key , value ] of url . searchParams . entries ( ) ) {
47
+ queryParams [ key ] = value ;
48
+ }
49
+
50
+ url . pathname = url . pathname . replace ( / \/ $ / , "" ) ; // Remove trailing slash if present
51
+ url . search = "" ; // Clear original search params
37
52
38
53
// Default is `azure-openai` in docs, but previously was `azure`
39
54
if ( this . _isAzureOpenAI ( config . env ?. apiType ) ) {
@@ -48,11 +63,15 @@ export class AzureApi extends OpenAIApi {
48
63
"`env.apiVersion` is a required configuration property for Azure OpenAI" ,
49
64
) ;
50
65
}
66
+ url . pathname = `${ url . pathname } /openai/deployments/${ config . env . deployment } ` ;
51
67
52
- return ` ${ baseURL } /openai/deployments/ ${ config . env . deployment } ? api-version= ${ config . env . apiVersion } ` ;
68
+ queryParams [ " api-version" ] = config . env . apiVersion ;
53
69
}
54
70
55
- return baseURL ;
71
+ return {
72
+ baseURL : url . toString ( ) ,
73
+ defaultQuery : queryParams ,
74
+ } ;
56
75
}
57
76
58
77
/**
0 commit comments