A clean, performant REST API for Google's Gemini AI model that supports text generation, image analysis, document processing, and audio analysis.
- Text Generation: Generate content from text prompts
- Image Analysis: Analyze and describe images
- Document Processing: Extract and analyze document content
- Audio Analysis: Process and transcribe audio files
- Health Monitoring: Built-in health check endpoint
- File Validation: Secure file type and size validation
- Error Handling: Comprehensive error handling and recovery
- Node.js (v16 or higher)
- Google Gemini API key
- Clone the repository
- Install dependencies:
npm install
- Copy the environment template:
cp .env.example .env
- Edit
.envand add your Gemini API key:Gemini_API=your_actual_api_key_here
npm run devnpm startThe server will start on port 3000 (or the port specified in your .env file).
GET /healthPOST /generate-text
Content-Type: application/json
{
"prompt": "Your text prompt here"
}POST /generate-from-image
Content-Type: multipart/form-data
image: [image file]
prompt: "Optional custom prompt" (default: "Analyze this image:")POST /generate-from-document
Content-Type: multipart/form-data
document: [document file]
prompt: "Optional custom prompt" (default: "Analyze this document:")POST /generate-from-audio
Content-Type: multipart/form-data
audio: [audio file]
prompt: "Optional custom prompt" (default: "Analyze this audio:")All endpoints return responses in the following format:
{
"success": true,
"output": "Generated content here..."
}{
"success": false,
"error": "Error message",
"details": ["Additional error details if applicable"]
}- File Size Limit: 50MB maximum
- Request Body Limit: 10MB maximum
- Supported Image Types: All standard image formats
- Supported Document Types: PDF, DOC, DOCX, TXT
- Supported Audio Types: All standard audio formats
Environment variables:
| Variable | Required | Default | Description |
|---|---|---|---|
Gemini_API |
Yes | - | Your Google Gemini API key |
PORT |
No | 3000 | Server port number |
This codebase has been recently refactored for improved:
- Performance: Better memory management and file handling
- Security: Input validation and file type restrictions
- Maintainability: Modular code structure and error handling
- Standards: Following JavaScript best practices and linting rules
See REFACTOR_SUMMARY.md for detailed information about the improvements.
The API includes comprehensive error handling for:
- Invalid file types
- Missing required fields
- File upload failures
- API rate limits
- Network timeouts
- Invalid prompts
Use the /health endpoint to monitor server status:
curl http://localhost:3000/health- Follow the existing code style
- Add appropriate error handling
- Update documentation as needed
- Test all endpoints before submitting
ISC License