This guide covers deploying the Whisperer API endpoints to Vercel for secure, scalable production use.
The Whisperer app uses Vercel as a secure proxy for OpenAI API calls, providing:
- Secure API Key Management: Keys stored as environment variables, never in client code
- Usage Monitoring: Built-in analytics and logging
- Global CDN: Fast response times worldwide
- Cost Control: Monitor and limit API usage
- Auto-scaling: Handles traffic spikes automatically
nix shell nixpkgs#nodejs_22 -c npx -y vercel --version# From the Whisperer project directory
make deploy
# Or manually:
vercel --prodIn your Vercel dashboard or via CLI:
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_CHAT_API_KEY production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_TRANSCRIBE_API_KEY production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_CHAT_MODEL production
# recommended value for OPENAI_CHAT_MODEL: gpt-4o-miniThe deployment creates three serverless functions:
- Method: POST
- Purpose: Proxy ChatGPT API calls
- Input: JSON with messages array
- Output: ChatGPT response
- Method: POST
- Purpose: Convert audio to text via Whisper
- Input: Multipart form with audio file
- Output: Transcribed text
- Method: GET
- Purpose: Verify API connectivity and status
- Output: Connection status and basic stats
Configure these in your Vercel dashboard:
| Variable | Description | Required |
|---|---|---|
OPENAI_CHAT_API_KEY |
OpenAI key used by /api/chat and /api/title |
Yes |
OPENAI_TRANSCRIBE_API_KEY |
OpenAI key used by /api/transcribe |
Yes (for voice transcription) |
OPENAI_CHAT_MODEL |
Chat model allowlist enforced server-side | Yes (gpt-4o-mini) |
WHISPERER_REQUEST_SIGNING_SECRET |
HMAC secret used to verify signed watch requests | Yes |
WHISPERER_CLIENT_ID |
Allowed client identifier (whisperer-watch) |
Yes |
OPENAI_API_KEY |
Legacy fallback key (all endpoints) | Optional |
- Go to your project settings
- Navigate to "Environment Variables"
- Add
OPENAI_API_KEYwith your key
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_CHAT_API_KEY production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_TRANSCRIBE_API_KEY production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_CHAT_MODEL production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add WHISPERER_REQUEST_SIGNING_SECRET production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add WHISPERER_CLIENT_ID production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env lsAfter deployment, update the API URL in your app:
- Open
Whisperer/APIService.swift - Update the
baseURL:
private let baseURL = "https://your-app-name.vercel.app"The project includes vercel.json for deployment configuration:
{
"functions": {
"api/chat.js": {
"maxDuration": 30
},
"api/transcribe.js": {
"maxDuration": 30
}
}
}- Store API keys as Vercel environment variables
- Never commit API keys to version control
- Use different keys for development/production
- Regularly rotate API keys
- Use separate keys for chat and transcription
- Restrict chat key to one model (
gpt-4o-mini) in OpenAI project settings
Use OpenAI Project API keys (not a global org key):
- Create a new OpenAI project named
Whisperer. - Set a low monthly project budget and alerts.
- Under model permissions, allow only
gpt-4o-minifor chat usage. - Create a project API key for chat and store it as
OPENAI_CHAT_API_KEY. - If you use voice transcription, create a second key with transcription access and store it as
OPENAI_TRANSCRIBE_API_KEY. - Set
OPENAI_CHAT_MODEL=gpt-4o-miniin Vercel so the server ignores client-supplied models. - Generate a long random secret (at least 32 bytes) and store it as
WHISPERER_REQUEST_SIGNING_SECRET. - Set
WHISPERER_CLIENT_ID=whisperer-watch.
- Validate request formats
- Implement rate limiting if needed
- Log suspicious activity
The API endpoints include proper CORS headers for web access while maintaining security.
- View function invocations
- Monitor response times
- Track error rates
- Analyze usage patterns
- Monitor API usage in OpenAI dashboard
- Set up usage alerts
- Track costs per endpoint
# Link to your Vercel project
nix shell nixpkgs#nodejs_22 -c npx -y vercel link
# Pull environment variables
nix shell nixpkgs#nodejs_22 -c npx -y vercel env pull .env.local
# Run locally
nix shell nixpkgs#nodejs_22 -c npx -y vercel dev# Test health check
curl https://your-app.vercel.app/api/stats
# Test chat endpoint
curl -X POST https://your-app.vercel.app/api/chat \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Hello"}]}'make deploy # Deploy to productionvercel --prod # Deploy to production
vercel # Deploy to preview
vercel dev # Run locally# Check environment variables
nix shell nixpkgs#nodejs_22 -c npx -y vercel env ls
# Add missing variables
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_CHAT_API_KEY production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_TRANSCRIBE_API_KEY production
nix shell nixpkgs#nodejs_22 -c npx -y vercel env add OPENAI_CHAT_MODEL production- Increase
maxDurationinvercel.json - Optimize API calls
- Check OpenAI API response times
- Verify CORS headers in API functions
- Check request origins
- Update allowed origins if needed
- Verify key is correctly set in Vercel
- Check key permissions in OpenAI dashboard
- Ensure key hasn't expired
# View function logs
nix shell nixpkgs#nodejs_22 -c npx -y vercel logs
# Run with verbose output
nix shell nixpkgs#nodejs_22 -c npx -y vercel --debug- Function invocations (generous free tier)
- Bandwidth usage
- Build minutes
- Monitor token usage
- Implement request caching if appropriate
- Set usage limits in OpenAI dashboard
- Environment variables configured
- API endpoints tested
- App updated with production URL
- Monitoring set up
- Usage limits configured
- Security review completed
- Backup deployment strategy
vercel domains add your-domain.comvercel teams switch your-team- Use different Vercel projects for staging/production
- Configure environment-specific variables
- Implement proper CI/CD workflows
For Vercel-specific issues:
For OpenAI API issues:
- Endpoint:
/api/chat - Method: POST
- Purpose: Proxy for OpenAI chat completions
- Headers:
X-Device-IDfor usage tracking
- Endpoint:
/api/transcribe - Method: POST
- Purpose: Proxy for OpenAI Whisper transcriptions
- Headers:
X-Device-IDfor usage tracking
The Vercel functions automatically log:
- Device IDs for usage tracking
- Token usage for chat completions
- Request timestamps
- Error rates
View logs in the Vercel dashboard under "Functions" -> "View Function Logs"
- No API Keys in App: The watch app no longer contains OpenAI API keys
- Centralized Management: All API keys are managed in Vercel
- Usage Tracking: Monitor API usage per device
- Rate Limiting: Can be easily added to the Vercel functions
- Access Control: Can restrict access by device ID or other criteria
The Vercel integration automatically:
- Deploys on pushes to the main branch
- Runs in preview mode for pull requests
- Provides deployment URLs for testing
For local development:
- Copy
.env.exampleto.env - Add your OpenAI API key to
.env - Run the Vercel dev server:
vercel dev- Update
APIService.swiftto usehttp://localhost:3000for local testing
- API Key Not Found: Ensure
OPENAI_API_KEYis set in Vercel environment variables - CORS Errors: The API includes CORS headers, but ensure your app's URL is correct
- Timeout Issues: Increase timeout values if needed for large audio files
Check Vercel function logs for detailed error information:
vercel logsMonitor OpenAI API costs through:
- Vercel function logs (token usage)
- OpenAI dashboard usage statistics
- Custom analytics (can be added to the API functions)
Consider adding:
- Rate limiting per device
- User authentication
- Advanced usage analytics
- Caching for frequently used responses
- Error retry mechanisms