# OpenAI API Setup (Alternative to Vertex AI)
The LinkedIn Lead Automation MCP Server now supports **OpenAI API** as an alternative to Vertex AI. This is useful if you:
- Want to avoid Google Cloud setup complexity
- Hit rate limits/quota issues with Vertex AI (429 errors)
- Prefer OpenAI's simpler API
- Want to use GPT-4o model
## Quick Setup
### 1. Set Environment Variables in Vercel
Add these environment variables:
```bash
# Choose AI Provider: 'openai' or 'vertex' (default: 'vertex')
AI_PROVIDER=openai
# OpenAI API Key (get from https://platform.openai.com/api-keys)
OPENAI_API_KEY=sk-...
# Optional: OpenAI Model (default: 'gpt-4o')
OPENAI_MODEL_ID=gpt-4o
```
### 2. Available OpenAI Models
- `gpt-4o` - Latest, most capable model (recommended)
- `gpt-4o-mini` - Faster, cheaper alternative
- `gpt-4-turbo` - Previous generation
- `gpt-3.5-turbo` - Fastest, cheapest (less capable)
### 3. Update Vercel Environment Variables
1. Go to your Vercel project: https://vercel.com/dashboard
2. Navigate to **Settings** → **Environment Variables**
3. Add/Update:
- `AI_PROVIDER` = `openai`
- `OPENAI_API_KEY` = `sk-...` (your OpenAI API key)
- `OPENAI_MODEL_ID` = `gpt-4o` (optional, defaults to gpt-4o)
4. **Save** and **Redeploy**
### 4. Test Configuration
After redeploy, test with:
```bash
curl -X POST "https://linkedin-mcp-mocha.vercel.app/api/products/analyze" \
-H "Content-Type: application/json" \
-d '{
"api_key": "YOUR_API_KEY",
"name": "AmroPilot",
"website_url": "https://amropilot.com",
"description": "AmroPilot is an AI-powered content creation platform",
"value_proposition": "Transform your content strategy with AI",
"target_audience": "Content creators, SEO professionals, digital marketers"
}' | python -m json.tool
```
## Switching Between Providers
### To Use OpenAI:
```bash
AI_PROVIDER=openai
OPENAI_API_KEY=sk-...
```
### To Use Vertex AI (Default):
```bash
AI_PROVIDER=vertex
# OR simply remove AI_PROVIDER and it defaults to vertex
GOOGLE_APPLICATION_CREDENTIALS_JSON={...}
GCP_PROJECT_ID=amgn-app
GCP_LOCATION=global
ANTHROPIC_MODEL_ID=claude-opus-4-5
```
## Rate Limits & Retry Logic
Both providers include automatic retry with exponential backoff:
- **429 (Rate Limit)**: Automatically retries up to 3 times
- **503 (Service Unavailable)**: Automatically retries up to 3 times
- **Wait times**: 1s, 2s, 4s (max 30s)
## Cost Comparison
### OpenAI (GPT-4o)
- **Input**: ~$2.50 per 1M tokens
- **Output**: ~$10.00 per 1M tokens
- **Rate Limits**: Varies by tier (tier 1: 500 RPM, tier 2: 5000 RPM)
### Vertex AI (Claude Opus 4.5)
- **Input**: ~$3.13 per 1M tokens (INR 281)
- **Output**: Varies
- **Rate Limits**: Based on project quota
## Which Provider to Choose?
### Choose OpenAI if:
- ✅ You want simpler setup (just API key)
- ✅ You need faster responses
- ✅ You hit Vertex AI quota limits
- ✅ You prefer OpenAI's API
### Choose Vertex AI if:
- ✅ You're already using Google Cloud
- ✅ You want Claude Opus 4.5 (more powerful for complex tasks)
- ✅ You have Google Cloud credits/budget
- ✅ You need specific regional deployment
## Troubleshooting
### Error: "OPENAI_API_KEY environment variable is required"
- Make sure `OPENAI_API_KEY` is set in Vercel
- Redeploy after adding environment variables
### Error: "Incorrect API key provided"
- Verify your API key starts with `sk-`
- Check the key hasn't expired
- Regenerate key at https://platform.openai.com/api-keys
### Error: "429 Rate Limit"
- Wait a few minutes and retry
- Upgrade your OpenAI tier for higher limits
- The system auto-retries, so just wait
### Switching Back to Vertex AI
- Set `AI_PROVIDER=vertex` or remove `AI_PROVIDER`
- Make sure Vertex AI credentials are still configured