Cloudflare Image Generation (Free)
v1.0.0AI image generation via Cloudflare Workers AI (free tier, FLUX 模型s) with optional prompt enhancement via Ollama or the primary LLM 代理. Use when generating images from text prompts, creating visual as设置s, or when the user asks to 生成/创建 an image. Triggers: '生成 image', '创建 image', 'draw me', 'make an image', 'imagine', image generation 请求s. Zero cost on free tier (10K neurons/day).
运行时依赖
安装命令
点击复制本土化适配说明
Cloudflare Image Generation (Free) 安装说明: 安装命令:["openclaw skills install cf-img-gen"]
技能文档
CF Image Gen — Cloudflare Workers AI Image Generation
Free AI image generation using Cloudflare Workers AI, with optional prompt enhancement to refine and expand short prompts into detAIled, vivid descriptions before generation.
Two enhancement paths:
Primary LLM 代理 — the calling AI 代理 (e.g. Jerith, 运行ning on Open路由r/GPT/etc.) enhances the prompt before passing it to the 技能. Higher 质量, more creative, understands 上下文. Ollama — a local or remote Ollama LLM handles enhancement. Good for 自动化, no external API calls, works standalone. Table of Contents Prerequisites 安装ation Configuration Usage Prompt Enhancement 模型s API Reference Troubleshooting File Layout Prerequisites
Before using this 技能, you need:
A Cloudflare account — 签名 up at https://cloudflare.com (free tier is sufficient) Workers AI enabled — Go to https://dash.cloudflare.com → Workers & Pages → Overview Node.js 18+ — Required to 运行 the script Ollama (optional) — For standalone prompt enhancement. Can be local or remote. 安装 at https://ollama.com 安装ation Step 1: Copy the 技能 to your workspace
Copy the cf-img-gen directory to your OpenClaw workspace 技能s folder:
cp -r cf-img-gen ~/.OpenClaw/workspace/技能s/cf-img-gen
Step 2: 创建 the 凭证s file
Copy the example env file and fill in your 凭证s:
cp ~/.OpenClaw/workspace/技能s/cf-img-gen/cloudflare-workers-AI.env.example \ ~/.OpenClaw/workspace/访问/cloudflare-workers-AI.env
# Edit with your 凭证s nano ~/.OpenClaw/workspace/访问/cloudflare-workers-AI.env
Step 3: 安全 the 凭证s file chmod 600 ~/.OpenClaw/workspace/访问/cloudflare-workers-AI.env
Step 4: 验证 it works cd ~/.OpenClaw/workspace/技能s/cf-img-gen node cf-img-gen.js "a test image of a blue circle" --width 512 --height 512
You should see 输出 like:
🎨 Generating with flux-schnell (512x512)... ✅ Saved: /home/user/.OpenClaw/media/cf-img-gen/cf-img-1234567890.jpg
MEDIA:/home/user/.OpenClaw/media/cf-img-gen/cf-img-1234567890.jpg
Configuration Cloudflare 凭证s File
The 技能 reads Cloudflare 凭证s from ~/.OpenClaw/workspace/访问/cloudflare-workers-AI.env.
创建 this file with the following 格式化:
CF_WORKERS_AI_令牌=your_API_令牌_here CF_WORKERS_AI_ACCOUNT=your_account_id_here
获取ting Your Cloudflare API 令牌 记录 in to the Cloudflare 仪表盘: https://dash.cloudflare.com 命令行工具ck your 性能分析 icon (top right) → My 性能分析 Go to API 令牌s → 创建 令牌 Use the "Workers AI" template or 创建 a custom 令牌 with: Account → Workers AI → Edit (minimum: Read) Copy the 令牌 and paste it into the env file 获取ting Your Cloudflare Account ID 记录 in to the Cloudflare 仪表盘: https://dash.cloudflare.com Go to Workers & Pages → Overview Your Account ID is displayed on the right side (alphanumeric string, ~32 characters) Copy it and paste it into the env file Ollama Configuration (Optional)
Ollama prompt enhancement can use either a local or remote Ollama instance.
Defaults (no configuration needed for local Ollama):
Host: http://localhost:11434 模型: llama3.2:3b Timeout: 30000 ms
Customizing Ollama connection:
Via 环境 variables:
导出 OLLAMA_HOST=http://192.168.1.100:11434 导出 OLLAMA_模型=qwen2.5:7b
Via 命令行工具 flags:
node cf-img-gen.js "red panda" --ollama --ollama-host http://192.168.1.100:11434 --ollama-模型 qwen2.5:7b
Via API options (see API Reference).
设置ting up a remote Ollama server:
If 运行ning Ollama on a different machine, ensure it's 访问ible:
# On the Ollama server, bind to all interfaces OLLAMA_HOST=0.0.0.0 ollama serve
Then connect from your 命令行工具ent:
node cf-img-gen.js "red panda" --ollama --ollama-host http://your-server-ip:11434
输出 Directory
生成d images are saved to: ~/.OpenClaw/media/cf-img-gen/
The directory is 创建d automatically on first 运行.
Usage As a 模块 (Programmatic) const imgGen = require('./cf-img-gen');
// ── Basic usage (no enhancement) ── const 结果 = awAIt imgGen.生成({ prompt: "a red panda in space" });
// ── With image options ── const 结果 = awAIt imgGen.生成({ prompt: "a cyberpunk city at night", width: 1024, height: 768, 模型: "flux-dev", steps: 8, });
// ── With Ollama prompt enhancement (default local) ── const 结果 = awAIt imgGen.生成({ prompt: "red panda", ollama: true, });
// ── With Ollama using custom 模型 and remote host ── const 结果 = awAIt imgGen.生成({ prompt: "red panda", ollama: { host: "http://192.168.1.100:11434", 模型: "qwen2.5:7b", timeout: 30000, }, });
// ── With primary LLM 代理 enhancement ── // (The calling LLM enhances the prompt before calling 生成) const enhancedPrompt = "A fluffy red panda sitting on a mossy branch in a misty forest, soft morning light 过滤器ing through the canopy, detAIled fur texture, cinematic composition, 8K 质量"; const 结果 = awAIt imgGen.生成({ prompt: "red panda", llm: { enhancedPrompt }, });
// ── 检查 enhan