← 返回
内容创作 Key 中文

Openrouter Image Generation

Generate or edit images through OpenRouter's multimodal image generation endpoint (`/api/v1/chat/completions`) using OpenRouter-compatible image models. Use...
{ "通过 OpenRouter 的多模态图像生成端点 (`/api/v1/chat/completions`),使用兼容 OpenRouter 的图像模型生成或编辑图像。使用……" : null }
bawerlacher
内容创作 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 3
Stars
📥 963
下载
💾 34
安装
1
版本
#latest

概述

OpenRouter Image Generation & Editing

Generate new images or edit existing ones using OpenRouter image-capable models via the Chat Completions API.

Usage

Run the script using absolute path (do NOT cd to the skill directory first):

Generate new image:

# Ensure outbound directory exists first
mkdir -p ~/.openclaw/media/outbound

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

Edit existing image (image-to-image):

# Ensure outbound directory exists first
mkdir -p ~/.openclaw/media/outbound

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

Important: Default OpenClaw delivery path is ~/.openclaw/media/outbound/. Save generated images there so other OpenClaw flows can pick them up easily.

API Key

The script checks for API key in this order:

  1. --api-key argument
  2. OPENROUTER_API_KEY environment variable

Optional OpenRouter attribution headers:

  • --site-url or OPENROUTER_SITE_URL
  • --app-name or OPENROUTER_APP_NAME

Model + Image Config

  • --model is required (no script default)
  • Example model: google/gemini-2.5-flash-image
  • Use --aspect-ratio for image_config.aspect_ratio (for example 1:1, 16:9)
  • Use --image-size for image_config.image_size (1K, 2K, 4K)
  • Use --image-config-json '{"key":"value"}' for advanced/provider-specific extras (merged into image_config)

Note: OpenRouter docs show aspect_ratio and image_size as the common image config fields for image generation. Additional keys may exist for specific providers/models (for example Sourceful features). If a request fails, remove unsupported options or switch models.

Note: The script always sends modalities: ["image", "text"]. Image-only models (some FLUX variants) may reject this — if you get an unexpected error with a non-Gemini model, this may be the cause. No workaround is currently exposed via CLI args.

Default Workflow (draft -> iterate -> final)

Goal: iterate quickly before spending time on higher-quality settings.

  • Draft: smaller size / faster model
  • --image-size 1K
  • Iterate: adjust prompt in small diffs and keep a new filename each run
  • Final: larger size or higher quality if the selected model supports it
  • Example: --image-size 4K --aspect-ratio 16:9

Preflight + Common Failures

  • Preflight:
  • command -v uv
  • test -n "$OPENROUTER_API_KEY" (or pass --api-key)
  • test -d ~/.openclaw/media/outbound || mkdir -p ~/.openclaw/media/outbound
  • If editing: test -f "path/to/input.png"
  • Common failures:
  • Error: No API key provided. -> set OPENROUTER_API_KEY or pass --api-key
  • Error loading input image: -> bad path or unreadable file
  • HTTP 400 with model/image config error -> unsupported model or invalid image_config.aspect_ratio / image_config.image_size
  • HTTP 401/403 -> invalid key, no model access, or quota/credits issue
  • No image found in response -> model may not support image output or request format rejected

Filename Generation

Generate filenames with the pattern: ~/.openclaw/media/outbound/yyyy-mm-dd-hh-mm-ss-name.png

Examples:

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

Prompt Handling

  • For generation: pass the user's description as-is unless it is too vague to be actionable.
  • For editing: make the requested change explicit and preserve everything else.

Prompt template for precise edits:

  • Change ONLY: . Keep identical: subject, composition/crop, pose, lighting, color palette, background, text, and overall style. Do not add new objects.

Output

  • Save the first returned image to ~/.openclaw/media/outbound/output-name.png by default (pass that full path in --filename)
  • Supports OpenRouter's base64 data URL image responses (message.images[0].image_url.url)
  • Prints the saved file path
  • Do not read the image back unless the user asks

Examples

Generate new image:

mkdir -p ~/.openclaw/media/outbound

uv run ~/.openclaw/workspace/skills/openrouter-image-generation/scripts/generate_image.py \
  --prompt "A cinematic product photo of a matte black mechanical keyboard on a wooden desk, warm window light" \
  --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

Edit existing image:

mkdir -p ~/.openclaw/media/outbound

uv run ~/.openclaw/workspace/skills/openrouter-image-generation/scripts/generate_image.py \
  --prompt "Change ONLY: make the sky dramatic with orange sunset clouds. Keep identical: subject, composition, lighting on foreground, and overall style." \
  --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"

Reference

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

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 17:12 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

content-creation

Humanizer

biostartechnology
消除AI写作痕迹,使文本更自然真实。基于维基百科"AI写作特征"指南,识别并修正夸张象征、宣传用语、肤浅-ing分析、模糊归因、破折号滥用、三项排比、AI词汇、负面平行结构及冗长连接词等模式。
★ 857 📥 199,251
content-creation

Baidu Wenku AIPPT

ide-rea
使用百度文库 AI 智能生成 PPT,自动根据内容选择模板。
★ 66 📥 46,129
content-creation

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 141 📥 41,015