Overview
Cabina uses Kie.ai (formerly Banana.dev) with the Nano Banana Pro model for AI-powered photo transformations. The integration is built around:- Model: Nano Banana Pro (2K resolution, fast inference)
- API: Kie.ai REST API
- Load Balancing: API key pool for distributed requests
- Storage: Two-tier upload (Kie.ai CDN + Supabase fallback)
Architecture
Kie.ai Setup
1. Create Account
Sign up
Go to kie.ai and create an account
Get API key
- Navigate to Dashboard → API Keys
- Click “Create new key”
- Copy the key (format:
abc123def456...)
2. Configure in Supabase
3. Add to API Key Pool (Optional)
For load balancing across multiple accounts:Model Configuration
Nano Banana Pro Specs
| Parameter | Value | Notes |
|---|---|---|
| Model ID | nano-banana-pro | Fast, high-quality |
| Max Resolution | 2K | 2048px on longest side |
| Aspect Ratios | All standard | 1:1, 3:4, 4:3, 9:16, 16:9 |
| Output Format | PNG, JPEG, WebP | PNG recommended |
| Inference Time | 10-30s | Depends on queue |
| Cost | ~$0.01/image | Check current pricing |
Generation Parameters
Default configuration used in Cabina:AI Prompts
Prompt Structure
Prompts are stored in theidentity_prompts table:
Example Prompts
Peaky Blinders Style:Prompt Best Practices
Be specific
Detailed descriptions produce better results
Use style references
Reference known movies, shows, or art styles
Describe lighting
Lighting is critical for photo realism
Add quality tags
Include “4K”, “professional”, “sharp focus”
Managing Prompts
supabase/functions/cabina-vision/index.ts:143-148
API Key Load Balancing
How It Works
- Function queries
api_key_poolfor active keys - Selects least recently used key
- Uses that key for the request
- Updates
last_used_atandusage_count
supabase/functions/cabina-vision/index.ts:27-46
Benefits
- Rate limit avoidance - Distributes load across accounts
- Fault tolerance - If one key fails, others continue working
- Cost distribution - Spreads usage across multiple billing accounts
Managing the Pool
Photo Upload Pipeline
Two-Tier Upload Strategy
- Primary: Kie.ai CDN upload (fast, globally distributed)
- Fallback: Supabase Storage (reliable, integrated)
supabase/functions/cabina-vision/index.ts:90-138
Generation Flow
1. Create Task
supabase/functions/cabina-vision/index.ts:152-165
2. Poll for Result
supabase/functions/cabina-vision/index.ts:185-216
3. Store Result
supabase/functions/cabina-vision/index.ts:224-237
Error Handling
Common Errors
Insufficient credits in Kie.ai accountSolution:
- Top up credits in Kie.ai dashboard
- Add backup API key with credits to pool
Invalid API credentialsSolution:
- Verify
BANANA_API_KEYsecret - Check API key is active in Kie.ai dashboard
- Ensure no typos in key
Photo upload failed on both tiersSolution:
- Check image size (max ~5MB)
- Verify image is valid base64
- Ensure Supabase storage bucket exists
AI generation task failedPossible causes:
- Inappropriate content detected
- Malformed prompt
- Server-side error
- Check Kie.ai dashboard for details
- Retry with different photo
- Review prompt for issues
Performance Optimization
Client-Side
Server-Side
- Use API key pool to distribute load
- Implement client-side polling instead of server-side for faster response
- Cache prompts to avoid DB queries
Monitoring
Cost Analysis
Kie.ai Pricing
Typical costs (check current pricing):- Per image: ~$0.01 USD
- Bulk discount: Available for >10,000 images/month
- Storage: Free via Kie.ai CDN (temporary)
Cost per Credit
If 1 credit = 1 generation:Reducing Costs
- Use lower resolution for previews
- Implement rate limiting
- Cache popular transformations
- Negotiate bulk pricing with Kie.ai
Next Steps
cabina-vision API
Complete API reference
Database Schema
Understand data structure