-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-raw.js
More file actions
31 lines (27 loc) · 1005 Bytes
/
test-raw.js
File metadata and controls
31 lines (27 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require('dotenv').config({ path: '.env.local' });
async function testRawAPI() {
console.log("Testing RAW Gemini API with fetch...");
const key = process.env.GOOGLE_API_KEY;
if (!key) {
console.error("No API key found in .env.local!");
return;
}
try {
const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=${key}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
contents: [{ parts: [{ text: "Say hello in 2 words" }] }]
})
});
const data = await res.json();
if (data.error) {
console.error("Gemini API Error:", data.error.message);
} else {
console.log("Success! Response:", data.candidates[0].content.parts[0].text);
}
} catch (e) {
console.error("Network/Fetch Error:", e.message);
}
}
testRawAPI();