Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 

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

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! 🎨

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages