Download test_key_validity.py from d-e-e-k-11/amazon_product: direct link, hf CLI and curl.
- Browser
- Download file 526 Bytes
-
https://huggingface.co/d-e-e-k-11/amazon_product/resolve/main/test_key_validity.py
- Command line
-
hf download hf://d-e-e-k-11/amazon_product/test_key_validity.py
-
curl -L -o test_key_validity.py https://huggingface.co/d-e-e-k-11/amazon_product/resolve/main/test_key_validity.py
526 Bytes
| import os | |
| from dotenv import load_dotenv | |
| import google.generativeai as genai | |
| load_dotenv() | |
| api_key = os.getenv("GOOGLE_API_KEY") | |
| if not api_key: | |
| print("Error: No API key found in .env") | |
| else: | |
| try: | |
| genai.configure(api_key=api_key) | |
| for m in genai.list_models(): | |
| if 'generateContent' in m.supported_generation_methods: | |
| print(m.name) | |
| print("\nAPI Key is valid and models listed successfully.") | |
| except Exception as e: | |
| print(f"Error: {e}") | |