-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeep_debug.py
More file actions
94 lines (81 loc) · 3.46 KB
/
Copy pathdeep_debug.py
File metadata and controls
94 lines (81 loc) · 3.46 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Deep Gemini API Diagnostic - Full raw error inspection
Run: python deep_debug.py
"""
import os
import sys
import re
import warnings
warnings.filterwarnings("ignore")
from pathlib import Path
from dotenv import load_dotenv
load_dotenv(dotenv_path=Path(__file__).parent / ".env")
api_key = os.getenv("GEMINI_API_KEY")
print("=" * 70)
print(" DEEP GEMINI API DIAGNOSTIC")
print("=" * 70)
# Step 1: Key info
print(f"\n[KEY] {api_key[:12]}...{api_key[-6:]} (len={len(api_key)})")
import google.generativeai as genai
genai.configure(api_key=api_key)
# Step 2: List models (this uses a different quota - read-only)
print("\n[STEP 1] Listing models (read-only, no quota consumed)...")
try:
models = list(genai.list_models())
flash_models = [m.name for m in models if "flash" in m.name.lower() and "generateContent" in m.supported_generation_methods]
print(f" Available flash models: {flash_models}")
except Exception as e:
print(f" ERROR listing models: {e}")
sys.exit(1)
# Step 3: Try generate with full raw error dump
print("\n[STEP 2] Raw error analysis for gemini-3.5-flash...")
try:
model = genai.GenerativeModel("gemini-3.5-flash")
response = model.generate_content("Say: OK")
print(f" SUCCESS: {response.text.strip()}")
except Exception as e:
raw = str(e)
print("\n--- FULL RAW ERROR ---")
print(raw[:3000])
print("--- END RAW ERROR ---")
print("\n--- PARSED QUOTA VIOLATIONS ---")
# Extract all quota_metric fields
metrics = re.findall(r'quota_metric: "([^"]+)"', raw)
quota_ids = re.findall(r'quota_id: "([^"]+)"', raw)
quota_vals = re.findall(r'quota_value: (\d+)', raw)
limits = re.findall(r'limit: (\d+)', raw)
retry = re.findall(r'seconds: (\d+)', raw)
for i, metric in enumerate(metrics):
print(f"\n Violation #{i+1}:")
print(f" Metric : {metric}")
if i < len(quota_ids): print(f" QuotaID : {quota_ids[i]}")
if i < len(quota_vals): print(f" Value : {quota_vals[i]}")
if limits:
print(f"\n Reported limit in message: {limits}")
if retry:
print(f" Retry after: {retry[0]} seconds")
print("\n--- RCA CONCLUSION ---")
if any("PerDayPerProject" in q for q in quota_ids):
if "limit: 0" in raw:
print(" ROOT CAUSE: IP-LEVEL BLOCK OR REGION RESTRICTION")
print(" The quota limit reported is 0, which means Google has")
print(" completely blocked this API endpoint for your IP or region.")
print(" This is NOT a per-account quota issue.")
print()
print(" SOLUTIONS:")
print(" 1. Use a VPN to change your IP address and retry")
print(" 2. Check if Gemini API is available in your country")
print(" 3. Enable billing on a Google Cloud project")
else:
print(" ROOT CAUSE: PER-PROJECT DAILY QUOTA EXHAUSTED")
print(f" Limit: {limits[0] if limits else 'unknown'} requests/day used up")
print(" The free tier allows 20 requests/day per project.")
print(" Each Google account = 1 project = 20 req/day cap.")
print()
print(" SOLUTIONS:")
print(" 1. Wait until ~6:30 AM IST for daily reset")
print(" 2. Enable billing on Google Cloud project")
elif any("PerMinute" in q for q in quota_ids):
print(" ROOT CAUSE: PER-MINUTE RATE LIMIT")
print(f" Retry after: {retry[0] if retry else '?'} seconds")
print("\n" + "=" * 70)