ClawSkills logoClawSkills

ImageRouter

使用 ImageRouter API(需要 API 密钥)通过任何模型生成 AI 图像。

介绍

# ImageRouter Image Generation

使用 curl 命令通过 ImageRouter 上可用的任何模型生成图像。

## 可用模型 `test/test` 模型是一个用于测试 API 的免费虚拟模型。它不是真正的模型,因此您应该使用其他模型来生成图像。

获取前 10 个最受欢迎的模型: ```bash curl -X POST 'https://backend.imagerouter.io/operations/get-popular-models' ```

按名称搜索可用模型: ```bash curl "https://api.imagerouter.io/v1/models?type=image&sort=date&name=gemini" ```

获取所有可用模型: ```bash curl "https://api.imagerouter.io/v1/models?type=image&sort=date&limit=1000" ```

## 快速开始 - 文生图 (Text-to-Image)

使用 JSON 端点进行基本生成: ```bash curl 'https://api.imagerouter.io/v1/openai/images/generations' \ -H 'Authorization: Bearer YOUR_API_KEY' \ --json '{ "prompt": "a serene mountain landscape at sunset", "model": "test/test", "quality": "auto", "size": "auto", "response_format": "url", "output_format": "webp" }' ```

## 统一端点 (文生图与图生图)

### 使用 multipart/form-data 进行文生图: ```bash curl 'https://api.imagerouter.io/v1/openai/images/edits' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -F 'prompt=a cyberpunk city at night' \ -F 'model=test/test' \ -F 'quality=high' \ -F 'size=1024x1024' \ -F 'response_format=url' \ -F 'output_format=webp' ```

### 图生图 (包含输入图像): ```bash curl 'https://api.imagerouter.io/v1/openai/images/edits' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -F 'prompt=transform this into a watercolor painting' \ -F 'model=test/test' \ -F 'quality=auto' \ -F 'size=auto' \ -F 'response_format=url' \ -F 'output_format=webp' \ -F 'image[]=@/path/to/your/image.webp' ```

### 多张图像 (最多 16 张): ```bash curl 'https://api.imagerouter.io/v1/openai/images/edits' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -F 'prompt=combine these images' \ -F 'model=test/test' \ -F 'image[][email protected]' \ -F 'image[][email protected]' \ -F 'image[][email protected]' ```

### 带遮罩 (某些模型进行重绘时需要遮罩): ```bash curl 'https://api.imagerouter.io/v1/openai/images/edits' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -F 'prompt=fill the masked area with flowers' \ -F 'model=test/test' \ -F 'image[][email protected]' \ -F 'mask[][email protected]' ```

## 参数

- **model** (必填): 要使用的图像模型 (参见 https://imagerouter.io/models) - **prompt** (可选): 生成的文本描述。大多数模型需要文本提示,但并非全部。 - **quality** (可选): `auto` (默认), `low`, `medium`, `high` - **size** (可选): `auto` (默认) 或 `WIDTHxHEIGHT` (例如 `1024x1024`)。 - **response_format** (可选): - `url` (默认) - 返回托管的 URL - `b64_json` - 返回 base64 编码的图像 - `b64_ephemeral` - Base64 格式且不保存到日志 - **output_format** (可选): `webp` (默认), `jpeg`, `png` - **image[]** (可选): 图生图的输入文件 (仅限 multipart) - **mask[]** (可选): 用于重绘的编辑遮罩 (仅限 multipart)

## 响应格式

```json { "created": 1769286389027, "data": [ { "url": "https://storage.imagerouter.io/fffb4426-efbd-4bcc-87d5-47e6936bf0bb.webp" } ], "latency": 6942, "cost": 0.004 } ```

## 端点对比

| 功能 | 统一端点 (/edits) | JSON 端点 (/generations) | |---------|------------------|---------------------| | 文生图 | ✅ | ✅ | | 图生图 | ✅ | ❌ | | 编码方式 | multipart/form-data | application/json |

## 提示

- `/v1/openai/images/generations` 和 `/v1/openai/images/edits` 对于统一端点来说是一样的 - 当您不需要文件上传时,使用 JSON 端点进行简单的文生图 - 当您需要图生图功能时,使用统一端点 - 在 https://imagerouter.io/models 检查模型功能 (质量支持、编辑支持等) - 在 https://imagerouter.io/api-keys 获取您的 API 密钥

## 按用例分类的示例

### 快速测试生成: ```bash curl 'https://api.imagerouter.io/v1/openai/images/generations' \ -H 'Authorization: Bearer YOUR_API_KEY' \ --json '{"prompt":"test image","model":"test/test"}' ```

### 直接下载图像: ```bash curl 'https://api.imagerouter.io/v1/openai/images/generations' \ -H 'Authorization: Bearer YOUR_API_KEY' \ --json '{"prompt":"abstract art","model":"test/test"}' \ | jq -r '.data[0].url' \ | xargs curl -o output.webp ```

更多产品