fix: gemini authentication error

This commit is contained in:
Hk-Gosuto
2023-12-30 11:36:45 +08:00
parent 2a9b36f626
commit 98b5ace66e
2 changed files with 8 additions and 6 deletions

View File

@@ -28,7 +28,12 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
const authToken = req.headers.get("Authorization") ?? "";
// check if it is openai api key or user token
const { accessCode, apiKey } = parseApiKey(authToken);
let { accessCode, apiKey } = parseApiKey(authToken);
if (modelProvider === ModelProvider.GeminiPro) {
const googleAuthToken = req.headers.get("x-goog-api-key") ?? "";
apiKey = googleAuthToken.trim().replaceAll("Bearer ", "").trim();
}
const hashedCode = md5.hash(accessCode ?? "").trim();