Cloudflare Workers Ai Images
by @slippersheepig
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...
clawhub install cloudflare-workers-ai-imagesπ About This Skill
name: cloudflare-workers-ai-image description: 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.
Cloudflare Workers AI Image
Use this skill for two related image workflows backed by Cloudflare Workers AI:
Use the bundled script:
python3 scripts/cf_workers_ai_image.py "" [options]
The script reads credentials from environment variables so the skill works cleanly in Docker-based OpenClaw deployments.
Trigger guidance
Use this skill when the user wants any of the following through Cloudflare Workers AI:
Strong trigger phrases include:
Mode selection guidance:
If the user asks for a local area edit, object replacement, or mask-based redraw, this skill does not cover that workflow anymore.
Required environment variables
Read references/docker-compose-env-example.md when the user asks how to pass credentials through Docker Compose.
Required variables:
CF_ACCOUNT_IDCF_API_TOKENIf either variable is missing, the script exits with a clear error.
Default models
The script defaults to these Workers AI model identifiers:
text2img β @cf/stabilityai/stable-diffusion-xl-base-1.0img2img β @cf/runwayml/stable-diffusion-v1-5-img2imgOverride any default with --model if Cloudflare changes naming or the user wants another compatible Workers AI model.
Commands
1) Text to image
python3 scripts/cf_workers_ai_image.py text2img "a cozy cabin in snowy mountains, cinematic lighting" --output /tmp/openclaw/
Optional knobs:
python3 scripts/cf_workers_ai_image.py text2img "a cozy cabin in snowy mountains, cinematic lighting" \
--negative-prompt "blurry, low quality, distorted" \
--num-steps 30 \
--guidance 7.5 \
--width 1024 \
--height 1024 \
--seed 42 \
--output /tmp/openclaw/
2) Image to image
python3 scripts/cf_workers_ai_image.py img2img "turn this into a watercolor illustration" \
--image ./input/source.png \
--strength 0.65 \
--output /tmp/openclaw/
The bundled script sends the source image as a base64 field (image_b64) for Workers AI compatibility.
Chat workflow
When you ask to generate or process an image:
1. Determine the mode (text2img or img2img) and convert your request into a prompt.
2. Run scripts/cf_workers_ai_image.py with the --output /tmp/openclaw/ argument.
3. The script saves the image to the specified temporary directory and prints the full path to stdout.
4. Send the image back through the current conversation provider's required image/file-send format.
5. After successful delivery, delete the temporary image file unless the user explicitly asked to keep it.
Provider-specific delivery rule
This skill only generates and saves image files. It does not define a universal send format.
When 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.
Required behavior:
Auto-send workflow for the current chat
When the runtime supports sending generated images back to the active conversation, prefer this flow:
1. Generate the image with scripts/cf_workers_ai_image.py --output /tmp/openclaw/.
2. Capture the file path printed to stdout.
3. Send the generated image to the current chat using the active provider's correct outbound media format, not a generic path-only assumption.
4. Include a short caption describing whether the result came from text2img or img2img.
5. Delete the temporary file immediately after send succeeds.
6. Only keep the file in a persistent location when the user explicitly asked to save it.
Recommended captions:
ζδ½ ηζη€Ίηζε₯½δΊγζδ½ ηζΊεΎεζη€ΊζΉε₯½δΊγIf the request is iterative, mention what changed in the new version, such as style, prompt emphasis, or source-image guidance.
Parameters
mode: text2img | img2imgprompt: prompt text--image: required for img2img--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--model: optional model override--negative-prompt: optional negative prompt--num-steps: optional sampling steps--guidance: optional guidance scale--strength: optional transformation strength--width, --height: optional text2img dimensions when supported by the model--seed: optional seed--timeout: HTTP timeout in secondsThe 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.
Smoke testing
Run the bundled smoke test script after changing the API script or credentials:
python3 scripts/smoke_test.py
What it does:
CF_ACCOUNT_ID and CF_API_TOKENtext2img requestimg2img requestUse smoke tests to validate connectivity and gross regressions, not image quality.
Troubleshooting
Missing credentials
If 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.
JSON instead of image
Workers AI may return JSON for errors or validation failures. Surface the full JSON body.
Storage policy
The default policy is temporary-file delivery.
401 / 403
The token is missing, invalid, expired, or does not have the right Cloudflare account permission.
404 / model not found
Cloudflare may have changed model identifiers. Retry with --model using the current Workers AI model name.
Input image issues
Use PNG for source images when possible.
Resource
scripts/cf_workers_ai_image.py
Use this script for deterministic, repeatable Cloudflare Workers AI image generation and editing.
scripts/smoke_test.py
Use this script for a fast end-to-end connectivity and output smoke test across the supported modes.
π Tips & Best Practices
Missing credentials
If 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.
JSON instead of image
Workers AI may return JSON for errors or validation failures. Surface the full JSON body.
Storage policy
The default policy is temporary-file delivery.
401 / 403
The token is missing, invalid, expired, or does not have the right Cloudflare account permission.
404 / model not found
Cloudflare may have changed model identifiers. Retry with --model using the current Workers AI model name.
Input image issues
Use PNG for source images when possible.