OpenClaw: A Practical Guide to Image Generation with OpenRouter and Local mflux
If you hear a voice within you say you cannot paint, then by all means paint and that voice will be silenced, — Vincent van Gogh.
A man paints with his brains and not with his hands, Michelangelo
Generating images within an autonomous AI agent workflow introduces unique challenges, particularly when dealing with asynchronous cloud APIs and local hardware constraints. OpenClaw’s image_generate tool is designed to be provider-agnostic, allowing you to seamlessly switch between cloud providers like OpenRouter (which offers free access to models like Google’s Gemini) and local, on-device solutions like mflux on Apple Silicon.
However, leveraging these tools effectively requires a solid understanding of how OpenClaw handles background tasks. Unlike synchronous text generation, image creation returns a task ID immediately. The agent must be explicitly instructed to wait for the background process to complete without panicking, apologizing, or hallucinating errors.
In this guide, we will explore how to properly configure and invoke image generation in OpenClaw. We will cover the mechanics of the asynchronous pipeline, how to write robust custom skills (such as a “Daily Gospel” reader) that prevent AI hallucinations, and a powerful technique for combining local mflux generation with cloud-based OpenRouter models to produce dual-image outputs in a single, seamless workflow.
Using Images with OpenClaw and OpenRouter Free Models
The image_generate tool in OpenClaw is provider-agnostic: it routes requests to whichever image backend you have configured.
- “Agnostic” here means “doesn’t care who makes it.”
- Think of /tool image_generate like the “Power” button on a Universal TV Remote. Whether you own a Sony, Samsung, or LG TV (“the image backend/provider”), you still press the exact same button on the remote, and the remote figures out who to send the signal to.
- Today you might set OpenClaw to use OpenRouter (free Google Gemini images), and tomorrow you might switch it to OpenAI (DALL-E). Your command never has to change!
“OpenClaw’s image_generate is asynchronous in chat sessions. The tool records a background task, returns a task ID immediately, and wakes the agent when the provider finishes. This is not an error state; it is the designed behavior.”
-
The Coffee Shop Buzzer Analogy:
When you order a fancy coffee at a busy café (the Cloud), the barista doesn’t make you stare at them in silence for 3 minutes. Instead, within 2 seconds, they hand you a plastic buzzer with a number on it (“a Task ID”). You go sit down and read your book (the AI keeps writing the prayer). Three minutes later, the buzzer goes off (“wakes the agent”) and your coffee is ready!
-
Why do we have to warn the AI that “This is not an error state”?
AI chatbots are used to getting answers instantly. When the AI asks the cloud for a picture, and the cloud replies 0.1 seconds later with “Task #9482 started, no picture yet,” a naive AI often panics! It thinks: “Oh no! Where is the picture?! It must be broken!” and it will apologize to you: “I’m sorry, I tried to make an image, but it didn’t work.” Therefore, when writing instructions for the AI, we have to firmly tell it: “Don’t panic and DO NOT apologize! Just leave a note saying the picture is on its way and keep going!”
Chat Commands
# =====================================================================
# COMMAND 1: Asking OpenClaw to generate an image
# =====================================================================
# - `/tool image_generate`: Wake up OpenClaw's built-in universal image tool.
# - `action=generate`: Tell the tool we want to CREATE a new picture.
# - `prompt="..."`: The description of the picture (inside quotes so spaces don't break it).
# - `aspectRatio=16:9`: Make it widescreen (like a TV or YouTube video).
# - `count=1`: Only make 1 picture.
/tool image_generate action=generate prompt="A cinematic, reverent depiction of Jonah on the shore after being delivered by the great fish" aspectRatio=16:9 count=1
# =====================================================================
# COMMAND 2: Checking which Cloud Provider is connected
# =====================================================================
# By changing `action=generate` to `action=list`, we ask OpenClaw:
# "Hey, which image companies do I have set up right now?"
/tool image_generate action=list
# And here is what OpenClaw prints back to the screen:
# It tells us that 'openrouter' is ready to go (✅), and by default, it will
# use Google's free "Gemini 3.1 Flash Image" AI model to draw our pictures.
Available image generation providers:
openrouter — configured ✅ (default: google/gemini-3.1-flash-image-preview)
Use the Async Pipeline Correctly
OpenClaw’s image_generate is asynchronous in chat sessions. The tool records a background task, returns a task ID immediately, and wakes the agent when the provider finishes. This is not an error state; it is the designed behavior.
At the bottom of the skill, you see a longer command that uses &&. In computer commands, && means: “Do Step 1, wait until it succeeds, AND THEN automatically do Step 2!”
`/tool image_generate action=generate prompt="<cinematic prompt>" aspectRatio=16:9 count=1 && /tool image_generate action=download && /tool image`
Here are the 3 dominoes lined up by &&:
/tool image_generate action=generate ...: Ask the cloud to draw the picture in the background.&& /tool image_generate action=download: Once the cloud finishes drawing it, download the image file from the internet onto your computer.&& /tool image: Once it is downloaded to your computer, actually display/show the picture right inside your chat window!
# =====================================================================
# 1. THE INDEX CARD (Frontmatter)
# =====================================================================
# Between the `---` dashes, we name the skill "daily-gospel" and tell
# OpenClaw when to use it.
---
name: daily-gospel
description: Fetch the daily Gospel reading and present it as a short guided prayer.
---
# =====================================================================
# 2. STEP ONE: FETCHING TODAY'S BIBLE READING WITH PYTHON
# =====================================================================
When the user asks for the daily Gospel or daily reading, run:
`{baseDir}/.venv/bin/python3 {baseDir}/scripts/daily_gospel.py`
# Let's translate that command!
# - `{baseDir}`: A smart shortcut that means "Whatever folder this skill is saved in."
# - `.venv/bin/python3`: In Python, a `.venv` (Virtual Environment) is like a private
# "sandbox" folder that holds all the special add-ons this script needs so they don't
# mess up the rest of your computer. This runs Python inside that private sandbox.
# - `{baseDir}/scripts/daily_gospel.py`: Runs the Python script that goes onto the internet
# and grabs today's official Bible reading.
# =====================================================================
# 3. UNDERSTANDING THE RESULT & PREVENTING "HALLUCINATIONS"
# =====================================================================
The script prints a JSON object with `title`, `date`, `reading`, and `link`.
If it reports an error, exits non-zero, or returns no entry, say briefly that
the reading is unavailable today and stop — do not invent or substitute
scripture.
# Let's translate the jargon here:
# - `JSON object`: A super neat, labeled format that computers use to share data.
# It looks like a digital index card:
# {"title": "Luke 15:1-7", "date": "Today", "reading": "Jesus told them this parable...", "link": "http..."}
# - `exits non-zero`: In the computer world, when a program finishes its job, it whispers
# a secret number to the operating system. `0` always means "Everything worked perfectly!"
# Any number that is NOT zero ("non-zero", like `1` or `2`) means "I crashed!"
# - `do not invent or substitute scripture`: AI models are huge people-pleasers. If the
# internet is down and the script fails, the AI might try to "be helpful" by making up
# a Bible reading from memory! This strict rule tells the AI: "If the script fails,
# just stop and tell the user it's unavailable."
[...]
# =====================================================================
# 4. HOW THE AI SHOULD FORMAT THE PRAYER
# =====================================================================
## Structure
1. **Opening — 🙏 (verbatim)**
Begin with this exact text, not a paraphrase:
> 🙏 Thank You for bringing us together to pray.
> [... It has already explain previously]
# ("Verbatim" means word-for-word. The AI isn't allowed to get creative with the opening line.)
5. **Image — 🖼️**
# By the time the AI reaches Step 5 of the prayer, it has already read today's Bible
# passage (`reading`). Now we instruct the AI to use its own imagination to write an
# art description based on today's Bible story!
Craft a descriptive, cinematic, and reverent prompt based on the core scene, imagery, or theme of the `reading`.
Invoke the image generator by outputting this exact tool command on its own line:
# Next, we tell the AI to trigger our 3-part chained command (Generate -> Download -> Show),
# replacing `"<cinematic prompt>` with the art description it just imagined:
Invoke the image generator by outputting this exact tool command on its own line:
`/tool image_generate action=generate prompt="<cinematic prompt>" aspectRatio=16:9 count=1 && /tool image_generate action=download && /tool image`
# =====================================================================
# 5. THE "DON'T PANIC" RULE FOR THE AI
# =====================================================================
# Here is that famous "Async Placeholder" rule!
# Because OpenRouter takes 10-30 seconds to draw the picture in the background,
# we forbid the AI from apologizing. Instead, we tell it to print a polite waiting
# message (`🖼️ *Visualizing today's reading...*`) and immediately move on to Step 6
# of the prayer while the cloud works in the background!
**CRITICAL ASYNC RULE:** The image tool runs in the background. It will not return the image immediately. DO NOT apologize or say that you cannot generate images. Simply output the tool command, print a brief placeholder like `🖼️ *Visualizing today's reading...*`, and proceed immediately to the next step.
[... Continue]
## Reference format
[... Continue]
# AIs learn best when you show them an example of what the final output should look like.
# This section shows the AI: "Put the command on Line 1, and put the waiting message on Line 2."
## Reference format
[... Continue]
/tool image_generate action=generate prompt="<cinematic prompt>" aspectRatio=16:9 count=1 && /tool image_generate action=download && /tool image
🖼️ *Visualizing today's reading...*
[... Continue]
To generate, download, and display an image in one flow, output the tool command on its own line and then proceed immediately: /tool image_generate action=generate prompt="<cinematic prompt>" aspectRatio=16:9 count=1 && /tool image_generate action=download && /tool image
Alternative Version
Part 1: What Changed in This Version? (Two Big Secrets)
Before we go line-by-line, notice that this version of the instructions does two things differently than the previous one:
- “Calling a Tool” vs. “Typing a /tool Command”.
In the previous message, we told the AI to literally type /tool image_generate... into the chat window like a human would.
In this version, we say: call the image_generate tool with: followed by a bulleted list.
What’s the difference? Modern AI agents (like OpenClaw) have “invisible hands” behind the scenes. Instead of typing ugly commands into your chat window, the AI can press the image_generate button silently in the background by filling out a digital form (action, model, prompt, aspectRatio, count).
- Why do we forbid the AI from writing [IMAGE ATTACHED]? (The “Fake Attachment” Trap)
At the bottom, the instructions say: “Do not write [IMAGE ATTACHED], [image], [image attached], or any similar placeholder.”
Why would an AI do that?! When AI models learn how to talk, they read millions of old emails and chat logs on the internet. In old email logs, whenever someone sent a picture, the computer deleted the picture to save space and replaced it with the text [IMAGE ATTACHED].
Because of that, AIs often get confused and think: “Oh! If I just type the letters [IMAGE ATTACHED] at the bottom of my message, a picture will magically appear for the human!” Of course, typing those words doesn’t actually attach a picture—it just looks silly! So this rule tells the AI: “Don’t fake it by typing [IMAGE ATTACHED] in text. Actually use your tool to attach the real picture file!”
# =====================================================================
# STEP 1: FETCH TODAY'S GOSPEL READING
# =====================================================================
When the user asks for the daily Gospel or daily reading, run:
`{baseDir}/.venv/bin/python3 {baseDir}/scripts/daily_gospel.py`
# - `{baseDir}`: The main folder where this skill lives on your Mac.
# - `.venv/bin/python3`: Runs the private "sandbox" version of Python that has
# all the internet-fetching tools installed.
# - `scripts/daily_gospel.py`: The Python program that downloads today's reading.
# =====================================================================
# STEP 2: READ THE DATA & STOP IF THE INTERNET IS DOWN
# =====================================================================
The script prints a JSON object with `title`, `date`, `reading`, and `link`.
# The Python script spits out a neat digital package (JSON) containing 4 labeled
# pieces of info: the Bible verse title, today's date, the scripture text (`reading`),
# and a website link.
If it reports an error, exits non-zero, or returns no entry, say briefly that
the reading is unavailable today and stop — do not invent or substitute
scripture.
# - "exits non-zero": Computer code for "the script crashed." (0 = Success, anything else = Error).
# - "do not invent...": Forbids the AI from making up a fake Bible verse or picking a
# random one from memory if the website is down.
# =====================================================================
# STEP 3: TRIGGER THE CLOUD IMAGE GENERATOR (Behind the Scenes)
# =====================================================================
Once you have the `reading`, **call the `image_generate` tool** with:
# Now that the AI has read today's Bible story (`reading`), we tell it to fill out
# the form for the built-in `image_generate` tool with these 5 exact settings:
- `action`: `"generate"`
# Setting 1: Tell the tool we want to CREATE a brand-new image.
- `model`: "openrouter/google/gemini-3.1-flash-image-preview" or the configured OpenRouter image model.
# Setting 2: Tell OpenClaw WHICH cloud artist to hire!
# Notice the path: Go to "openrouter" -> go to "google" -> use "gemini-3.1-flash-image-preview".
# (And if the user configured a different default model, allow that one too).
- `prompt`: a descriptive, cinematic, reverent prompt based on the core scene, imagery, or theme of the `reading`
# Setting 3: The AI must read the Bible passage and write a movie-like ("cinematic"),
# respectful ("reverent") art description of the scene.
- `aspectRatio`: `"16:9"`
# Setting 4: Make the picture widescreen (wider than it is tall).
- `count`: `1`
# Setting 5: Only generate 1 image from the cloud.
# =====================================================================
# STEP 4: ATTACH THE REAL IMAGE (No Fake Text Placeholders!)
# =====================================================================
Do not write `[IMAGE ATTACHED]`, `[image]`, `[image attached]`, or any similar
placeholder. The image should be attached to the email or chat message.
# As we learned above, this stops the AI from lazily typing the words "[IMAGE ATTACHED]"
# and forces it to attach the actual image file that came back from the tool.
How to Combine /mflux (Local) + OpenRouter (Cloud) for TWO Images!
This is actually a fantastic idea! Having both gives you:
- A Local Image (mflux on your Mac): Guaranteed to work even if OpenRouter hits a daily limit, completely private, and saved right into your
~/Downloadsfolder. - A Cloud Image (OpenRouter): Drawn by Google’s huge Gemini model in the cloud, giving you a second artistic style to compare!
How does the AI run both in one skill? Remember that /mflux is just a shortcut that tells the AI to run: python ~/macOS/skills/mflux/generate_image.py "PROMPT" "~/Downloads/output.png"
Inside a skill file (SKILL.md), one skill doesn’t usually type /mflux to call another skill. Instead, you put both instructions right inside your daily-gospel skill!
That way, the AI:
- Creates one reasonable good cinematic prompt based on the Gospel reading.
- Image #1 (Local): Runs your mflux Python script on your Mac to create ~/Downloads/daily_gospel_local.png.
- Image #2 (Cloud): Calls the image_generate tool to create the second image in the cloud via OpenRouter.
- Attaches/displays both images in your chat or email!
Here is how you can rewrite that section of your daily-gospel SKILL.md file so it generates both the local mflux image and the cloud OpenRouter image, heavily commented so you understand how it works:
# =====================================================================
# STEP 1: FETCH TODAY'S GOSPEL READING
# =====================================================================
When the user asks for the daily Gospel or daily reading, run:
`{baseDir}/.venv/bin/python3 {baseDir}/scripts/daily_gospel.py`
# - `{baseDir}`: The main folder where this skill lives on your Mac.
# - `.venv/bin/python3`: Runs the private "sandbox" version of Python that has
# all the internet-fetching tools installed.
# - `scripts/daily_gospel.py`: The Python program that downloads today's reading.
# =====================================================================
# STEP 2: READ THE DATA & STOP IF THE INTERNET IS DOWN
# =====================================================================
The script prints a JSON object with `title`, `date`, `reading`, and `link`.
If it reports an error, exits non-zero, or returns no entry, say briefly that
the reading is unavailable today and stop — do not invent or substitute
scripture.
# - "exits non-zero": Computer code for "the script crashed." (0 = Success, anything else = Error).
# - "do not invent...": Forbids the AI from making up a fake Bible verse or picking a
# random one from memory if the website is down.
## Generating Two Images (Local + Cloud)
Once you have the `reading`, craft a single descriptive, cinematic, and reverent prompt based on the core scene, imagery, or theme of the `reading`. You will use this prompt to generate **two** images — one locally via `mflux`, and one in the cloud via `OpenRouter`:
### 1. Local Image (via mflux on Apple Silicon)
Run the local `mflux` generator command using your crafted prompt:
`python ~/macOS/skills/mflux/generate_image.py "" "~/Downloads/gospel_local.png"`
Wait for this command to finish creating `~/Downloads/gospel_local.png`.
### 2. Cloud Image (via OpenRouter)
Next, **call the `image_generate` tool** with:
- `action`: `"generate"`
- `model`: `"openrouter/google/gemini-3.1-flash-image-preview"` or the configured OpenRouter image model.
- `prompt`: the same descriptive, cinematic, reverent prompt (or a slight variation of it)
- `aspectRatio`: `"16:9"`
- `count`: `1`
### 3. Attaching Both Images
Attach/display both the local image (`~/Downloads/gospel_local.png`) and the cloud-generated image in the final chat message or email.
Do not write `[IMAGE ATTACHED]`, `[image]`, `[image attached]`, or any similar text placeholder.
Why this order (Local first, Cloud second) works best:
- Step 1 (mflux Local) is Synchronous: The AI starts your Mac’s mflux script first, pauses for ~30–60 seconds while your Mac draws the picture, and saves it neatly as ~/Downloads/gospel_local.png.
- Step 2 (image_generate Cloud) is Asynchronous: Right after the local image finishes, the AI triggers the OpenRouter cloud tool and finishes writing your prayer.
- Result: You never have two heavy tasks fighting each other at the exact same second, and you end up with two beautiful interpretations of the day’s Gospel—one made by your Mac, and one made by the Cloud!