# nano **Repository Path**: coderz/nano ## Basic Information - **Project Name**: nano - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-14 - **Last Updated**: 2025-09-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Nano Banana Server A Node.js server that interfaces with Google's Gemini 2.5 Flash Image (Nano Banana) API for AI-powered image generation and editing. ## Features - **Text-to-Image Generation**: Generate images from text prompts - **Image Editing**: Modify existing images using natural language instructions - **Multi-Image Composition**: Combine multiple images with text prompts - **Conversational Chat**: Interactive image generation through chat interface - **Rate Limiting**: Built-in rate limiting to prevent API abuse - **Security**: Helmet.js for security headers, CORS support - **Error Handling**: Comprehensive error handling and logging ## Prerequisites - Node.js 16.x or higher - Google Cloud API Key with Gemini API access ## Installation 1. Clone the repository: ```bash git clone cd nano ``` 2. Install dependencies: ```bash npm install ``` 3. Configure environment variables: ```bash cp .env.example .env ``` 4. Edit `.env` and add your Google API key: ``` GEMINI_API_KEY=your_actual_api_key_here ``` ## Configuration Environment variables in `.env`: - `GEMINI_API_KEY`: Your Google Cloud API key (required) - `PORT`: Server port (default: 3000) - `NODE_ENV`: Environment mode (development/production) - `CORS_ORIGIN`: CORS origin configuration (default: *) - `RATE_LIMIT_WINDOW_MS`: Rate limit window in milliseconds (default: 60000) - `RATE_LIMIT_MAX_REQUESTS`: Maximum requests per window (default: 10) - `MAX_FILE_SIZE_MB`: Maximum upload file size in MB (default: 10) ## Usage ### Start the server Development mode (with auto-reload): ```bash npm run dev ``` Production mode: ```bash npm start ``` ### API Endpoints #### Health Check ``` GET /health ``` #### API Status ``` GET /api/status ``` #### Generate Image ``` POST /api/generate Content-Type: application/json { "prompt": "A photorealistic portrait of an elderly Japanese ceramicist", "temperature": 1.0, // optional (0.0-2.0) "topP": 0.95, // optional (0.0-1.0) "topK": 40 // optional } ``` #### Edit Image ``` POST /api/edit Content-Type: multipart/form-data image: prompt: "Make the background a sunset" temperature: 1.0 // optional topP: 0.95 // optional topK: 40 // optional ``` #### Compose Multiple Images ``` POST /api/compose Content-Type: multipart/form-data images: images: images: // max 3 images prompt: "Combine these images into a collage" temperature: 1.0 // optional topP: 0.95 // optional topK: 40 // optional ``` #### Chat Interface ``` POST /api/chat Content-Type: application/json { "messages": [ { "role": "user", "content": "Generate an image of a sunset" } ], "temperature": 1.0, // optional "topP": 0.95, // optional "topK": 40 // optional } ``` ### Response Format All endpoints return responses in the following format: Success: ```json { "success": true, "data": { "images": [ { "mimeType": "image/png", "base64": "...", "dataUrl": "data:image/png;base64,..." } ], "text": "Generated image description" } } ``` Error: ```json { "error": "Error type", "message": "Error description" } ``` ## Client Integration Example ### JavaScript/Fetch ```javascript // Generate image const response = await fetch('http://localhost:3000/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: 'A beautiful landscape' }) }); const result = await response.json(); if (result.success) { const imageUrl = result.data.images[0].dataUrl; // Display the image } ``` ### File Upload Example ```javascript // Edit image const formData = new FormData(); formData.append('image', fileInput.files[0]); formData.append('prompt', 'Make it more colorful'); const response = await fetch('http://localhost:3000/api/edit', { method: 'POST', body: formData }); const result = await response.json(); ``` ## Rate Limiting The API implements rate limiting to prevent abuse: - Default: 10 requests per minute for general API endpoints - Strict: 5 requests per minute for image generation endpoints ## Security - CORS enabled (configurable origin) - Helmet.js for security headers - File type validation (JPEG, PNG, GIF, WebP only) - File size limits (default 10MB) - API key validation ## Error Codes - `400`: Bad Request - Invalid parameters or missing required fields - `403`: Permission Denied - Invalid or missing API key - `429`: Too Many Requests - Rate limit exceeded - `500`: Internal Server Error - Server or API error ## Development Project structure: ``` nano/ ├── src/ │ ├── config/ # Configuration files │ ├── controllers/ # Request handlers │ ├── middleware/ # Express middleware │ ├── routes/ # API routes │ ├── services/ # Business logic │ └── server.js # Main server file ├── .env # Environment variables ├── .env.example # Environment template ├── package.json # Dependencies └── README.md # Documentation ``` ## Troubleshooting 1. **API Key Issues**: Ensure your Google Cloud API key has Gemini API access enabled 2. **Rate Limiting**: If you hit rate limits, wait for the window to reset (default 60 seconds) 3. **File Upload Errors**: Check file size and format requirements 4. **CORS Issues**: Configure `CORS_ORIGIN` in `.env` for your client domain ## License ISC ## Support For issues or questions, please create an issue in the repository.