openrouter-images
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenRouter Images
OpenRouter 图像生成与编辑
Generate images from text prompts and edit existing images via OpenRouter's chat completions API with image modalities.
通过OpenRouter支持图像模态的聊天补全API,根据文本提示生成图像并编辑现有图像。
Prerequisites
前置条件
The environment variable must be set. Get a key at https://openrouter.ai/keys
OPENROUTER_API_KEY必须设置环境变量。可前往https://openrouter.ai/keys 获取密钥。
OPENROUTER_API_KEYFirst-Time Setup
首次设置
bash
cd <skill-path>/scripts && npm installbash
cd <skill-path>/scripts && npm installDecision Tree
决策树
Pick the right script based on what the user is asking:
| User wants to... | Script | Example |
|---|---|---|
| Generate an image from a text description | | "Create an image of a sunset over mountains" |
| Generate with specific aspect ratio | | "Make a wide landscape image of a forest" |
| Generate with a different model | | "Generate using gemini-2.5-flash-image" |
| Edit or modify an existing image | | "Make the sky purple in photo.png" |
| Transform an image with instructions | | "Add a party hat to the animal in this image" |
根据用户需求选择合适的脚本:
| 用户想要... | 脚本 | 示例 |
|---|---|---|
| 根据文本描述生成图像 | | "创建一幅山脉日落的图像" |
| 生成指定宽高比的图像 | | "制作一幅宽幅森林景观图" |
| 使用其他模型生成图像 | | "使用gemini-2.5-flash-image生成图像" |
| 编辑或修改现有图像 | | "将photo.png中的天空改为紫色" |
| 根据指令转换图像 | | "给这张图片里的动物添加派对帽" |
Generate Image
生成图像
Create a new image from a text prompt:
bash
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-2.5-flash-image根据文本提示创建新图像:
bash
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-2.5-flash-imageOptions
参数选项
| Flag | Description | Default |
|---|---|---|
| OpenRouter model ID | |
| Output file path | |
| Aspect ratio (e.g. | Model default |
| Image size (e.g. | Model default |
| 参数 | 说明 | 默认值 |
|---|---|---|
| OpenRouter模型ID | |
| 输出文件路径 | |
| 宽高比(例如 | 模型默认值 |
| 图像尺寸(例如 | 模型默认值 |
Edit Image
编辑图像
Modify an existing image with a text prompt:
bash
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-2.5-flash-image通过文本提示修改现有图像:
bash
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-2.5-flash-imageOptions
参数选项
| Flag | Description | Default |
|---|---|---|
| OpenRouter model ID | |
| Output file path | |
| Aspect ratio (e.g. | Model default |
| Image size (e.g. | Model default |
Supported input formats: , , , ,
.png.jpg.jpeg.webp.gif| 参数 | 说明 | 默认值 |
|---|---|---|
| OpenRouter模型ID | |
| 输出文件路径 | |
| 宽高比(例如 | 模型默认值 |
| 图像尺寸(例如 | 模型默认值 |
支持的输入格式:, , , ,
.png.jpg.jpeg.webp.gifOutput Format
输出格式
generate.ts
generate.ts
json
{
"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
}json
{
"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
edit.ts
json
{
"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
}json
{
"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 Response Shapes
API响应格式
Image generation uses with . See the Responses API reference and image generation guide for full request details.
POST /api/v1/responsesmodalities: ["image", "text"]The image-specific output item type is — this is not obvious from the general Responses API docs:
image_generation_calljson
{
"type": "image_generation_call",
"id": "imagegen-abc123",
"status": "completed",
"result": "<base64-encoded image data>"
}This appears alongside standard output items in the array. Text and image outputs may each be absent depending on the model and prompt.
messageoutput图像生成使用接口,并指定。如需完整请求详情,请查看Responses API参考文档和图像生成指南。
POST /api/v1/responsesmodalities: ["image", "text"]图像专属的输出项类型为——这在通用Responses API文档中并未明确说明:
image_generation_calljson
{
"type": "image_generation_call",
"id": "imagegen-abc123",
"status": "completed",
"result": "<base64-encoded image data>"
}该输出项会与标准输出项一同出现在数组中。根据模型和提示的不同,文本和图像输出可能会缺失其一。
messageoutputUsing a Different Model
使用其他模型
The default model is (Nano Banana 2). To use a different model, pass with any OpenRouter model ID that supports image output modalities.
google/gemini-3.1-flash-image-preview--model <id>Use the skill to discover image-capable models:
openrouter-modelsbash
cd <openrouter-models-skill-path>/scripts && npx tsx search-models.ts --modality image默认模型为(Nano Banana 2)。如需使用其他模型,可通过参数传入任何支持图像输出模态的OpenRouter模型ID。
google/gemini-3.1-flash-image-preview--model <id>可使用工具发现支持图像功能的模型:
openrouter-modelsbash
cd <openrouter-models-skill-path>/scripts && npx tsx search-models.ts --modality imagePresenting Results
结果展示
- After generating or editing, display the saved image to the user
- Include the model used and any text response the model provided (printed to stderr)
- If multiple images are returned, show all of them
- When the user doesn't specify an output path, tell them where the file was saved
- For edit operations, mention the source image that was modified
- 生成或编辑完成后,向用户展示保存的图像
- 说明使用的模型以及模型返回的任何文本响应(会打印至stderr)
- 如果返回多张图像,需全部展示
- 当用户未指定输出路径时,告知用户文件的保存位置
- 对于编辑操作,提及被修改的源图像