Environment File Setup
Create a.env.local file in the root directory of your project:
Required Variables
These environment variables are required for the application to function properly.OpenWeatherMap API Key
API key for accessing OpenWeatherMap services (current weather, forecasts, and maps).Used in:
src/lib/api/weather.ts:1- Weather data fetchingsrc/components/ui/WeatherMap.tsx:56- Interactive weather mapssrc/components/ui/SearchCity.tsx:69- City search autocomplete
This variable is prefixed with
NEXT_PUBLIC_ because it’s used in client-side components. This means it will be exposed to the browser.Groq API Key
API key for Groq’s AI services, used for weather analysis and the chat feature.Used in:
src/lib/api/mistral.ts:9- AI weather analysis (blue card)src/app/api/chat/route.ts:7- Interactive chat responses
llama-3.1-8b-instantExample:This is a server-side variable (no
NEXT_PUBLIC_ prefix). It’s only accessible in API routes and Server Actions, keeping your key secure.reCAPTCHA Keys
Google reCAPTCHA v2 site key for client-side validation.Used in:
src/components/ui/WeatherChat.tsx:51- Chat security validation
Google reCAPTCHA v2 secret key for server-side validation.Used in:
src/app/api/chat/route.ts:8- Verifying chat requests
News API Key
API key for GNews.io to fetch weather-related news articles.Used in:
src/app/api/news/route.ts:6- Fetching weather and environmental news
Complete .env.local Template
Copy this template to create your.env.local file:
Security Considerations
Public vs Private Variables
Public vs Private Variables
Public Variables (
NEXT_PUBLIC_*):- Exposed to the browser
- Visible in client-side JavaScript
- Use only for APIs that support browser-based authentication
- Example: OpenWeatherMap, reCAPTCHA site key
- Only accessible on the server
- Never exposed to the browser
- Use for sensitive keys and secrets
- Example: Groq API key, reCAPTCHA secret key, News API key
API Key Rotation
API Key Rotation
Best practices for rotating API keys:
- Generate a new key from the provider’s dashboard
- Add the new key to your
.env.localfile - Test the application locally
- Update the key in your production environment (Vercel, etc.)
- Revoke the old key after confirming the new one works
Rate Limiting & Quotas
Rate Limiting & Quotas
Important limits to be aware of:
- OpenWeatherMap Free Tier: 1,000 calls/day, 60 calls/minute
- Groq Free Tier: Rate limits vary by model
- reCAPTCHA: No strict limits for legitimate traffic
- GNews.io: Varies by plan (typically 100-10,000 requests/day)
Validation
To verify your environment variables are loaded correctly:"Error: GROQ_API_KEY no configurada en las variables de entorno""Faltan llaves de API. ⚙️"
.env.local file.
Next Steps
Get API Keys
Learn how to obtain all required API keys from their respective providers.
Deploy to Production
Configure environment variables for production deployment on Vercel.
