# Google Gemini API Setup Guide

This guide will help you get a **free** Google Gemini API key to enable AI-powered question generation in Random Learner.

## 🚀 Quick Start (5 minutes)

### Step 1: Visit Google AI Studio
1. Go to [Google AI Studio](https://aistudio.google.com/)
2. Sign in with your Google account (or create one if needed)

### Step 2: Get Your Free API Key
1. Click on **"Get API key"** in the left sidebar
2. Click **"Create API key"**
3. Select **"Create API key in new project"** (recommended)
4. Your API key will be generated instantly! 🎉

### Step 3: Copy Your API Key
1. Click the **copy button** next to your API key
2. **Important**: Keep this key secure and don't share it publicly

### Step 4: Add to Random Learner
1. Open Random Learner
2. Click on **Settings** (⚙️) in the system tray
3. Go to the **AI Configuration** section
4. Select **"Google Gemini"** as your AI Provider
5. Paste your API key in the **"Gemini API Key"** field
6. Click **"Test Connection"** to verify it works
7. Click **"Save Settings"**

## ✅ You're Done!

Random Learner will now generate intelligent, personalized questions using Google's Gemini AI!

---

## 🆓 Free Tier Details

### What You Get for Free:
- **15 requests per minute**
- **1,500 requests per day**
- **1 million tokens per month**
- Access to Gemini 1.5 Flash model

### Perfect for Learning:
- Generate **100-200 questions per day** easily
- Each question uses ~1 request
- More than enough for personal learning sessions
- No credit card required!

---

## 🔧 Advanced Configuration

### Custom Prompts
You can customize how Gemini generates questions:
1. Go to Settings → AI Configuration
2. Enable **"Use Custom Prompt"**
3. Modify the prompt to focus on specific topics or styles
4. Example modifications:
   - Add specific programming languages
   - Focus on practical examples
   - Adjust difficulty levels
   - Include real-world scenarios

### Question Caching
Random Learner automatically caches AI-generated questions:
- **Offline access**: Use cached questions when internet is unavailable
- **Faster loading**: Instant access to previously generated questions
- **API efficiency**: Reduces API calls for repeated topics
- **Export/Import**: Backup your question cache

---

## 🛠️ Troubleshooting

### Common Issues:

#### "Invalid API Key" Error
- **Solution**: Double-check you copied the entire API key
- **Tip**: API keys start with "AIza..." and are quite long

#### "Quota Exceeded" Error
- **Cause**: You've hit the daily limit (1,500 requests)
- **Solution**: Wait until tomorrow or upgrade to paid tier
- **Prevention**: Use question caching to reduce API calls

#### "Network Error"
- **Solution**: Check your internet connection
- **Fallback**: Random Learner will use cached questions automatically

#### Questions Not Generating
1. Verify API key is correct
2. Check internet connection
3. Try the "Test Connection" button
4. Look at cached questions as backup

---

## 🔒 Security & Privacy

### API Key Security:
- ✅ **Stored locally** on your device only
- ✅ **Encrypted** in Random Learner settings
- ✅ **Never shared** with third parties
- ❌ **Don't commit** API keys to version control
- ❌ **Don't share** in screenshots or logs

### Data Privacy:
- Only question topics and difficulty levels are sent to Google
- No personal information is transmitted
- Generated questions are cached locally
- You control all data

---

## 💡 Pro Tips

### Maximize Your Free Tier:
1. **Enable Caching**: Let Random Learner save questions for reuse
2. **Batch Learning**: Generate multiple questions in focused sessions
3. **Topic Rotation**: Vary topics to build a diverse question cache
4. **Export Cache**: Backup your questions regularly

### Best Practices:
- **Test Connection** after setup to ensure everything works
- **Monitor Usage** if you're a heavy user (check Google AI Studio)
- **Mix with Static**: Use both AI and static questions for variety
- **Regular Updates**: Keep Random Learner updated for improvements

---

## 🆙 Upgrading (Optional)

If you need more than the free tier:

### Paid Tier Benefits:
- **Higher rate limits** (300+ requests per minute)
- **More daily requests** (unlimited with pay-per-use)
- **Priority support** from Google
- **Advanced models** access

### When to Upgrade:
- Generating 200+ questions daily
- Using for team/classroom settings
- Need faster response times
- Want access to newer models

---

## 🤝 Support

### Need Help?
1. **Test Connection**: Use the built-in test in Settings
2. **Check Logs**: Look at console output for error details
3. **Try Cache**: Use cached questions if API fails
4. **Documentation**: Visit [Google AI Studio Docs](https://ai.google.dev/docs)

### Community:
- Share tips and tricks with other learners
- Report issues on GitHub
- Suggest improvements for better AI integration

---

## 🎯 What's Next?

Once you have Gemini set up:
1. **Explore Topics**: Try different programming subjects
2. **Adjust Difficulty**: Experiment with beginner to advanced levels
3. **Custom Prompts**: Tailor questions to your learning style
4. **Build Cache**: Generate questions for offline study sessions
5. **Continuous Learning**: Use the "Next Question" feature for study marathons

**Happy Learning!** 🧠✨

---

*Last updated: January 2024*
*Random Learner Version: 1.0.3+*
