A simple Python script demonstrating basic integration with Google Gemini's free API.
-
Get a free API key:
- Visit Google AI Studio
- Create a free API key for Gemini
-
Install dependencies:
pip install -r requirements.txt
-
Configure API key:
cp .env.example .env # Edit .env and replace 'your_gemini_api_key_here' with your actual API key
Run the script:
python main.pyThe script will make a request to Google Gemini API and print a greeting response.
- ✅ Secure API key handling via environment variables
- ✅ Basic error handling for network and API errors
- ✅ Timeout protection
- ✅ Clear error messages
- API keys are stored in
.envfile (not tracked by git) - Environment variables loaded using
python-dotenv - No hardcoded secrets in source code
Expected output:
Making request to Gemini API...
LLM Response:
Hello! I'm Gemini, a friendly AI assistant created by Google. I'm here to help you with a wide variety of tasks...