Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

✨ Free AI Image Generation API (100,000 Calls/Day) ⚡

GitHub stars License Cloudflare AI

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

This project lets you deploy your own free AI image generation API using Cloudflare Workers, with up to 100,000 API calls per day. Generate stunning images from text prompts using powerful models like Stable Diffusion XL! 🎨

✨ Features

  • 🆓 100,000 free API calls per day (Cloudflare Workers AI free tier)
  • Lightning-fast image generation from text prompts
  • 🛠️ Easy to deploy - no coding experience required
  • 🔒 Secure with API key authentication
  • 🎯 Multiple AI models available

🚀 How It Works

  • 📤 You deploy a Cloudflare Worker using the provided worker.js file
  • 🌐 The Worker exposes a simple API endpoint for image generation
  • 🔐 You authenticate using your own API key
  • 🤖 The Worker uses Cloudflare's free AI models to generate images

📋 Setup Instructions

1. 🌟 Get a Cloudflare Account

2. ⚡ Create a New Worker

  • Go to the Cloudflare Workers dashboard
  • Click "Create application" 🎯
  • Choose "Create Worker"
  • Give it a name like free-image-generation-api 📝
  • Click "Deploy" to create a Hello World worker 🚀

3. 🔧 Replace the Worker Code

  • In the worker editor, replace the default Hello World code with the worker.js code from this repo 📄
  • Click "Save and Deploy"

4. 🔑 Set Up Environment Variables

  • In your worker dashboard, go to "Settings" > "Variables" ⚙️
  • Under "Environment Variables", click "Add variable"
  • Name: API_KEY 🏷️
  • Value: your-secret-api-key (replace with a strong secret key) 🔒
  • Click "Save and Deploy" 💾

5. 🤖 Enable Workers AI

  • In the Cloudflare dashboard, go to "Workers & Pages" > "AI" 🧠
  • Enable Workers AI for your account (free tier is enough) 🆓

6. 🔗 Add AI Binding to Your Worker

  • Go back to your worker's dashboard
  • Click on "Settings" > "Variables" ⚙️
  • Scroll down to "Service bindings" section
  • Click "Add binding"
  • Variable name: AI 🏷️
  • Service: Select "Workers AI" from dropdown 🤖
  • Click "Save and Deploy"

⚠️ Important: Without this AI binding, your worker won't be able to access Cloudflare's AI models!

7. 🌐 Get Your Worker URL

  • Your worker will be available at: https://<your-worker-name>.<your-subdomain>.workers.dev 🔗
  • You can find the exact URL in your worker's dashboard 📍

🎯 Usage

🖥️ cURL Example

curl -X POST https://<your-worker-name>.<your-subdomain>.workers.dev \
  -H "Authorization: Bearer your-secret-api-key" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "A cute robot cooking breakfast"}' \
  --output image.jpg

🌐 JavaScript Example

const res = await fetch("https://<your-worker-name>.<your-subdomain>.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" }),
});
const blob = await res.blob();
const img = document.createElement("img");
img.src = URL.createObjectURL(blob);
img.style.height = "500px";
document.body.appendChild(img);

📝 Notes

  • 🆓 Free Tier: Cloudflare Workers AI free tier allows 100,000 AI requests per day. See Cloudflare pricing for details.
  • 🎨 Models: You can change the model in worker.js to use other available models (see comments in the file).
  • 🔒 Security: Keep your API key secret. Rotate it if needed.

📄 License

MIT License ⭐


⭐ Star this repo if it helped you! ⭐

About

Free AI Image Generation API using Cloudflare Workers

Topics

Resources

Stars

253 stars

Watchers

6 watching

Forks

Releases

Packages

Contributors

Languages