File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { NextRequest , NextResponse } from "next/server" ;
2
+ import { getServerSideConfig } from "@/app/config/server" ;
2
3
3
4
export async function handle (
4
5
req : NextRequest ,
@@ -9,6 +10,7 @@ export async function handle(
9
10
if ( req . method === "OPTIONS" ) {
10
11
return NextResponse . json ( { body : "OK" } , { status : 200 } ) ;
11
12
}
13
+ const serverConfig = getServerSideConfig ( ) ;
12
14
13
15
// remove path params from searchParams
14
16
req . nextUrl . searchParams . delete ( "path" ) ;
@@ -31,6 +33,18 @@ export async function handle(
31
33
return true ;
32
34
} ) ,
33
35
) ;
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
+
34
48
const controller = new AbortController ( ) ;
35
49
const fetchOptions : RequestInit = {
36
50
headers,
You can’t perform that action at this time.
0 commit comments