OpenRouter Image Generation
Generate images from prompts using OpenRouter's image generation endpoint.
Requirements
- -
OPENROUTER_API_KEY in environment - INLINECODE1
- Python package: INLINECODE2
Install dependency:
CODEBLOCK0
FTUX preflight (run first)
CODEBLOCK1
If checks fail, tell the user exactly what is missing and provide copy/paste fix steps from the Fixups output.
Default model
- - INLINECODE4
- Optional alternatives (if enabled on your account):
openai/gpt-5-image, INLINECODE6
Usage
CODEBLOCK2
Optional args:
CODEBLOCK3
Queue -> response pattern (avoid traffic jams)
When a user asks for multiple images/iterations, do not hold one long-running turn per image.
Do not block waiting for a "single message with all files" if the adapter does not support it.
Hard contract for queue mode:
- - NEVER run
run_image_queue.py in the same foreground turn as enqueue for multi-image requests. - ALWAYS enqueue + immediate queued ack first, then background handoff.
Use a queue + batched response flow:
- 1. Enqueue each requested image quickly.
- Immediately return with a short "queued" acknowledgement (do not wait for generation in the same turn).
- Drain queue in background (preferred: sub-agent/session worker).
- Send one consolidated completion status response when done.
- Always attach generated image files (never send only paths).
- If the messaging adapter allows only one media per send, post attachments as reply-chain messages under the consolidated completion status message (one file per message).
Enqueue command:
CODEBLOCK4
Background queue handoff (recommended):
CODEBLOCK5
Manual drain command (worker context only; not same foreground turn):
CODEBLOCK6
Batch-enqueue N variants with consistent file names:
CODEBLOCK7
Useful options:
CODEBLOCK8
Data transmission notice (external provider)
- - This skill sends prompts and generated/edit inputs to OpenRouter (
openrouter.ai). - If you pass
--baseline-image, that image content is transmitted to the provider as part of the request. - Do not submit sensitive/private images unless the user explicitly approves external transmission.
Notes
- - If generation fails due to model/provider mismatch, retry with
--model openai/gpt-5-image-mini. - Local baseline uploads are deny-by-default; pass
--confirm-external-upload only when user explicitly approves sending that local file to provider. - Local baseline files are restricted to png/jpg/jpeg/webp, non-symlink regular files, workspace-local paths, and max size threshold.
- For iterative work, prefer
--image-size low; switch to medium or high for final renders. - Use
--clarify-hints to surface prompt-quality gaps early; use --strict-clarify for workflows that must fail on ambiguity. - Keep prompts explicit for text rendering tasks.
- Save outputs into workspace paths, not
/tmp, for durability. - When user asks for generated images in chat, attach the generated file in the response (do not only send a path).
- For queue mode, read results from:
-
.../imagegen-queue/results/*.json (success)
-
.../imagegen-queue/failed/*.json (failure details)
- - Edit/variant intent prompts fail fast if no baseline is supplied (
--baseline-image) unless explicitly overridden. - Resolve baseline deterministically in caller: current-message attachment > replied-message attachment > clarification request.
- Pass
--baseline-source-kind current_attachment|reply_attachment|explicit_path_or_url for auditable provenance. - When baseline is supplied, rails default to low-variation + locked palette/composition unless explicitly changed.
- Queue results persist provider metadata (generation id + provider response payload/path) and drift diagnostics (
edit_intent_detected, baseline_applied, baseline_source, baseline_source_kind, baseline_resolution_policy, rails_applied) to help edits/debugging and smarter agent continuation. - Queue worker writes
handoff_mode + same_turn_drain_detected so you can enforce true async behavior in tests/ops. - INLINECODE30 writes
<prefix>-manifest.json with baseline, constraints, variant deltas, and output targets for reproducible reruns.
OpenRouter 图像生成
使用 OpenRouter 的图像生成端点,根据提示词生成图像。
环境要求
- - 环境中需配置 OPENROUTERAPIKEY
- python3
- Python 包:requests
安装依赖:
bash
python3 -m pip install requests
首次使用前检查(先运行)
bash
python3 {baseDir}/scripts/preflight_check.py
python3 {baseDir}/scripts/preflight_check.py --json
如果检查失败,请准确告知用户缺少什么,并从 Fixups 输出中提供可复制/粘贴的修复步骤。
默认模型
- - google/gemini-3.1-flash-image-preview
- 可选替代模型(如果您的账户已启用):openai/gpt-5-image、openai/gpt-5-image-mini
使用方法
bash
python3 {baseDir}/scripts/generate_image.py \
--prompt 一只赛博朋克螃蟹的电影级肖像 \
--model google/gemini-3.1-flash-image-preview \
--image-size low \
--out ./generated/cyber-crab.png
可选参数:
bash
--model openai/gpt-5-image
--model openai/gpt-5-image-mini
--image-size low|medium|high
--clarify-hints # 将提示质量提示打印到 stderr
--strict-clarify # 当提示词描述不明确时快速失败
--baseline-image ./path/to/reference.png
--baseline-source-kind currentattachment|replyattachment|explicitpathor_url
--confirm-external-upload # 本地基线文件上传时需要
--variation-strength low|medium|high
--must-keep 标题位置
--must-keep 徽标标记
--lock-palette
--lock-composition
--allow-no-baseline-on-edit-intent
队列 -> 响应模式(避免流量拥堵)
当用户请求多张图像/迭代时,不要为每张图像保持一个长时间运行的轮次。
如果适配器不支持,不要阻塞等待包含所有文件的单条消息。
队列模式的硬性约定:
- - 对于多图像请求,绝不在与入队相同的前台轮次中运行 runimagequeue.py。
- 始终先入队 + 立即返回队列确认,然后进行后台交接。
使用队列 + 批量响应流程:
- 1. 快速将每个请求的图像入队。
- 立即返回一条简短的已入队确认消息(不要在同一轮次中等待生成)。
- 在后台处理队列(推荐:子代理/会话工作器)。
- 完成后发送一条合并的完成状态响应。
- 始终附加生成的图像文件(绝不只发送路径)。
- 如果消息适配器每次只允许发送一个媒体,则在合并的完成状态消息下以回复链消息的形式发布附件(每条消息一个文件)。
入队命令:
bash
python3 {baseDir}/scripts/enqueueimagejob.py \
--prompt 一张复古80年代螃蟹海报 \
--model google/gemini-3.1-flash-image-preview \
--image-size low \
--clarify-hints \
--out ./generated/crab-01.png \
--request-id discord-<消息ID>
后台队列交接(推荐):
bash
python3 {baseDir}/scripts/queueandreturn.py \
--prompt 一个极简的雪蟹标志 \
--count 4 \
--request-id discord-<消息ID> \
--out-dir ./generated \
--prefix crab-logo \
--queue-dir ./generated/imagegen-queue
手动处理队列命令(仅工作器上下文使用;不在同一前台轮次中):
bash
python3 {baseDir}/scripts/runimagequeue.py \
--queue-dir ./generated/imagegen-queue
queueandreturn 防护措施(可选调优)
python3 {baseDir}/scripts/queue
andreturn.py \
--max-background-workers 2 \
--orphan-timeout-sec 1800 \
...
批量入队 N 个变体,文件名保持一致:
bash
python3 {baseDir}/scripts/enqueue_variants.py \
--prompt 一个极简的雪蟹标志 \
--count 4 \
--baseline-image ./generated/base-logo.png \
--variation-strength low \
--lock-palette \
--lock-composition \
--must-keep 文字标记位置 \
--must-keep 图标轮廓 \
--out-dir ./generated \
--prefix crab-logo \
--request-id discord-<消息ID>
有用的选项:
bash
--max-jobs 3 # 仅处理子集以控制批次
--start-index 5 # 从先前批次的编号继续
数据传输通知(外部提供商)
- - 此技能将提示词和生成的/编辑的输入发送到 OpenRouter(openrouter.ai)。
- 如果您传递 --baseline-image,该图像内容将作为请求的一部分传输给提供商。
- 除非用户明确批准外部传输,否则不要提交敏感/私人图像。
注意事项
- - 如果由于模型/提供商不匹配导致生成失败,请使用 --model openai/gpt-5-image-mini 重试。
- 本地基线上传默认拒绝;仅在用户明确批准将本地文件发送给提供商时传递 --confirm-external-upload。
- 本地基线文件限制为 png/jpg/jpeg/webp 格式、非符号链接的常规文件、工作区本地路径,并有最大大小阈值。
- 对于迭代工作,优先使用 --image-size low;在最终渲染时切换到 medium 或 high。
- 使用 --clarify-hints 尽早发现提示质量差距;对于必须在歧义时失败的工作流,使用 --strict-clarify。
- 对于文本渲染任务,保持提示词明确。
- 将输出保存到工作区路径,而不是 /tmp,以确保持久性。
- 当用户在聊天中请求生成的图像时,在响应中附加生成的文件(不要只发送路径)。
- 对于队列模式,从以下位置读取结果:
- .../imagegen-queue/results/*.json(成功)
- .../imagegen-queue/failed/*.json(失败详情)
- - 编辑/变体意图提示词在未提供基线(--baseline-image)时会快速失败,除非明确覆盖。
- 在调用方确定性地解析基线:当前消息附件 > 回复消息附件 > 澄清请求。
- 传递 --baseline-source-kind currentattachment|replyattachment|explicitpathorurl 以实现可审计的溯源。
- 当提供基线时,防护措施默认为低变体 + 锁定调色板/构图,除非明确更改。
- 队列结果会持久保存提供商元数据(生成 ID + 提供商响应负载/路径)和漂移诊断(editintentdetected、baselineapplied、baselinesource、baselinesourcekind、baselineresolutionpolicy、railsapplied),以帮助编辑/调试和更智能的代理延续。
- 队列工作器会写入 handoffmode + sameturndraindetected,以便您在测试/操作中强制执行真正的异步行为。
- enqueue_variants.py 会写入 <前缀>-manifest.json,包含基线、约束、变体差异和输出目标,以实现可重复的重新运行。