diff --git a/src/proxy/openai.ts b/src/proxy/openai.ts index e0330c0..8e0d134 100644 --- a/src/proxy/openai.ts +++ b/src/proxy/openai.ts @@ -22,17 +22,16 @@ const rewriteRequest = (proxyReq: http.ClientRequest, req: Request) => { proxyReq.setHeader("Authorization", `Bearer ${key.key}`); if (req.method === "POST" && req.body) { + if (req.body?.stream) { + req.body.stream = false; + const updatedBody = JSON.stringify(req.body); + proxyReq.setHeader("Content-Length", Buffer.byteLength(updatedBody)); + (req as any).rawBody = Buffer.from(updatedBody); + } + // body-parser and http-proxy-middleware don't play nice together fixRequestBody(proxyReq, req); } - - if (req.body?.stream) { - req.body.stream = false; - const updatedBody = JSON.stringify(req.body); - proxyReq.setHeader("Content-Length", Buffer.byteLength(updatedBody)); - proxyReq.write(updatedBody); - proxyReq.end(); - } }; const openaiProxy = createProxyMiddleware({