Estimated time: 10-15 minutes
Configure external APIs required for NutriSync features.
Required for food image analysis, AI chat, and nutrition recommendations.
- Go to aistudio.google.com/app/apikey
- Click Create API key
- Select Create API key in new project
- Copy the API key (starts with
AIzaSy...)
Free tier includes:
- 60 requests per minute
- 1,500 requests per day
Sufficient for development and small-scale usage.
Required for food database search (400,000+ foods with nutrition data).
- Go to fdc.nal.usda.gov/api-key-signup.html
- Fill in the form:
- Organization: Personal Project (or your organization)
- Purpose: Nutrition tracking application
- Submit and check email for API key
Use DEMO_KEY instead of registering:
- Limited to 30 requests per hour
- Suitable for initial development only
Create backend/.env (new file in backend folder):
# Supabase Configuration
SUPABASE_URL=https://[your-project-ref].supabase.co
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key_here
SUPABASE_KEY=your_anon_key_here
# Google Gemini AI
GOOGLE_API_KEY=AIzaSy_your_key_here
# USDA FoodData Central
USDA_API_KEY=your_usda_key_here
# Or for testing: USDA_API_KEY=DEMO_KEYImportant Notes:
- No quotes around values
- Replace
[your-project-ref]with your actual Supabase project reference SUPABASE_SERVICE_ROLE_KEYmust be kept secret (never commit to git or expose in frontend)- Use the service_role key from Supabase dashboard (not anon key)
GOOGLE_API_KEYmust start withAIzaSy- This file should already be in
.gitignore- verify it's not tracked by git
Security Checklist:
- File named exactly
.env(not.env.txtor.env.example) - Located in
backend/directory - Listed in
.gitignore - No quotes around any values
- All keys are from your Supabase Project Settings > API page
Create frontend/.env.local (new file in frontend folder):
# Supabase Configuration (Frontend)
VITE_SUPABASE_URL=https://[your-project-ref].supabase.co
VITE_SUPABASE_ANON_KEY=your_anon_key_here
# Backend API
VITE_API_URL=http://localhost:8000Important Notes:
- File must be named
.env.local(not.env) - All frontend variables must have
VITE_prefix - Use anon key (not service_role key) - safe for public exposure
VITE_API_URLpoints to your backend server (localhost for development)- No quotes around values
- Restart dev server after creating or modifying this file
Verification: After creating the file, verify it's loaded:
- Start frontend dev server:
npm run dev - Open browser console (F12)
- Type:
console.log(import.meta.env.VITE_SUPABASE_URL) - Should show your Supabase URL (not
undefined)
Security Checklist:
- File named exactly
.env.local - Located in
frontend/directory - All variables have
VITE_prefix - Using anon key (not service_role key)
- Listed in
.gitignore
| Variable | Location | Value From | Public? |
|---|---|---|---|
SUPABASE_URL |
Backend | Supabase Project Settings > API | Yes |
SUPABASE_SERVICE_ROLE_KEY |
Backend | Supabase Project Settings > API (service_role) | No - Keep secret |
SUPABASE_KEY |
Backend | Supabase Project Settings > API (anon) | Yes |
GOOGLE_API_KEY |
Backend | Google AI Studio | No - Keep secret |
USDA_API_KEY |
Backend | USDA API Key Signup | No |
VITE_SUPABASE_URL |
Frontend | Same as backend SUPABASE_URL | Yes |
VITE_SUPABASE_ANON_KEY |
Frontend | Same as backend SUPABASE_KEY | Yes |
VITE_API_URL |
Frontend | http://localhost:8000 (dev) |
Yes |
Next: Running the Application