Skip to content

Commit 18a6571

Browse files
authored
Update proxy.ts
Update proxy.ts
1 parent 2b0f2e5 commit 18a6571

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/api/proxy.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ export async function handle(
3434
}),
3535
);
3636
// if dalle3 use openai api key
37-
if (req.headers.get("x-base-url")?.includes("openai")) {
38-
headers.set("Authorization", `Bearer ${serverConfig.apiKey}`);
39-
}
37+
const baseUrl = req.headers.get("x-base-url");
38+
if (baseUrl?.includes("api.openai.com")) {
39+
if (!serverConfig.apiKey) {
40+
return NextResponse.json(
41+
{ error: "OpenAI API key not configured" },
42+
{ status: 500 },
43+
);
44+
}
45+
headers.set("Authorization", `Bearer ${serverConfig.apiKey}`);
46+
}
4047

4148
const controller = new AbortController();
4249
const fetchOptions: RequestInit = {

0 commit comments

Comments
 (0)