返回顶部
o

openrouter-image-generationOpenRouter图像生成

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
安全检测
已通过
495
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

openrouter-image-generation

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/输出名称.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/输出名称.png \
--input-image 输入图像路径.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 输入图像路径.png
  • - 常见失败:
- 错误:未提供 API 密钥。 -> 设置 OPENROUTERAPIKEY 或传递 --api-key - 加载输入图像时出错: -> 路径错误或文件不可读 - HTTP 400 并显示模型/图像配置错误 -> 不支持的模型或无效的 imageconfig.aspectratio / imageconfig.imagesize - HTTP 401/403 -> 密钥无效、无模型访问权限或配额/积分问题 - 响应中未找到图像 -> 模型可能不支持图像输出或请求格式被拒绝

文件名生成

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

示例:

  • - ~/.openclaw/media/outbound/2026-02-26-14-23-05-产品照片.png
  • ~/.openclaw/media/outbound/2026-02-26-14-25-30-天空编辑.png

提示处理

  • - 生成:直接传递用户的描述,除非描述过于模糊无法执行。
  • 编辑:明确说明要进行的更改,并保留其他所有内容。

精确编辑的提示模板:

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

输出

  • - 默认将返回的第一张图像保存到 ~/.openclaw/media/outbound/输出名称.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-键盘产品照片.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-日落天空编辑.png \
--model google/gemini-2.5-flash-image \
--input-image 原始照片.jpg

参考

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

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

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

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

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

通过命令行安装

skillhub install openrouter-image-generation-1776118756

下载

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

文件大小: 5.95 KB | 发布时间: 2026-4-15 13:48

v1.0.0 最新 2026-4-15 13:48
- 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.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部