A simple API proxy for Google's Gemini 1.5 Pro AI, deployable to Vercel and accessible via cURL.
- POST endpoint to send prompts to Google's Gemini 1.5 Pro AI
- Secure API key handling via environment variables
- Error handling for missing prompts and API issues
- Ready for Vercel deployment
- Clone this repository
- Install dependencies:
npm install - Create a
.envfile in the root directory with your Gemini API key:GEMINI_API_KEY=your_api_key_here PORT=3000 # Optional for local development - Get your Gemini API key from Google AI Studio
Run the server locally:
npm start
The server will be available at http://localhost:3000.
-
Install Vercel CLI (if you haven't already):
npm install -g vercel -
Deploy to Vercel:
vercel -
Set up environment variables in the Vercel dashboard:
- Go to your project settings
- Add
GEMINI_API_KEYwith your API key
Send a prompt to the API:
# For local development
curl -X POST http://localhost:3000/api/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"Tell me a joke about programming"}'
# For Vercel deployment
curl -X POST https://your-vercel-url.vercel.app/api/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"Tell me a joke about programming"}'{
"prompt": "Tell me a joke about programming",
"response": "Why do programmers prefer dark mode? Because light attracts bugs!"
}The API includes error handling for:
- Missing prompts
- API key configuration issues
- Gemini API errors
- Rate limit exceeded errors (429)
Gemini API has usage quotas and rate limits that vary based on your API key type:
- Free tier keys have stricter limits
- Paid API keys have higher quotas
If you receive a 429 error, it means you've exceeded your current quota. Options to resolve:
- Wait and retry later
- Upgrade to a paid API key
- Implement rate limiting in your application
For more details, visit Google AI Studio's rate limits page.
ISC