This is the secure backend server for the AI Portfolio project, powering the GPT-4o chatbot functionality.
- Environment Variables: API keys are stored securely in
.envfile (never committed) - Server-side API calls: OpenAI API key stays on the server, never exposed to frontend
- CORS enabled: Configured for secure cross-origin requests
- Serverless ready: Optimized for Vercel deployment
- https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip - Runtime environment
- https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip - Web server framework
- OpenAI GPT-4o - AI chatbot model
- dotenv - Environment variable management
- CORS - Cross-origin resource sharing
backend/
├── https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip # Express server (local development)
├── api/
│ └── https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip # Serverless API endpoint (Vercel)
├── https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip # Vercel deployment config
├── https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip # Dependencies
├── https://raw.githubusercontent.com/saadashrafai/Ai-Backend-Secure/main/api/Secure-Backend-Ai-saleroom.zip # Environment variable template
└── .gitignore # Protected files
npm installCreate a .env file in the root directory:
OPENAI_API_KEY=your-actual-openai-api-key-here.env file!
npm start
# or
npm run devThe server will start on http://localhost:3001
Sends messages to OpenAI GPT-4o and returns AI responses.
Request Body:
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant..."
},
{
"role": "user",
"content": "User message here"
}
],
"temperature": 0.8,
"max_tokens": 200
}Response:
{
"choices": [
{
"message": {
"role": "assistant",
"content": "AI response here"
}
}
]
}- Push this repo to GitHub
- Go to Vercel Dashboard
- Import your GitHub repository
- Add environment variable:
- Key:
OPENAI_API_KEY - Value: Your actual OpenAI API key
- Key:
- Deploy!
# Install Vercel CLI
npm install -g vercel
# Deploy
vercel
# Add environment variable
vercel env add OPENAI_API_KEY✅ DO:
- Keep
.envfile in.gitignore - Use environment variables for sensitive data
- Set API keys in Vercel dashboard for production
- Validate all incoming requests
❌ DON'T:
- Commit API keys to Git
- Expose API keys in frontend code
- Share
.envfile publicly - Hard-code sensitive credentials
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | ✅ Yes |
Get your API key from: OpenAI Platform
This backend is part of the AI Portfolio project. For frontend integration, see the main portfolio repository.
Private - All rights reserved
Saad Ashraf
- Specialized in AI automation and full-stack development
- Expert in GPT integration and secure API design