{"skill":{"slug":"cloudflare-workers-ai-images","displayName":"Cloudflare Workers Ai Images","summary":"Generate and edit images through Cloudflare Workers AI using one skill that supports text-to-image and image-to-image. Use when the user asks to generate, dr...","description":"---\nname: cloudflare-workers-ai-image\ndescription: Generate and edit images through Cloudflare Workers AI using one skill that supports text-to-image and image-to-image. Use when the user asks to generate, draw, create, render, transform, restyle, or modify images with Cloudflare Workers AI models such as stable-diffusion-xl-base-1.0 and stable-diffusion-v1-5-img2img. Trigger for requests about prompt-based image generation, editing an existing image, preserving a source image while changing overall style or composition, or when the user explicitly mentions Cloudflare Workers AI, Workers AI, SDXL, or img2img. Save generated images to a temporary local path, let OpenClaw send them to the current conversation window, and remove the temporary files after successful delivery unless the user explicitly asks to keep a saved copy.\n---\n\n# Cloudflare Workers AI Image\n\nUse this skill for two related image workflows backed by Cloudflare Workers AI:\n\n- **text2img** → create a new image from a prompt\n- **img2img** → transform an existing source image with a prompt\n\nUse the bundled script:\n\n```bash\npython3 scripts/cf_workers_ai_image.py <mode> \"<prompt>\" [options]\n```\n\nThe script reads credentials from environment variables so the skill works cleanly in Docker-based OpenClaw deployments.\n\n## Trigger guidance\n\nUse this skill when the user wants any of the following through Cloudflare Workers AI:\n\n- generate a brand-new image from text\n- make a picture, illustration, concept art, poster, wallpaper, avatar, or cover image\n- transform an existing image into another style or composition\n- keep the original image as a base but restyle or modify it globally\n- perform text2img or img2img with Stable Diffusion-family models on Cloudflare\n\nStrong trigger phrases include:\n\n- \"用 Cloudflare Workers AI 生成图片\"\n- \"用 Workers AI 做文生图\"\n- \"用 SDXL 生成一张图\"\n- \"把这张图改成水彩风\"\n- \"基于这张图重绘\"\n- \"用 img2img 改图\"\n- \"用 Workers AI 改这张图片风格\"\n\nMode selection guidance:\n\n- Choose **text2img** when there is no source image and the user wants a new image from a prompt.\n- Choose **img2img** when there is a source image and the user wants a global transformation, style transfer, or composition-preserving edit.\n\nIf the user asks for a local area edit, object replacement, or mask-based redraw, this skill does not cover that workflow anymore.\n\n## Required environment variables\n\nRead `references/docker-compose-env-example.md` when the user asks how to pass credentials through Docker Compose.\n\nRequired variables:\n\n- `CF_ACCOUNT_ID`\n- `CF_API_TOKEN`\n\nIf either variable is missing, the script exits with a clear error.\n\n## Default models\n\nThe script defaults to these Workers AI model identifiers:\n\n- `text2img` → `@cf/stabilityai/stable-diffusion-xl-base-1.0`\n- `img2img` → `@cf/runwayml/stable-diffusion-v1-5-img2img`\n\nOverride any default with `--model` if Cloudflare changes naming or the user wants another compatible Workers AI model.\n\n## Commands\n\n### 1) Text to image\n\n```bash\npython3 scripts/cf_workers_ai_image.py text2img \"a cozy cabin in snowy mountains, cinematic lighting\" --output /tmp/openclaw/\n```\n\nOptional knobs:\n\n```bash\npython3 scripts/cf_workers_ai_image.py text2img \"a cozy cabin in snowy mountains, cinematic lighting\" \\\n  --negative-prompt \"blurry, low quality, distorted\" \\\n  --num-steps 30 \\\n  --guidance 7.5 \\\n  --width 1024 \\\n  --height 1024 \\\n  --seed 42 \\\n  --output /tmp/openclaw/\n```\n\n### 2) Image to image\n\n```bash\npython3 scripts/cf_workers_ai_image.py img2img \"turn this into a watercolor illustration\" \\\n  --image ./input/source.png \\\n  --strength 0.65 \\\n  --output /tmp/openclaw/\n```\n\nThe bundled script sends the source image as a base64 field (`image_b64`) for Workers AI compatibility.\n\n## Chat workflow\n\nWhen you ask to generate or process an image:\n\n1. Determine the mode (text2img or img2img) and convert your request into a prompt.\n2. Run `scripts/cf_workers_ai_image.py` with the `--output /tmp/openclaw/` argument.\n3. The script saves the image to the specified temporary directory and prints the full path to stdout.\n4. Send the image back through the **current conversation provider's required image/file-send format**.\n5. After successful delivery, delete the temporary image file unless the user explicitly asked to keep it.\n\n## Provider-specific delivery rule\n\nThis skill only generates and saves image files. **It does not define a universal send format.**\n\nWhen returning a generated or edited image in chat, always follow the **current session provider's required outbound media format**. Different providers may require different delivery methods, wrappers, or tools. Do **not** assume that reading a local image path, echoing a file path, or relying on one provider's auto-routing behavior will work across all providers.\n\nRequired behavior:\n\n- Detect the current session provider/channel before sending.\n- Use that provider's correct media-send path and syntax.\n- If the provider requires a provider-specific wrapper or message format for outbound images, use it.\n- If the provider does not reliably auto-send images from a local file read, do not rely on that fallback.\n- Treat image delivery as provider-specific, not skill-generic.\n\n## Auto-send workflow for the current chat\n\nWhen the runtime supports sending generated images back to the active conversation, prefer this flow:\n\n1. Generate the image with `scripts/cf_workers_ai_image.py --output /tmp/openclaw/`.\n2. Capture the file path printed to stdout.\n3. Send the generated image to the current chat using the **active provider's correct outbound media format**, not a generic path-only assumption.\n4. Include a short caption describing whether the result came from text2img or img2img.\n5. Delete the temporary file immediately after send succeeds.\n6. Only keep the file in a persistent location when the user explicitly asked to save it.\n\nRecommended captions:\n\n- text2img → `按你的提示生成好了。`\n- img2img → `按你的源图和提示改好了。`\n\nIf the request is iterative, mention what changed in the new version, such as style, prompt emphasis, or source-image guidance.\n\n## Parameters\n\n- `mode`: `text2img` | `img2img`\n- positional `prompt`: prompt text\n- `--image`: required for `img2img`\n- `--output`: required output file path or directory; use a temporary directory for normal chat delivery, or a persistent location only when the user explicitly requests a saved file\n- `--model`: optional model override\n- `--negative-prompt`: optional negative prompt\n- `--num-steps`: optional sampling steps\n- `--guidance`: optional guidance scale\n- `--strength`: optional transformation strength\n- `--width`, `--height`: optional text2img dimensions when supported by the model\n- `--seed`: optional seed\n- `--timeout`: HTTP timeout in seconds\n\nThe script's responsibility stops at generating the file and printing its saved path. The caller must handle outbound delivery using the active chat provider's required image-send format.\n\n## Smoke testing\n\nRun the bundled smoke test script after changing the API script or credentials:\n\n```bash\npython3 scripts/smoke_test.py\n```\n\nWhat it does:\n\n- checks `CF_ACCOUNT_ID` and `CF_API_TOKEN`\n- creates a local PNG input for img2img\n- runs one `text2img` request\n- runs one `img2img` request\n- verifies that each command writes an image file and prints a usable output path\n- prints a JSON summary and exits non-zero if any mode fails\n\nUse smoke tests to validate connectivity and gross regressions, not image quality.\n\n## Troubleshooting\n\n### Missing credentials\n\nIf the script says a required environment variable is missing, pass `CF_ACCOUNT_ID` and `CF_API_TOKEN` through Docker Compose. See `references/docker-compose-env-example.md`.\n\n### JSON instead of image\n\nWorkers AI may return JSON for errors or validation failures. Surface the full JSON body.\n\n### Storage policy\n\nThe default policy is temporary-file delivery.\n\n- Generate into a temporary local path for normal chat delivery\n- Return the saved file path so OpenClaw can send the file to the current conversation\n- Delete the temporary file immediately after successful delivery\n- Keep a persistent local copy only when the user explicitly asks for that behavior\n\n### 401 / 403\n\nThe token is missing, invalid, expired, or does not have the right Cloudflare account permission.\n\n### 404 / model not found\n\nCloudflare may have changed model identifiers. Retry with `--model` using the current Workers AI model name.\n\n### Input image issues\n\nUse PNG for source images when possible.\n\n## Resource\n\n### scripts/cf_workers_ai_image.py\n\nUse this script for deterministic, repeatable Cloudflare Workers AI image generation and editing.\n\n### scripts/smoke_test.py\n\nUse this script for a fast end-to-end connectivity and output smoke test across the supported modes.\n","tags":{"latest":"1.1.1"},"stats":{"comments":0,"downloads":654,"installsAllTime":1,"installsCurrent":1,"stars":0,"versions":5},"createdAt":1774702042688,"updatedAt":1778492261160},"latestVersion":{"version":"1.1.1","createdAt":1775394356970,"changelog":"Clarify provider-specific outbound image delivery requirements and fix a missing base64 import in the Workers AI image script.","license":"MIT-0"},"metadata":null,"owner":{"handle":"slippersheepig","userId":"s173ga2b39rqhtd9xy993f9zzd83kt2m","displayName":"sheepgreen","image":"https://avatars.githubusercontent.com/u/58287293?v=4"},"moderation":null}