Text to Image generation app for you that uses Fal.ai's SDXL model via DigitalOcean's serverless inference API.
A web application that generates images using Fal.ai's Stable Diffusion XL model via DigitalOcean's Serverless Inference API.
- 🎨 Generate high-quality images from text prompts
- ⚡ Fast SDXL model for quick generation
- 🎛️ Advanced controls (inference steps, guidance scale)
- 📥 Download generated images
- 🌐 Responsive web interface
- ☁️ Deploy to DigitalOcean App Platform
- DigitalOcean Account with access to Gradient AI Platform
- Opt-in to Fal.ai models in DigitalOcean console:
- Go to: https://cloud.digitalocean.com/account/feature-preview?feature=fal-models
- Enable the feature preview
- API Access Token from DigitalOcean
git clone <your-repo-url>
cd fal-ai-image-generatornpm installCreate a .env file in the root directory:
cp .env.example .envEdit .env and add your DigitalOcean API key:
MODEL_ACCESS_KEY=your_digitalocean_api_key_here
PORT=3000
To get your API key:
- Go to: https://cloud.digitalocean.com/account/api/tokens
- Click "Generate New Token"
- Give it a name and select appropriate scopes
- Copy the token and paste it in your
.envfile
# Development mode (with auto-restart)
npm run dev
# Production mode
npm startOpen your browser and navigate to: http://localhost:3000
fal-ai-image-generator/
├── server.js # Express backend server
├── public/
│ └── index.html # Frontend interface
├── package.json # Node.js dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore file
└── README.md # This file
- Push your code to GitHub
git init
git add .
git commit -m "Initial commit"
git remote add origin <your-github-repo-url>
git push -u origin main-
Create a new App on DigitalOcean
- Go to: https://cloud.digitalocean.com/apps
- Click "Create App"
- Select "GitHub" as the source
- Choose your repository
- DigitalOcean will auto-detect the Node.js app
-
Configure the App
- Name:
fal-ai-image-generator - Region: Choose closest to you
- Plan: Basic ($5/month minimum)
- Environment Variables: Add
MODEL_ACCESS_KEY - Build Command:
npm install - Run Command:
npm start - HTTP Port: 3000
- Name:
-
Add Environment Variable
- In the App settings, go to "Settings" → "App-Level Environment Variables"
- Add:
MODEL_ACCESS_KEY=your_digitalocean_api_key
-
Deploy
- Click "Create Resources"
- Wait for deployment to complete
- Your app will be available at:
https://your-app-name.ondigitalocean.app
# Install doctl
# macOS: brew install doctl
# Other: https://docs.digitalocean.com/reference/doctl/how-to/install/
# Authenticate
doctl auth init
# Create app.yaml configuration file
cat > app.yaml << EOF
name: fal-ai-image-generator
region: nyc
services:
- name: web
github:
repo: your-username/your-repo
branch: main
build_command: npm install
run_command: npm start
http_port: 3000
environment_slug: node-js
instance_count: 1
instance_size_slug: basic-xxs
envs:
- key: MODEL_ACCESS_KEY
value: your_digitalocean_api_key
type: SECRET
EOF
# Deploy
doctl apps create --spec app.yamlGenerate an image from a text prompt.
Request Body:
{
"prompt": "A futuristic city at sunset",
"num_inference_steps": 4,
"guidance_scale": 3.5,
"num_images": 1
}Response:
{
"success": true,
"data": {
"images": [
{
"url": "https://...",
"width": 1024,
"height": 768
}
]
}
}Health check endpoint.
Response:
{
"status": "healthy",
"timestamp": "2025-01-01T00:00:00.000Z"
}- num_inference_steps (1-8): Higher values = better quality but slower (default: 4)
- guidance_scale (1-10): How closely to follow the prompt (default: 3.5)
- output_format: Image aspect ratio (default: landscape_4_3)
- num_images (1-4): Number of images to generate (default: 1)
- Make sure you've created a
.envfile with your API key - Check that the environment variable is set correctly in DigitalOcean App Platform
- The model might be cold-starting (first request can take longer)
- Try again in a few seconds
- Check DigitalOcean's status page for any API issues
- Check that you've opted into the Fal.ai models feature preview
- Verify your API key has the correct permissions
- Check the server logs for detailed error messages
- DigitalOcean App Platform automatically sets the PORT environment variable
- The app is configured to use
process.env.PORTor default to 3000
- DigitalOcean App Platform: $5-12/month (Basic plan)
- API Calls: Check current pricing at https://www.digitalocean.com/pricing/gradient-ai-platform
- First-time users: May qualify for credits
- DigitalOcean Gradient AI Platform Docs
- Serverless Inference API
- Fal.ai Documentation
- Blog Post: Fal.ai on DigitalOcean
MIT
For issues and questions:
- GitHub Issues: Create an issue in this repository
- DigitalOcean Support: https://docs.digitalocean.com/support/
- Community: https://www.digitalocean.com/community/