Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

✨ Free AI Image Generation API ⚡

Typing SVG

Live API Cloudflare AI License


📝 Prompt → ⚡ API → 🤖 AI → 🎨 Image


🚀 Deploy your own free AI image generation API in minutes!


🌐 Try the Live API

🚀 Your AI Image Generation API is Live

Open Live API



🔗 API Endpoint

https://farukhetro.farukhetro.workers.dev


✨ What Is This?

This project lets you deploy your own AI image generation API using Cloudflare Workers AI.

Generate stunning images from text prompts without managing expensive GPU servers or traditional backend infrastructure.

                    ✨ YOUR IDEA
                         │
                         ▼
                  📝 TEXT PROMPT
                         │
                         ▼
                ┌─────────────────┐
                │   ⚡ API CALL   │
                └────────┬────────┘
                         │
                         ▼
                ┌─────────────────┐
                │ ☁️ CLOUDFLARE   │
                │     WORKER      │
                └────────┬────────┘
                         │
                         ▼
                ┌─────────────────┐
                │ 🤖 WORKERS AI   │
                │   AI MODEL      │
                └────────┬────────┘
                         │
                         ▼
                ┌─────────────────┐
                │  🎨 AI IMAGE    │
                └─────────────────┘

💡 The idea is simple:

Write a prompt → Send an API request → Get an AI-generated image.


✨ Features

Feature Description
🆓 100,000 Calls/Day Cloudflare Workers AI free-tier allowance, subject to current limits
Lightning Fast Serverless image generation
🎨 AI Image Generation Turn text prompts into images
📏 Custom Aspect Ratios 1:1, 16:9, 9:16, 2:3, 3:2, 4:5, 5:4
🔒 Secure API Bearer-token authentication
🤖 Multiple Models Use supported Cloudflare AI models
☁️ Serverless No VPS or GPU server required
🛠️ Easy Deployment Get started in minutes
🌍 Global Infrastructure Powered by Cloudflare

🎬 Animated Workflow

flowchart LR
    A["📝 Prompt"] --> B["⚡ API"]
    B --> C["☁️ Worker"]
    C --> D["🔐 Auth"]
    D --> E["🤖 Workers AI"]
    E --> F["🎨 Generate"]
    F --> G["📦 Image"]

    style A stroke-width:2px
    style B stroke-width:2px
    style C stroke-width:2px
    style D stroke-width:2px
    style E stroke-width:2px
    style F stroke-width:2px
    style G stroke-width:2px
Loading

🚀 How It Works

01 — 📝 Write

Create a simple text prompt describing the image you want.

A futuristic city floating above the clouds,
cinematic lighting, highly detailed

02 — ⚡ Send

Send your prompt to your Worker API.

POST / 
Authorization: Bearer YOUR_API_KEY

03 — 🤖 Generate

Your Cloudflare Worker sends the request to Workers AI.

Prompt
  ↓
Cloudflare Worker
  ↓
Workers AI
  ↓
AI Model

04 — 🎨 Receive

The API returns the generated image.

📝 Prompt
   ↓
⚡ API
   ↓
🤖 AI
   ↓
🎨 IMAGE

📋 Setup Instructions

1. 🌟 Create a Cloudflare Account

If you don't already have one, create an account on Cloudflare.


2. ⚡ Create a New Worker

Go to the Cloudflare Workers Dashboard.

Choose:

Create application
       ↓
Create Worker
       ↓
Choose a name
       ↓
Deploy

Example:

free-image-generation-api

3. 🔧 Replace the Worker Code

Open the Worker editor and replace the default Hello World code with the worker.js code from this repository.

Then click:

Save and Deploy

✅ Your Worker is now deployed.


4. 🔑 Configure Your API Key

Go to:

Worker
  ↓
Settings
  ↓
Variables
  ↓
Environment Variables

Add:

API_KEY=your-secret-api-key

Replace your-secret-api-key with a strong random secret.

🔒 Never expose your API key publicly or commit it to GitHub.


5. 🤖 Enable Workers AI

In your Cloudflare dashboard:

Workers & Pages
       ↓
AI
       ↓
Workers AI

Enable Workers AI for your account.

⚠️ Free-tier availability and limits may change. Check Cloudflare's current documentation before relying on specific quotas.


6. 🔗 Add the AI Binding

Go to:

Worker
  ↓
Settings
  ↓
Variables
  ↓
Service Bindings

Click Add binding.

Use:

Variable name: AI
Service: Workers AI

Then:

Save and Deploy

⚠️ Important: Without the AI binding, your Worker cannot access Workers AI models.


🌐 Your Live API

Once deployed, your endpoint will look like:

https://<your-worker-name>.<your-subdomain>.workers.dev

🚀 This project's live endpoint:

https://farukhetro.farukhetro.workers.dev

🎯 Usage

⚙️ API Parameters

Parameter Type Required Default Description
prompt string Description of the image
aspect_ratio string 1:1 Desired image aspect ratio

📏 Supported Aspect Ratios

1:1     → Square
16:9    → Landscape
9:16    → Portrait
2:3     → Portrait
3:2     → Landscape
4:5     → Portrait
5:4     → Landscape

🖥️ cURL Example

curl -X POST https://farukhetro.farukhetro.workers.dev \
  -H "Authorization: Bearer your-secret-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A cute robot cooking breakfast",
    "aspect_ratio": "16:9"
  }' \
  --output image.jpg

🎨 Result

        📝 Prompt
           │
           ▼
       ⚡ API Call
           │
           ▼
        🤖 AI
           │
           ▼
      ┌───────────┐
      │ 🎨 IMAGE  │
      └───────────┘

🌐 JavaScript Example

const res = await fetch(
  "https://farukhetro.farukhetro.workers.dev",
  {
    method: "POST",

    headers: {
      "Authorization": "Bearer your-secret-api-key",
      "Content-Type": "application/json",
    },

    body: JSON.stringify({
      prompt: "A futuristic city in the clouds",
      aspect_ratio: "16:9"
    }),
  }
);

const blob = await res.blob();

const img = document.createElement("img");

img.src = URL.createObjectURL(blob);

img.style.height = "500px";
img.style.maxWidth = "100%";

document.body.appendChild(img);

🧠 Prompt Examples

🤖 Robot

A cute futuristic robot cooking breakfast
inside a modern kitchen, cinematic lighting,
high detail, realistic photography

🌆 Cyberpunk

A futuristic cyberpunk city at night,
neon lights, flying cars, rainy streets,
cinematic atmosphere, ultra detailed

🏔️ Landscape

A peaceful mountain landscape during golden hour,
dramatic clouds, beautiful natural lighting,
cinematic photography

🚀 Sci-Fi

An astronaut exploring an alien planet,
massive mountains in the background,
cinematic lighting, highly detailed concept art

🎯 Use Cases

This API can power:

🎨 AI Art Platforms
🖼️ Image Generation Websites
📱 Mobile Applications
🤖 AI Assistants
💬 Discord / Telegram Bots
📰 Blog Image Generators
📢 Social Media Content
🛍️ E-Commerce Images
🎮 Game Assets
🧑‍💻 Developer Tools

☁️ Why Cloudflare Workers?

Traditional AI image generation can require expensive infrastructure.

This project uses a serverless architecture instead.

TRADITIONAL APPROACH
─────────────────────

💻 VPS
   ↓
🎮 GPU
   ↓
💰 Infrastructure Costs
   ↓
🔧 Server Maintenance


THIS PROJECT
────────────

☁️ Cloudflare
   ↓
⚡ Worker
   ↓
🤖 Workers AI
   ↓
🎨 Generated Image

No need for:

❌ VPS
❌ Dedicated GPU
❌ Traditional backend server
❌ Always-running process
❌ Complex infrastructure

Just:

✅ Cloudflare
✅ Worker
✅ AI Binding
✅ API Key

🔐 Security

Your API key protects your image-generation endpoint.

❌ Don't do this:

const API_KEY = "my-secret-key";

inside publicly accessible frontend code.

✅ Keep secrets server-side:

🌐 Frontend
     │
     ▼
🖥️ Your Backend
     │
     ▼
☁️ Cloudflare Worker
     │
     ▼
🤖 Workers AI

Never commit secrets such as:

.env
.env.local
API_KEY
API_SECRET
ACCESS_TOKEN

to your repository.


🛠️ Customize It

You can modify the Worker for your own project.

Component Customize
🤖 AI Model Change the Workers AI model
🎨 Prompts Add prompt processing
📏 Images Modify aspect ratios
🔐 Authentication Add custom authentication
🚦 Rate Limits Add request limits
🌐 CORS Configure allowed origins
📊 Analytics Track API usage
🖥️ Frontend Build your own interface

📊 Architecture

                         🌍 INTERNET
                              │
                              ▼
                     ┌─────────────────┐
                     │   Your Client   │
                     │ Web / App / Bot │
                     └────────┬────────┘
                              │
                              │ HTTPS
                              ▼
                     ┌─────────────────┐
                     │ ☁️ Cloudflare   │
                     │     Worker     │
                     └────────┬────────┘
                              │
                         🔐 API KEY
                              │
                              ▼
                     ┌─────────────────┐
                     │ 🤖 Workers AI   │
                     │                 │
                     │   AI Model      │
                     └────────┬────────┘
                              │
                              ▼
                     ┌─────────────────┐
                     │   🎨 IMAGE      │
                     │   GENERATED     │
                     └─────────────────┘

📝 Notes

🆓 Free Tier

Cloudflare Workers AI provides a free usage allowance subject to Cloudflare's current pricing, limits, and account terms.

The commonly referenced 100,000 AI requests/day allowance may change.

Check the latest information on Cloudflare Workers AI and Cloudflare pricing.

🎨 Models

You can change the model inside worker.js to use other models supported by Cloudflare Workers AI.

🔒 Security

Keep your API key private.

If your key is compromised:

🚨 Revoke
   ↓
🔄 Rotate
   ↓
🔐 Generate a new secret

🧪 Testing Checklist

Before using the API in production:

☐ Worker deployed
☐ Workers AI enabled
☐ AI binding configured
☐ API_KEY configured
☐ Authentication tested
☐ Image generation tested
☐ Aspect ratios tested
☐ Error handling tested
☐ API key protected
☐ Current usage limits reviewed

⭐ Project Stats

GitHub Stars GitHub Forks License

🤝 Contributing

Contributions are welcome! 🎉

1. 🍴 Fork the repository
2. 🌿 Create a branch
3. 🛠️ Make your changes
4. 🧪 Test your changes
5. 💾 Commit your changes
6. 🚀 Push your branch
7. 🔀 Open a Pull Request

Have an idea?

Open an issue and let's build it together. 🚀


⭐ Support

If this project helped you:

⭐ Star the repository

🍴 Fork it

🛠️ Build something amazing

📢 Share it with other developers


Star Repository

📄 License

This project is licensed under the MIT License.

See LICENSE for the complete license.


Animated Footer



Try Live API



Made with ❤️ for the open-source AI community


⭐ Star it if you found it useful!

About

Free AI image generation API powered by Cloudflare Workers AI. Deploy your own secure image-generation API with API key authentication, multiple AI models, and custom aspect ratios — up to 100,000 AI requests per day on the free tier.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages