Fix OpenAI wildcard proxy host header and query string forwarding (#54)
authorStefan Gasser <redacted>
Tue, 20 Jan 2026 21:23:49 +0000 (22:23 +0100)
committerGitHub <redacted>
Tue, 20 Jan 2026 21:23:49 +0000 (22:23 +0100)
src/routes/openai.ts

index b4e7b55b58713210ad42b0468b474fb42151c1a1..60fad19b4aafe338d275c2f57ac6a3ba87402769 100644 (file)
@@ -147,12 +147,14 @@ openaiRoutes.all("/*", (c) => {
   const config = getConfig();
   const { baseUrl } = getOpenAIInfo(config.providers.openai);
   const path = c.req.path.replace(/^\/openai\/v1/, "");
+  const query = c.req.url.includes("?") ? c.req.url.slice(c.req.url.indexOf("?")) : "";
 
-  return proxy(`${baseUrl}${path}`, {
+  return proxy(`${baseUrl}${path}${query}`, {
     ...c.req,
     headers: {
-      "Content-Type": c.req.header("Content-Type"),
-      Authorization: c.req.header("Authorization"),
+      ...c.req.header(),
+      "X-Forwarded-Host": c.req.header("host"),
+      host: undefined,
     },
   });
 });
git clone https://git.99rst.org/PROJECT