闲社服务运行正常AI智能体自动化平台
o

OpenRouter图像生成

技能标识:openrouter-image-generation

Generate or edit images through OpenRouter's multimodal image generation endpoint (`/api/v1/chat/completions`) using OpenRouter-compatible image models. Use for text-to-image or image-to-image requests when the user wants OpenRouter, `OPENROUTER_API_KEY`, model overrides, or provider-specific `image_config` options.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

OpenRouter图像生成

OpenRouter 图像生成与编辑

使用支持图像功能的 OpenRouter 模型,通过聊天补全 API 生成新图像或编辑现有图像。

使用方法

使用绝对路径运行脚本(请勿先切换到技能目录):

生成新图像:
bash

首先确保出站目录存在


mkdir -p ~/.openclaw/media/outbound

uv run ~/.openclaw/workspace/skills/openrouter-image-generation/scripts/generate_image.py \
--prompt 你的图像描述 \
--filename ~/.openclaw/media/outbound/output-name.png \
--model google/gemini-2.5-flash-image \
[--aspect-ratio 16:9] \
[--image-size 2K]

编辑现有图像(图像到图像):
bash

首先确保出站目录存在


mkdir -p ~/.openclaw/media/outbound

uv run ~/.openclaw/workspace/skills/openrouter-image-generation/scripts/generate_image.py \
--prompt 编辑指令 \
--filename ~/.openclaw/media/outbound/output-name.png \
--input-image path/to/input.png \
--model google/gemini-2.5-flash-image

重要提示: 默认的 OpenClaw 交付路径为 ~/.openclaw/media/outbound/。请将生成的图像保存到该目录,以便其他 OpenClaw 流程能够轻松获取。

API 密钥

脚本按以下顺序检查 API 密钥:

  1. 1. --api-key 参数
  2. OPENROUTERAPIKEY 环境变量

可选的 OpenRouter 归属标头:

  • - --site-url 或 OPENROUTERSITEURL
  • --app-name 或 OPENROUTERAPPNAME

模型 + 图像配置

  • - --model 为必填项(脚本无默认值)
  • 示例模型:google/gemini-2.5-flash-image
  • 使用 --aspect-ratio 设置 imageconfig.aspectratio(例如 1:1、16:9)
  • 使用 --image-size 设置 imageconfig.imagesize(1K、2K、4K)
  • 使用 --image-config-json {key:value} 设置高级/提供商特定的额外参数(合并到 image_config 中)

注意:OpenRouter 文档显示 aspectratio 和 imagesize 是图像生成的常见图像配置字段。特定提供商/模型可能存在其他键(例如 Sourceful 功能)。如果请求失败,请移除不支持的选项或切换模型。

注意:脚本始终发送 modalities: [image, text]。仅支持图像的模型(某些 FLUX 变体)可能会拒绝此请求——如果使用非 Gemini 模型时遇到意外错误,这可能是原因。目前 CLI 参数未提供解决方法。

默认工作流程(草稿 -> 迭代 -> 最终)

目标:在投入高质量设置之前快速迭代。

  • - 草稿:较小尺寸/较快模型
- --image-size 1K
  • - 迭代:对提示进行小幅调整,每次运行使用新文件名
  • 最终:如果所选模型支持,使用更大尺寸或更高质量
- 示例:--image-size 4K --aspect-ratio 16:9

预检 + 常见故障

  • - 预检:
- command -v uv - test -n $OPENROUTERAPIKEY(或传递 --api-key) - test -d ~/.openclaw/media/outbound || mkdir -p ~/.openclaw/media/outbound - 如果编辑:test -f path/to/input.png
  • - 常见故障:
- Error: No API key provided. -> 设置 OPENROUTERAPIKEY 或传递 --api-key - Error loading input image: -> 路径错误或文件不可读 - HTTP 400 并显示模型/图像配置错误 -> 不支持的模型或无效的 imageconfig.aspectratio / imageconfig.imagesize - HTTP 401/403 -> 密钥无效、无模型访问权限或配额/积分问题 - No image found in response -> 模型可能不支持图像输出或请求格式被拒绝

文件名生成

使用以下模式生成文件名:~/.openclaw/media/outbound/yyyy-mm-dd-hh-mm-ss-name.png

示例:

  • - ~/.openclaw/media/outbound/2026-02-26-14-23-05-product-shot.png
  • ~/.openclaw/media/outbound/2026-02-26-14-25-30-sky-edit.png

提示处理

  • - 对于生成:按原样传递用户的描述,除非描述过于模糊而无法操作。
  • 对于编辑:明确说明需要更改的内容,并保留其他所有内容。

精确编辑的提示模板:

  • - 仅更改:<更改内容>。保持相同:主体、构图/裁剪、姿势、光照、调色板、背景、文字和整体风格。不要添加新对象。

输出

  • - 默认将返回的第一张图像保存到 ~/.openclaw/media/outbound/output-name.png(在 --filename 中传递完整路径)
  • 支持 OpenRouter 的 base64 数据 URL 图像响应(message.images[0].image_url.url)
  • 打印保存的文件路径
  • 除非用户要求,否则不要回读图像

示例

生成新图像:
bash
mkdir -p ~/.openclaw/media/outbound

uv run ~/.openclaw/workspace/skills/openrouter-image-generation/scripts/generate_image.py \
--prompt 一张电影级产品照片,木桌上放着一把哑光黑色机械键盘,温暖的窗光 \
--filename ~/.openclaw/media/outbound/2026-02-26-14-23-05-keyboard-product-shot.png \
--model google/gemini-2.5-flash-image \
--aspect-ratio 16:9 \
--image-size 2K

编辑现有图像:
bash
mkdir -p ~/.openclaw/media/outbound

uv run ~/.openclaw/workspace/skills/openrouter-image-generation/scripts/generate_image.py \
--prompt 仅更改:让天空变得戏剧性,带有橙色日落云彩。保持相同:主体、构图、前景光照和整体风格。 \
--filename ~/.openclaw/media/outbound/2026-02-26-14-25-30-sunset-sky-edit.png \
--model google/gemini-2.5-flash-image \
--input-image original-photo.jpg

参考

  • - OpenRouter 文档:https://openrouter.ai/docs/guides/overview/multimodal/image-generation

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 openrouter-image-generation-1776299018 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 openrouter-image-generation-1776299018 技能

通过命令行安装

skillhub install openrouter-image-generation-1776299018

下载

⬇ 下载 openrouter-image-generation v1.0.0(免费)

文件大小: 5.96 KB | 发布时间: 2026-4-16 17:07

v1.0.0 最新 2026-4-16 17:07
- Initial release of OpenRouter Image Generation skill.
- Allows generating and editing images via OpenRouter-compatible models using the Chat Completions API.
- Supports both text-to-image and image-to-image workflows.
- Fully configurable: choose model, aspect ratio, image size, and advanced provider-specific image configs.
- Handles API key via argument or environment variable, with optional attribution headers.
- Saves generated images to the OpenClaw default outbound media directory for easy integration into other flows.
返回顶部