Migrated from custom admin endpoint + Redis storage to Devvit's built-in settings system for managing the Gemini API key.
- Deleted:
POST /api/admin/set-gemini-keyendpoint fromsrc/server/index.ts - Reason: Devvit settings provide a better, more secure solution
- File:
src/server/ai/gemini.ts - Changed:
- From:
redis.get('config:gemini_api_key') - To:
settings.get('apiKey')
- From:
- Import: Changed from
redistosettingsfrom@devvit/web/server
- File:
devvit.json - Added:
{
"settings": [
{
"type": "string",
"name": "apiKey",
"label": "Gemini API Key",
"helpText": "Your Google Gemini API key for document analysis. Get one at https://aistudio.google.com/app/apikey",
"isSecret": true
}
]
}- File:
GEMINI_API_KEY_SETUP.md - Changes:
- Removed all admin endpoint instructions
- Added Devvit CLI setup instructions
- Simplified security considerations
- Updated code examples
- File:
.kiro/specs/gemini-analysis/tasks.md- Updated Task 2.4 to reflect Devvit settings approach
- File:
.kiro/specs/gemini-analysis/design.md- Updated API Key Storage section with new approach
# Required custom endpoint and moderator authentication
curl -X POST /api/admin/set-gemini-key \
-H "Content-Type: application/json" \
-d '{"apiKey": "AIza..."}'# Simple CLI command
npx devvit settings set apiKey
# Or with value directly:
npx devvit settings set apiKey "AIza..."- Simpler: No custom code needed
- More Secure: Encrypted by Devvit platform
- Standard: Follows Devvit best practices
- Easier Management: CLI-based, no API calls needed
- Better UX: Clear help text in settings UI
If you already have the API key set in Redis:
- Get the current key from Redis (if you have access)
- Run
npx devvit settings set apiKey "YOUR_KEY" - Deploy the updated code
- The old Redis key will be ignored
After deployment, verify the integration works:
# Test the analysis endpoint
curl -X POST /api/analyze \
-H "Content-Type: application/json" \
-d '{
"fileData": "data:image/png;base64,...",
"fileType": "image/png",
"fileName": "test.png"
}'If the key is not set, you'll see:
{
"error": "Gemini API key not configured. Run: npx devvit settings set apiKey"
}- ✅
src/server/index.ts- Removed admin endpoint - ✅
src/server/ai/gemini.ts- Updated to use settings - ✅
devvit.json- Added settings configuration - ✅
GEMINI_API_KEY_SETUP.md- Updated documentation - ✅
.kiro/specs/gemini-analysis/tasks.md- Updated task - ✅
.kiro/specs/gemini-analysis/design.md- Updated design
The analysis endpoint (/api/analyze) remains unchanged. Only the configuration method changed.