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 11import { NextRequest , NextResponse } from "next/server" ;
2+ import { getServerSideConfig } from "@/app/config/server" ;
23
34export 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,
You can’t perform that action at this time.
0 commit comments