-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (30 loc) · 879 Bytes
/
test.py
File metadata and controls
32 lines (30 loc) · 879 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
32
import os
import requests
from dotenv import load_dotenv
def test_gemini_api():
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")
url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent"
headers = {
"Content-Type": "application/json",
"X-goog-api-key": api_key
}
data = {
"contents": [
{
"parts": [
{"text": "Explain how AI works in a few words"}
]
}
]
}
try:
resp = requests.post(url, headers=headers, json=data)
resp.raise_for_status()
print("Gemini API is working. Response:")
print(resp.json())
except Exception as e:
print("Gemini API test failed.")
print(e)
if __name__ == "__main__":
test_gemini_api()