Overview
The Generate Image API creates beautiful anime-style visualizations of Bhagavad Gita verses using AI. Images are generated via Replicate and cached in Supabase to avoid regeneration.This endpoint is rate limited to 5 requests per hour per user to manage AI generation costs.
Generate Image
Generate an anime-style image for a specific verse
Authentication
Required: Yes (Clerk session token)Request Body
Chapter number (1-18)
Verse number (1-78)
Response
Always “success”
Image generation result
Example Request
Example Response
Check Image Existence
Check if an image already exists for a verse (no authentication required)
Query Parameters
Chapter number (1-18)
Verse number (1-78)
Response
Returns the existing image data if found, ornull if no image exists.
Example Request
Example Response (Image Exists)
Example Response (No Image)
Technical Details
AI Model
- Provider: Replicate
- Model: Anime-style image generation
- Generation Time: 15-30 seconds
- Output Format: PNG image
Storage
Images are stored in Supabase with the following schema:| Field | Type | Description |
|---|---|---|
| id | uuid | Primary key |
| chapter | integer | Chapter number |
| verse | integer | Verse number |
| url | text | Replicate image URL |
| created_at | timestamp | Generation timestamp |
Rate Limiting
POST /api/generate-image: 5 requests per hour per user This strict rate limit helps manage AI generation costs while still providing reasonable access for users.Caching Strategy
- Before generating, check if image exists for the verse
- If exists, return cached URL immediately
- If not exists, generate via Replicate and store in Supabase
- Subsequent requests return the cached image
Sharing Generated Images
Generated images can be shared via the shareable page:- Full-size image display
- Download as PNG button
- Open Graph metadata for social media previews
- Link back to the original verse
Error Codes
| Status Code | Description |
|---|---|
| 200 | Success |
| 400 | Invalid chapter/verse numbers |
| 401 | Unauthorized (authentication required for POST) |
| 429 | Rate limit exceeded (5/hour) |
| 500 | Image generation failed or Replicate API error |
Usage Notes
Implementation Reference
Source:frontend/app/api/generate-image/route.ts
- POST handler: Lines 11-137
- GET handler: Lines 140-177
- Rate limiter: Line 9