Include api key in header instead of in the URL (#4240)

This commit is contained in:
Sandy Tao 2025-07-15 11:37:14 -07:00 committed by GitHub
parent 40c4070846
commit 7b49560265
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -28,7 +28,7 @@ export async function getEffectiveModel(
const modelToTest = DEFAULT_GEMINI_MODEL; const modelToTest = DEFAULT_GEMINI_MODEL;
const fallbackModel = DEFAULT_GEMINI_FLASH_MODEL; const fallbackModel = DEFAULT_GEMINI_FLASH_MODEL;
const endpoint = `https://generativelanguage.googleapis.com/v1beta/models/${modelToTest}:generateContent?key=${apiKey}`; const endpoint = `https://generativelanguage.googleapis.com/v1beta/models/${modelToTest}:generateContent`;
const body = JSON.stringify({ const body = JSON.stringify({
contents: [{ parts: [{ text: 'test' }] }], contents: [{ parts: [{ text: 'test' }] }],
generationConfig: { generationConfig: {
@ -45,7 +45,10 @@ export async function getEffectiveModel(
try { try {
const response = await fetch(endpoint, { const response = await fetch(endpoint, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: {
'Content-Type': 'application/json',
'x-goog-api-key': apiKey,
},
body, body,
signal: controller.signal, signal: controller.signal,
}); });