This guide will help you configure the necessary API keys and services to make your sentiment analysis application fully functional.
Purpose: Powers the core sentiment analysis and emotion detection features.
Steps to get your API key:
- Visit HuggingFace
- Create a free account or sign in
- Go to your Settings > Access Tokens
- Click "New token"
- Give it a name (e.g., "Sentiment Analysis App")
- Select "Read" permissions
- Copy the generated token (starts with
hf_)
Free Tier: 1,000 requests per month Paid Tier: Starting at $9/month for 10,000 requests
Purpose: Enables automatic language detection and translation.
Steps to get your API key:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the "Cloud Translation API"
- Go to "Credentials" > "Create Credentials" > "API Key"
- Copy the generated API key (starts with
AIzaSy) - (Optional) Restrict the key to Translation API only for security
Free Tier: $10 credit per month (≈500,000 characters) Pricing: $20 per 1M characters after free tier
Purpose: Enhanced text analysis and summarization features.
Steps to get your API key:
- Visit OpenAI Platform
- Create an account or sign in
- Go to API Keys
- Click "Create new secret key"
- Copy the generated key (starts with
sk-)
Pricing: Pay-per-use, starting at $0.002 per 1K tokens
cp .env.example .envOpen the .env file and replace the dummy values with your actual API keys:
# Server Configuration
PORT=3001
NODE_ENV=development
# Database Configuration (Optional)
MONGODB_URI=mongodb://localhost:27017/sentiment-analysis
REDIS_URL=redis://localhost:6379
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=7d
# API Keys - Replace these with your actual API keys
HUGGINGFACE_API_KEY=hf_your_actual_huggingface_key_here
GOOGLE_TRANSLATE_API_KEY=AIzaSy_your_actual_google_translate_key_here
OPENAI_API_KEY=sk-your_actual_openai_key_here
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
# File Upload Configuration
MAX_FILE_SIZE=10485760
UPLOAD_DIR=uploadsMake sure your .env file is not committed to version control:
echo ".env" >> .gitignorenpm run devThis starts both the frontend (port 5173) and backend (port 3001) simultaneously.
npm run build
npm startVisit http://localhost:3001/api/health to see which services are configured:
{
"status": "OK",
"services": {
"huggingface": "configured",
"googleTranslate": "configured",
"openai": "configured"
}
}curl -X POST http://localhost:3001/api/sentiment/analyze \
-H "Content-Type: application/json" \
-d '{"text": "I love this product!", "includeEmotions": true}'- Never commit API keys to version control
- Use environment variables for all sensitive data
- Rotate API keys regularly
- Restrict API key permissions when possible
The application includes built-in rate limiting:
- 100 requests per 15 minutes per IP address
- Configurable via environment variables
All inputs are validated and sanitized:
- Text length limits (10,000 characters max)
- File size limits (10MB max)
- File type restrictions
1. "API key not configured" errors
- Check that your
.envfile exists and contains the correct keys - Restart the server after updating environment variables
- Verify API keys don't contain extra spaces or quotes
2. HuggingFace API errors
- Ensure your API key has "Read" permissions
- Check if you've exceeded your monthly quota
- Some models may take time to "warm up" on first use
3. Google Translate API errors
- Verify the Translation API is enabled in Google Cloud Console
- Check your billing account is set up (required even for free tier)
- Ensure API key restrictions allow your server's IP
4. File upload issues
- Check file size (max 10MB)
- Verify file format (CSV, JSON, Excel, TXT only)
- Ensure upload directory has write permissions
Set NODE_ENV=development in your .env file to see detailed error messages and stack traces.
Monitor your API usage through the respective dashboards:
- HuggingFace: Usage Dashboard
- Google Cloud: Cloud Console Billing
- OpenAI: Usage Dashboard
The application provides built-in metrics at /api/health:
- Cache hit rates
- Processing times
- Error rates
The application is designed to work even without API keys:
- Without HuggingFace: Uses intelligent mock sentiment analysis
- Without Google Translate: Uses heuristic language detection
- Without OpenAI: Disables advanced summarization features
This allows you to:
- Test the application immediately
- Gradually add API keys as needed
- Maintain functionality during API outages
If you encounter issues:
- Check the console logs for detailed error messages
- Verify your API keys are correctly formatted
- Test individual API endpoints using the provided curl commands
- Check the respective API service status pages
Once your APIs are configured:
- Test all features with sample data
- Configure database connections for persistence
- Set up monitoring and alerting
- Deploy to your production environment
- Configure domain-specific rate limits
Note: The application will work with mock data even without API keys, allowing you to test the interface and functionality before setting up external services.