diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/azure.go b/plugins/wasm-go/extensions/ai-proxy/provider/azure.go index 1a79908d4e..b09cdd0951 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/azure.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/azure.go @@ -69,7 +69,22 @@ func (m *azureProvider) OnRequestBody(ctx wrapper.HttpContext, apiName ApiName, } func (m *azureProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header, log wrapper.Log) { - util.OverwriteRequestPathHeader(headers, m.serviceUrl.RequestURI()) + u, e := url.Parse(ctx.Path()) + if e == nil { + customApiVersion := u.Query().Get("api-version") + if customApiVersion == "" { + util.OverwriteRequestPathHeader(headers, m.serviceUrl.RequestURI()) + } else { + q := m.serviceUrl.Query() + q.Set("api-version", customApiVersion) + newUrl := *m.serviceUrl + newUrl.RawQuery = q.Encode() + util.OverwriteRequestPathHeader(headers, newUrl.RequestURI()) + } + } else { + log.Errorf("failed to parse request path: %v", e) + util.OverwriteRequestPathHeader(headers, m.serviceUrl.RequestURI()) + } util.OverwriteRequestHostHeader(headers, m.serviceUrl.Host) util.OverwriteRequestAuthorizationHeader(headers, "api-key "+m.config.GetApiTokenInUse(ctx)) headers.Del("Content-Length")