diff --git a/app/api/common.ts b/app/api/common.ts index 24453dd96..6fdde2c30 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -95,12 +95,12 @@ export async function requestOpenai(req: NextRequest) { } } } - + const contentType = req.headers.get("Content-Type") ?? "application/json"; const fetchUrl = cloudflareAIGatewayUrl(`${baseUrl}/${path}`); console.log("fetchUrl", fetchUrl); const fetchOptions: RequestInit = { headers: { - "Content-Type": "application/json", + "Content-Type": contentType, "Cache-Control": "no-store", [authHeaderName]: authValue, ...(serverConfig.openaiOrgId && { @@ -117,7 +117,7 @@ export async function requestOpenai(req: NextRequest) { }; // #1815 try to refuse gpt4 request - if (serverConfig.customModels && req.body) { + if (serverConfig.customModels && req.body && contentType.includes("json")) { try { const clonedBody = await req.text(); fetchOptions.body = clonedBody; diff --git a/app/client/api.ts b/app/client/api.ts index 42c0348c4..108ee910b 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -260,7 +260,7 @@ export function getHeaders(ignoreHeaders?: boolean) { : isAlibaba ? accessStore.alibabaApiKey : accessStore.openaiApiKey; - if (accessStore.isUseOpenAIEndpointForAllModels) { + if (accessStore.isUseOpenAIEndpointForAllModels || ignoreHeaders) { return { isGoogle: false, isAzure: false,