🚀 Cloudflare Workers Deployment Guide

📌 Step 1: Log in to Cloudflare Workers

Go to Cloudflare Workers and log in to your account.

📌 Step 2: Create a New Worker

In the Cloudflare Workers dashboard, click on "Create a Service" to create a new worker.

📌 Step 3: Copy and Paste the Code into the Worker

// worker.js - Cloudflare Worker Script By - WOODcraft export default { async fetch(request, env) { const url = new URL(request.url); const models = { "realistic_vision": "SG161222/Realistic_Vision_V5.1_noVAE", "dreamshaper": "Lykon/DreamShaper-v7", "sdxl": "stabilityai/stable-diffusion-xl-base-1.0", "deliberate": "XpucT/Deliberate", "anything_v5": "stabilityai/stable-diffusion-2-1", "protogen": "darkstorm2150/Protogen_x5.8", "flux": "black-forest-labs/FLUX.1-dev" }; if (url.searchParams.get("model") === "list") { return new Response(JSON.stringify(models, null, 2), { headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } let modelKey = url.searchParams.get('model') || "realistic_vision"; let model = models[modelKey] || models["realistic_vision"]; const prompt = url.searchParams.get('input') || 'A futuristic city at sunset'; if (!env.HUGGINGFACE_TOKEN) { return new Response(JSON.stringify({ error: "Missing Hugging Face API token" }), { status: 401, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } const requestBody = { inputs: prompt }; try { const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, { method: "POST", headers: { "Authorization": `Bearer ${env.HUGGINGFACE_TOKEN}`, "Content-Type": "application/json" }, body: JSON.stringify(requestBody) }); if (!response.ok) { const errorResponse = await response.json(); return new Response(JSON.stringify({ error: "Failed to fetch from Hugging Face API", details: errorResponse }), { status: response.status, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } const imageBuffer = await response.arrayBuffer(); return new Response(imageBuffer, { headers: { "Content-Type": "image/png", "Access-Control-Allow-Origin": "*" } }); } catch (error) { return new Response(JSON.stringify({ error: "Internal Server Error", details: error.message }), { status: 500, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } } };

📌 Step 4: Save and Deploy the Worker

Click "Save" and then "Deploy" to make your worker live.

🏞️ Use the model list

You can now use the any model:

{ "realistic_vision": "SG161222/Realistic_Vision_V5.1_noVAE", "dreamshaper": "Lykon/DreamShaper-v7", "sdxl": "stabilityai/stable-diffusion-xl-base-1.0", "deliberate": "XpucT/Deliberate", "anything_v5": "stabilityai/stable-diffusion-2-1", "protogen": "darkstorm2150/Protogen_x5.8", "flux": "black-forest-labs/FLUX.1-dev" }

📌 Step 5: Use the API URL

You can now use the Worker URL to make API calls. Example:

https://your-worker-name.YOUR_SUBDOMAIN.workers.dev/?input=An astronaut on Mars&model=flux

📌 Step 6: Set Up Hugging Face API Token

Follow these steps:

  1. Go to Hugging Face API Tokens
  2. Log in or create an account
  3. Click "New token" and create a token with read access
  4. Copy the token

📌 How to Add the API Token in Cloudflare Workers

Once you have the Hugging Face token, follow these steps:

  1. Open your Cloudflare Worker dashboard
  2. Go to your deployed Worker
  3. Click on Variables (Environment Variables)
  4. Add a new variable: HUGGINGFACE_TOKEN = your_api_token_here
  5. Click "Save and Deploy"

🎉 Your API is Now Ready!

Your AI Image Generator is now live on Cloudflare Workers! 🚀

Powered By 𝐖𝐎𝐎𝐃𝐜𝐫𝐚𝐟𝐭
© 2025 Cloudflare Workers Deployment Guide. All rights reserved.