import os from google import genai from dotenv import load_dotenv # Load the API key from your .env file load_dotenv() print("Attempting to connect to Gemini API...") try: client = genai.Client(api_key=os.getenv("GEMINI_API_KEY")) # A simple, tiny request response = client.models.generate_content( model='gemini-2.5-flash', contents='Reply with the exact words: "Connection Successful!"' ) print("\n✅ SUCCESS! The API is reachable.") print(f"Gemini says: {response.text}") except Exception as e: print("\n❌ FAILED. The network block is still active.") print(f"Error Details: {str(e)}")