소스 검색

Update proxy.ts

Update proxy.ts
JingSyue 1 년 전
부모
커밋
18a6571883
1개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 3
      app/api/proxy.ts

+ 10 - 3
app/api/proxy.ts

@@ -34,9 +34,16 @@ export async function handle(
     }),
   );
   // if dalle3 use openai api key
-  if (req.headers.get("x-base-url")?.includes("openai")) {
-    headers.set("Authorization", `Bearer ${serverConfig.apiKey}`);
-  }
+    const baseUrl = req.headers.get("x-base-url");
+    if (baseUrl?.includes("api.openai.com")) {
+      if (!serverConfig.apiKey) {
+        return NextResponse.json(
+          { error: "OpenAI API key not configured" },
+          { status: 500 },
+        );
+      }
+      headers.set("Authorization", `Bearer ${serverConfig.apiKey}`);
+    }
 
   const controller = new AbortController();
   const fetchOptions: RequestInit = {