Skip to content

Commit 6e03f32

Browse files
authored
Merge pull request ChatGPTNextWeb#5795 from JingSyue/main
fix: built-in plugin dalle3 error ChatGPTNextWeb#5787
2 parents 108069a + 18a6571 commit 6e03f32

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

app/api/proxy.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NextRequest, NextResponse } from "next/server";
2+
import { getServerSideConfig } from "@/app/config/server";
23

34
export async function handle(
45
req: NextRequest,
@@ -9,6 +10,7 @@ export async function handle(
910
if (req.method === "OPTIONS") {
1011
return NextResponse.json({ body: "OK" }, { status: 200 });
1112
}
13+
const serverConfig = getServerSideConfig();
1214

1315
// remove path params from searchParams
1416
req.nextUrl.searchParams.delete("path");
@@ -31,6 +33,18 @@ export async function handle(
3133
return true;
3234
}),
3335
);
36+
// if dalle3 use openai api key
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+
}
47+
3448
const controller = new AbortController();
3549
const fetchOptions: RequestInit = {
3650
headers,

0 commit comments

Comments
 (0)