Skip to content
项目

saurav-z/free-image-generation-api

在 GitHub 查看

关于

Free AI Image Generation API using Cloudflare Workers

设计与媒体

这些数字如何统计

可以做什么

  • 🆓 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

实测星标增长

24小时
0
7天
-1
15天
+4
1个月
+11

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

✨ 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! ⭐

探索相关项目

加载中…