mcpField
O
openrouter-images

openrouter-images

github.com/openrouterteam创意与媒体309481 次安装1 天前更新
代码仓库

关于 openrouter-images

openrouter-images 是一项通过 OpenRouter Image API 生成和编辑图像的技能,面向需要从文本创作或修改图像的用户。它还可查询模型及其参数,帮助按模型能力选择选项。

主要功能

  1. 01按文本提示生成图像
  2. 02根据提示编辑现有图像
  3. 03查询图像模型与能力
  4. 04查看模型端点支持的参数
  5. 05设置输出格式、尺寸和数量

适用场景

  1. 01比较可用图像模型的能力
  2. 02按描述生成新图像
  3. 03修改照片中的颜色或对象
  4. 04指定比例和分辨率生成图像

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/openrouterteam/skills --skill openrouter-images

安装后在 Claude Code 中输入/openrouter-images确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

README.md
scripts/
discover.ts
edit.ts
generate.ts
lib.ts
package-lock.json
package.json

详细介绍

OpenRouter 图片

通过 OpenRouter 专用的图像 API(POST /api/v1/images)根据文本提示词生成图像并编辑现有图像。此技能还会发现有哪些模型可用,以及每个模型接受哪些参数,帮助你选择有效的模型和选项,而不是靠猜测。

前提条件

必须设置 OPENROUTER_API_KEY 环境变量。请在 https://openrouter.ai/keys 获取密钥。

发现功能(discover.ts)公开可用,无需密钥;生成和编辑则需要密钥。

首次设置

cd <skill-path>/scripts && npm install

决策树

根据用户的需求选择合适的脚本:

用户想要……脚本示例
查看有哪些图像模型及其支持的功能discover.ts“我可以使用哪些图像模型?”
检查特定模型接受的确切参数discover.ts <model>“seedream 支持 4K 吗?”
根据文本描述生成图像generate.ts "prompt"“生成一张山间日落的图像”
使用特定选项生成图像generate.ts "prompt" --aspect-ratio 16:9“生成一张宽幅森林风景图”
使用其他模型生成图像generate.ts "prompt" --model <id>“使用 gemini 3.1 flash lite image 生成图像”
编辑或修改现有图像edit.ts path "prompt"“把 photo.png 中的天空改成紫色”
按照说明变换图像edit.ts path "prompt"“给这张图里的动物戴上一顶派对帽”

先发现功能

不同模型接受的参数各不相同。与其硬编码标志并遇到 400 错误,不如在生成前先发现可用选项。

列出所有图像模型及其精简的功能摘要:

cd <skill-path>/scripts && npx tsx discover.ts

每个条目都会报告模型 id、input_modalities / output_modalities(图像输入表示支持编辑 / 图生图)、supports_streaming,以及 supported_parameters 映射表——其中汇总了该模型任一端点接受的参数。

查看某个模型确切的端点级功能:

cd <skill-path>/scripts && npx tsx discover.ts bytedance-seed/seedream-4.5

此操作会调用 GET /api/v1/images/models/{author}/{slug}/endpoints,并按提供商端点返回以下信息:

字段含义
provider_name / provider_slug提供服务的提供商。使用 provider_slug 作为 --provider-options 中的键。
supported_parameters此端点接受的确切参数及其允许值。
allowed_passthrough_parameters可通过 --provider-options 传入的提供商特定键(例如 steps、guidance)。
supports_streaming此端点是否支持流式传输。
pricing按图像 / 按 token 计价的价格明细。

功能值会以易读的字符串形式显示:枚举显示为 1K | 2K | 4K,范围显示为 0–100,布尔值显示为 supported。缺失的参数表示不受支持——不要发送该参数。

生成图像

根据文本提示词创建新图像:

cd <skill-path>/scripts && npx tsx generate.ts "a red panda wearing sunglasses"
cd <skill-path>/scripts && npx tsx generate.ts "a futuristic cityscape at night" --aspect-ratio 16:9
cd <skill-path>/scripts && npx tsx generate.ts "pixel art of a dragon" --output dragon.png
cd <skill-path>/scripts && npx tsx generate.ts "a watercolor painting" --model google/gemini-3.1-flash-lite-image --resolution 1K

编辑图像

使用文本提示词修改现有图像。源图像会作为图生图参考(input_references)发送,因此请使用 input_modalities 包含 image 的模型——可通过 discover.ts <model> 检查。

cd <skill-path>/scripts && npx tsx edit.ts photo.png "make the sky purple"
cd <skill-path>/scripts && npx tsx edit.ts avatar.jpg "add a party hat" --output avatar-hat.png
cd <skill-path>/scripts && npx tsx edit.ts scene.png "convert to watercolor style" --model google/gemini-3.1-flash-lite-image

支持的输入格式:.png、.jpg、.jpeg、.webp、.gif

选项

generate.ts 和 edit.ts 接受相同的标志。只传递目标模型支持的参数——使用 discover.ts <model> 确认。

标志说明默认值
--model <id>OpenRouter 模型 IDgoogle/gemini-3.1-flash-image-preview
--output <path>输出文件路径image-YYYYMMDD-HHmmss.png
--aspect-ratio <r>宽高比(例如 16:9、1:1、4:3)模型默认值
--resolution <t>分辨率档位(512、1K、2K、4K)模型默认值
--size <s>简写:档位(2K)或指定像素尺寸(2048x2048)模型默认值
--quality <q>auto、low、medium 或 high模型默认值
--output-format <f>png、jpeg、webp 或 svg(矢量模型)模型默认值
--background <b>auto、transparent 或 opaque模型默认值
--output-compression <n>webp/jpeg 的压缩率,范围为 0–100模型默认值
--n <count>要生成的图像数量(1–10,视提供方支持情况而定)1
--seed <int>用于确定性生成的种子(在支持的情况下)随机
--provider-options <json>提供方专属透传参数,以 provider_slug 为键无

--provider-options 接受一个以提供方 slug 为键的 JSON 对象,使用该端点的 allowed_passthrough_parameters 中的键:

cd <skill-path>/scripts && npx tsx generate.ts "a dramatic portrait" \
  --model black-forest-labs/flux.2-pro \
  --provider-options '{"black-forest-labs": {"steps": 40, "guidance": 3}}'

输出格式

generate.ts
{
  "model": "google/gemini-3.1-flash-image-preview",
  "prompt": "a red panda wearing sunglasses",
  "images_saved": ["/absolute/path/to/image-20260305-143022.png"],
  "count": 1
}
edit.ts
{
  "model": "google/gemini-3.1-flash-image-preview",
  "source_image": "photo.png",
  "prompt": "make the sky purple",
  "images_saved": ["/absolute/path/to/image-20260305-143055.png"],
  "count": 1
}

API 返回费用时,生成费用(USD)会打印到 stderr。当 --n 请求生成多张图像时,每张图像都会以 -1、-2、… 为后缀保存。

API 响应结构

生成图像使用 POST /api/v1/images。完整的请求和响应详情请参阅图像生成指南。

图像以 base64 编码的形式返回在 data 数组中。对于栅格 PNG 输出,会省略 media_type;矢量输出(例如 SVG)则会包含该字段,保存文件的扩展名也会与之对应:

{
  "created": 1748372400,
  "data": [{ "b64_json": "<base64-encoded image data>" }],
  "usage": { "prompt_tokens": 0, "completion_tokens": 4175, "total_tokens": 4175, "cost": 0.04 }
}

使用其他模型

默认模型为 google/gemini-3.1-flash-image-preview(Nano Banana 2)。若要使用其他模型,请通过 --model <id> 传入任意图像模型 ID(例如 google/gemini-3.1-flash-lite-image)。运行 discover.ts 浏览图像模型,并运行 discover.ts <model> 确认其支持的参数和提供方,然后再生成。

展示结果

  • 生成或编辑完成后,向用户展示保存的图像
  • 注明所用模型;如果有报告生成费用,也一并注明(费用会打印到 stderr)
  • 如果返回多张图像,请全部展示
  • 如果用户未指定输出路径,请告知文件的保存位置
  • 对于编辑操作,请说明修改的是哪张源图像

评论

支持 Markdown