-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-api-usage.js
More file actions
64 lines (53 loc) Β· 2.16 KB
/
check-api-usage.js
File metadata and controls
64 lines (53 loc) Β· 2.16 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Script to check Gemini API usage and limits
const { GoogleGenerativeAI } = require("@google/generative-ai");
async function checkAPIUsage() {
console.log("π Checking Gemini API Usage...\n");
const apiKey = process.env.GEMINI_API_KEY;
if (!apiKey || apiKey === "your-gemini-api-key-here") {
console.log("β No API key found in environment variables");
console.log("π‘ Make sure you have GEMINI_API_KEY in your .env.local file");
return;
}
console.log("β
API Key found:", apiKey.substring(0, 10) + "...");
try {
const genAI = new GoogleGenerativeAI(apiKey);
// Try a simple request to test the API
console.log("π§ͺ Testing API connection...");
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const result = await model.generateContent(
"Hello, this is a test message."
);
const response = await result.response;
const text = response.text();
console.log("β
API is working!");
console.log("π Test response:", text.substring(0, 100) + "...");
} catch (error) {
console.log("β API Error:", error.message);
if (error.message.includes("429")) {
console.log("\nπ¨ RATE LIMIT EXCEEDED!");
console.log("π You've hit the Gemini API rate limits");
console.log("β° Wait for quota reset (usually daily)");
console.log(
"π‘ Or upgrade your plan at: https://makersuite.google.com/app/apikey"
);
} else if (error.message.includes("403")) {
console.log("\nπ API KEY ISSUE!");
console.log("π Your API key might be invalid or restricted");
console.log(
"π‘ Check your API key at: https://makersuite.google.com/app/apikey"
);
} else if (error.message.includes("quota")) {
console.log("\nπ QUOTA EXCEEDED!");
console.log("π You've used up your daily quota");
console.log("β° Wait for quota reset (usually daily)");
} else {
console.log("\nβ UNKNOWN ERROR!");
console.log("π Check the error message above for details");
}
}
}
// Run the check
if (require.main === module) {
checkAPIUsage().catch(console.error);
}
module.exports = { checkAPIUsage };