-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.js
More file actions
31 lines (24 loc) · 923 Bytes
/
test-api.js
File metadata and controls
31 lines (24 loc) · 923 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
const { GoogleGenerativeAI } = require('@google/generative-ai');
const apiKey = process.env.GEMINI_API_KEY;
console.log('API Key present:', !!apiKey);
console.log('API Key (masked):', apiKey ? apiKey.substring(0, 10) + '...' : 'MISSING');
if (!apiKey) {
console.error('ERROR: GEMINI_API_KEY is not set!');
process.exit(1);
}
const genAI = new GoogleGenerativeAI(apiKey);
async function testAPI() {
try {
console.log('\nTesting Gemini API...');
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
const result = await model.generateContent('Say hello in 5 words');
const response = result.response;
const text = response.text();
console.log('✓ API works!');
console.log('Response:', text);
} catch (error) {
console.error('✗ API Error:', error.message);
process.exit(1);
}
}
testAPI();