HF SDXL Image
Generate a single image from a text prompt with the Hugging Face router endpoint. The skill defaults to stabilityai/stable-diffusion-xl-base-1.0 and can be switched to another compatible Hugging Face Inference API model by setting HFIMAGEMODEL.
Chat-oriented workflow
When you ask to generate an image:
- 1. Convert your request into a prompt.
- Run
scripts/generate_hf_sdxl.py with the --output /tmp/openclaw/ argument. - The script saves the image to a temporary path and prints the file path to stdout.
- Send the image back through the current conversation provider's required image/file-send format.
- After successful delivery, delete the temporary file unless the user explicitly asked to keep it.
Provider-specific delivery rule
This skill only generates and saves an image file. It does not define a universal send format.
When returning the 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 simply reading a local file path, pasting a path, or relying on one provider's auto-routing behavior will work on another provider.
Required behavior:
- - Detect the current session provider/channel before sending.
- Use that provider's correct media-send path and syntax.
- If the provider requires a provider-specific wrapper or message format for images, use it.
- If the provider does not reliably auto-send images from a local file read, do not rely on that fallback.
- Treat image delivery as provider-specific, not skill-generic.
Examples of what to avoid:
- - Do not assume
read on an image path will always send the image correctly. - Do not assume Telegram-style or QQ-style delivery rules apply to other providers.
- Do not claim success until the image has actually been sent through the current provider's proper format.
Strong trigger examples
Use this skill for requests like:
- - "生成一张图片:夕阳下的海边小镇"
- "画一张赛博朋克风格的城市夜景"
- "帮我做一张封面图,主题是 AI 和机器人"
- "用 Hugging Face 生成一张可爱的熊在图书馆读书"
- "用 SDXL 出一张未来感海报"
- "create an illustration of a scholar bear reading in a grand library"
Command
Default delivery workflow:
python3 scripts/generatehfsdxl.py "a cozy cyberpunk alley at night, cinematic lighting" --wait-for-model --output /tmp/openclaw/
With a model override:
HFIMAGEMODEL=stabilityai/stable-diffusion-3-medium-diffusers python3 scripts/generatehfsdxl.py "a cozy cyberpunk alley at night, cinematic lighting" --wait-for-model --output /tmp/openclaw/
Use a temporary directory for normal chat delivery. Only point --output at a persistent user-chosen location when the user explicitly asks to save or export the image.
Behavior
- - Sends POST https://router.huggingface.co/hf-inference/models/
- Reads the bearer token from HUGGINGFACETOKEN
- Reads the model id from HFIMAGE_MODEL when set; otherwise uses stabilityai/stable-diffusion-xl-base-1.0
- Sends JSON with inputs set to the prompt
- Requests image output with a single supported Accept header value
- Requires
--output and saves the generated image to that path or directory - Prints the saved file path to stdout so OpenClaw can send the file to the current conversation
- Only generates and stores the image locally; provider-specific outbound delivery must be handled by the caller according to the active chat provider
- Uses a temporary local file as the standard transport step for reliable delivery
- Expects OpenClaw to delete temporary files after a successful send
- Fails loudly when the API returns JSON or an HTTP error
Parameters
- - Positional prompt: image prompt text
- --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
- --timeout: HTTP timeout in seconds; defaults to 180
- --wait-for-model: set options.waitformodel=true so cold starts wait instead of failing fast
Troubleshooting
Missing token
If the script says Missing HUGGINGFACE_TOKEN environment variable., export the token before running it.
export HUGGINGFACETOKEN=hfxxx
Optional model override
To switch to another compatible Hugging Face Inference API model, set HFIMAGEMODEL.
export HFIMAGEMODEL=stabilityai/stable-diffusion-3-medium-diffusers
If HFIMAGEMODEL is unset, the script uses stabilityai/stable-diffusion-xl-base-1.0.
401 or 403
The token is missing, invalid, expired, or does not have permission for the endpoint.
503 or model loading errors
Retry with --wait-for-model.
JSON instead of an image
Read the full JSON error body and surface it to the user. Do not pretend generation succeeded.
Storage policy
The default policy is temporary-file delivery.
- - Generate into a temporary local path for normal chat delivery
- Return the saved file path so OpenClaw can send the file to the current conversation
- Delete the temporary file immediately after successful delivery
- Keep a persistent local copy only when the user explicitly asks for that behavior
Resource
scripts/generatehfsdxl.py
Use this script for deterministic generation and repeatable testing.
HF SDXL 图像生成
通过 Hugging Face 路由端点,根据文本提示生成单张图像。该技能默认使用 stabilityai/stable-diffusion-xl-base-1.0 模型,可通过设置 HFIMAGEMODEL 切换到其他兼容的 Hugging Face 推理 API 模型。
面向聊天的工作流程
当您要求生成图像时:
- 1. 将您的请求转换为提示词。
- 使用 --output /tmp/openclaw/ 参数运行 scripts/generatehfsdxl.py。
- 脚本将图像保存到临时路径,并将文件路径打印到标准输出。
- 通过当前对话提供商所需的图像/文件发送格式发送图像。
- 成功发送后,删除临时文件,除非用户明确要求保留。
特定于提供商的发送规则
此技能仅生成并保存图像文件。它不定义通用的发送格式。
在聊天中返回图像时,始终遵循当前会话提供商所需的出站媒体格式。不同的提供商可能需要不同的发送方法、包装器或工具。不要假设简单地读取本地文件路径、粘贴路径或依赖某个提供商的自动路由行为就能在另一个提供商上生效。
必需行为:
- - 在发送前检测当前会话提供商/渠道。
- 使用该提供商的正确媒体发送路径和语法。
- 如果提供商要求使用特定于提供商的包装器或消息格式来发送图像,请使用它。
- 如果提供商不能可靠地自动发送从本地文件读取的图像,不要依赖这种回退方式。
- 将图像发送视为特定于提供商的行为,而非技能通用行为。
需要避免的示例:
- - 不要假设对图像路径执行 read 操作总能正确发送图像。
- 不要假设 Telegram 风格或 QQ 风格的发送规则适用于其他提供商。
- 在图像实际通过当前提供商的正确格式发送之前,不要声称成功。
强触发示例
对此类请求使用此技能:
- - 生成一张图片:夕阳下的海边小镇
- 画一张赛博朋克风格的城市夜景
- 帮我做一张封面图,主题是 AI 和机器人
- 用 Hugging Face 生成一张可爱的熊在图书馆读书
- 用 SDXL 出一张未来感海报
- create an illustration of a scholar bear reading in a grand library
命令
默认发送工作流程:
python3 scripts/generatehfsdxl.py a cozy cyberpunk alley at night, cinematic lighting --wait-for-model --output /tmp/openclaw/
使用模型覆盖:
HFIMAGEMODEL=stabilityai/stable-diffusion-3-medium-diffusers python3 scripts/generatehfsdxl.py a cozy cyberpunk alley at night, cinematic lighting --wait-for-model --output /tmp/openclaw/
对于普通的聊天发送,使用临时目录。只有当用户明确要求保存或导出图像时,才将 --output 指向用户选择的持久化位置。
行为
- - 发送 POST 请求到 https://router.huggingface.co/hf-inference/models/<模型ID>
- 从 HUGGINGFACETOKEN 读取 bearer 令牌
- 当设置了 HFIMAGE_MODEL 时读取模型 ID;否则使用 stabilityai/stable-diffusion-xl-base-1.0
- 发送 JSON,其中 inputs 设置为提示词
- 使用单个支持的 Accept 头值请求图像输出
- 需要 --output 参数,并将生成的图像保存到该路径或目录
- 将保存的文件路径打印到标准输出,以便 OpenClaw 将文件发送到当前对话
- 仅在本地生成和存储图像;特定于提供商的出站发送必须由调用者根据活跃的聊天提供商处理
- 使用临时本地文件作为标准传输步骤,以确保可靠发送
- 期望 OpenClaw 在成功发送后删除临时文件
- 当 API 返回 JSON 或 HTTP 错误时,会大声报错
参数
- - 位置参数 prompt:图像提示文本
- --output:必需的输出文件路径或目录;对于普通聊天发送使用临时目录,仅当用户明确请求保存文件时才使用持久化位置
- --timeout:HTTP 超时时间(秒);默认为 180
- --wait-for-model:设置 options.waitformodel=true,使冷启动等待而不是快速失败
故障排除
缺少令牌
如果脚本显示 Missing HUGGINGFACE_TOKEN environment variable.,请在运行前导出令牌。
export HUGGINGFACETOKEN=hfxxx
可选的模型覆盖
要切换到其他兼容的 Hugging Face 推理 API 模型,请设置 HFIMAGEMODEL。
export HFIMAGEMODEL=stabilityai/stable-diffusion-3-medium-diffusers
如果未设置 HFIMAGEMODEL,脚本将使用 stabilityai/stable-diffusion-xl-base-1.0。
401 或 403 错误
令牌缺失、无效、已过期或没有该端点的权限。
503 或模型加载错误
使用 --wait-for-model 重试。
返回 JSON 而非图像
读取完整的 JSON 错误体并将其呈现给用户。不要假装生成成功。
存储策略
默认策略是临时文件发送。
- - 对于普通聊天发送,生成到临时本地路径
- 返回保存的文件路径,以便 OpenClaw 将文件发送到当前对话
- 成功发送后立即删除临时文件
- 仅当用户明确要求时才保留持久化的本地副本
资源
scripts/generatehfsdxl.py
使用此脚本进行确定性生成和可重复测试。