A simple API router for image generation models. This service acts as a proxy between your application and other image generation APIs, simplifying the process of using different models.
- OpenAI compatible API endpoint
- Rate limiting
- Free and paid model usage tracking
See API Reference
- Docker and Docker Compose
- API keys for the models you want to use
- Clone the repository
- Create a
.envfile and add your API keys - Follow instructions below to get Vertex API key
- Enable CORS for S3 image storage
Using Docker Compose:
docker compose upThe API will be available at http://localhost:4000
docker compose down && docker compose up -dTo run tests inside the Docker container:
# Run tests with console output visible
docker compose down && docker compose up -d
docker compose exec api npm test -- --verbosedocker compose -f docker-compose.generate.yml upGET /health
Example curl command:
curl http://localhost:3000/health- Rate limiting is enabled (100 requests per 15 minutes per IP)
- Security headers are implemented using Helmet
- CORS is enabled for cross-origin requests
- API key is required for image generation
Update: after the empty character streaming that I added to bypass Cloudflare timeouts, I'm not sure if this is still needed.
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
send_timeout 600s;
Create a public s3 bucket and update the .env.
- Add a new CNAME DNS record:
CNAME storage s3.provider.com
- Add CLoudflare transform rule:
Filter:
Hostname equals storage.imagerouter.io
# (http.host eq "storage.imagerouter.io")
Rewrite to Dynamic Redirectconcat("/file/BUCKET_NAME", http.request.uri.path)
- Allow CORS for storage:
Create a new HTTP Response Header Transform Rule:
Filter:
Hostname equals storage.imagerouter.io
# (http.host eq "storage.imagerouter.io")
Set static Access-Control-Allow-Origin *