关于 integrate-image
Integrate Image Generation 是一项帮助开发者将 Runway 文生图功能接入服务端代码的技能,涵盖 Node.js 和 Python SDK 用法及 API 路由示例。它还说明如何用参考图引导生成,并提示本地图片需先上传。
主要功能
- 01调用 Runway 文生图接口
- 02选择不同图像生成模型
- 03使用参考图和标签引导生成
- 04设置图像宽高比
- 05查看服务端路由集成示例
适用场景
- 01为服务端应用添加文生图接口
- 02用参考图控制生成图像风格
- 03在原型开发中使用快速模型
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ runwayml/ skills --skill integrate-image安装后在 Claude Code 中输入/integrate-image确认已加载。
详细介绍
集成图像生成
前置条件: 请先运行
+check-compatibility。集成前运行+fetch-api-reference,以加载最新 API 参考。API 凭据需要+setup-api-key。如果用户有本地参考图像,则需要+integrate-uploads。
帮助用户将 Runway 图像生成功能添加到服务器端代码中。
可用模型
| 模型 | 最适合 | 费用 | 速度 |
|---|---|---|---|
gen4_image | 最高质量 | 5 个积分(720p),8 个积分(1080p) | 标准 |
gen4_image_turbo | 快速生成 | 2 个积分 | 快 |
gemini_2.5_flash | Google Gemini 模型 | 5 个积分 | 标准 |
模型选择建议:
- 默认推荐:
gen4_image— 质量最佳 - 注重预算/速度:
gen4_image_turbo— 最便宜、速度最快
端点:POST /v1/text_to_image
基本文生图
// Node.js SDK
import RunwayML from '@runwayml/sdk';
const client = new RunwayML();
const task = await client.textToImage.create({
model: 'gen4_image',
promptText: 'A serene Japanese garden with cherry blossoms and a koi pond',
ratio: '1280:720'
}).waitForTaskOutput();
const imageUrl = task.output[0];
# Python SDK
from runwayml import RunwayML
client = RunwayML()
task = client.text_to_image.create(
model='gen4_image',
prompt_text='A serene Japanese garden with cherry blossoms and a koi pond',
ratio='1280:720'
).wait_for_task_output()
image_url = task.output[0]
使用参考图像
参考图像可以通过视觉参考引导生成。在提示词中使用 @Tag 语法引用特定图像。
const task = await client.textToImage.create({
model: 'gen4_image',
promptText: '@EiffelTower painted in the style of @StarryNight',
referenceImages: [
{ uri: 'https://example.com/eiffel-tower.jpg', tag: 'EiffelTower' },
{ uri: 'https://example.com/starry-night.jpg', tag: 'StarryNight' }
],
ratio: '1280:720'
}).waitForTaskOutput();
task = client.text_to_image.create(
model='gen4_image',
prompt_text='@EiffelTower painted in the style of @StarryNight',
reference_images=[
{"uri": "https://example.com/eiffel-tower.jpg", "tag": "EiffelTower"},
{"uri": "https://example.com/starry-night.jpg", "tag": "StarryNight"}
],
ratio='1280:720'
).wait_for_task_output()
如果用户有本地参考图像,请先使用 +integrate-uploads 上传:
import fs from 'fs';
const refUpload = await client.uploads.createEphemeral(
fs.createReadStream('/path/to/reference.jpg')
);
const task = await client.textToImage.create({
model: 'gen4_image',
promptText: 'A portrait in the style of @Reference',
referenceImages: [
{ uri: refUpload.runwayUri, tag: 'Reference' }
],
ratio: '1280:720'
}).waitForTaskOutput();
常用参数
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | 模型 ID(必填) |
promptText | string | 图像的文字描述(必填) |
ratio | string | 宽高比,例如 '1280:720'、'720:1280'、'1080:1080' |
referenceImages | array | 可选。用于视觉引导的 { uri, tag } 对象数组 |
集成模式
示例:Express.js API 路由
import RunwayML from '@runwayml/sdk';
import express from 'express';
const client = new RunwayML();
const app = express();
app.use(express.json());
app.post('/api/generate-image', async (req, res) => {
try {
const { prompt, model = 'gen4_image', ratio = '1280:720', referenceImages } = req.body;
const task = await client.textToImage.create({
model,
promptText: prompt,
ratio,
...(referenceImages && { referenceImages })
}).waitForTaskOutput();
res.json({ imageUrl: task.output[0] });
} catch (error) {
console.error('Image generation failed:', error);
res.status(500).json({ error: error.message });
}
});
示例:Next.js API 路由
// app/api/generate-image/route.ts
import RunwayML from '@runwayml/sdk';
import { NextRequest, NextResponse } from 'next/server';
const client = new RunwayML();
export async function POST(request: NextRequest) {
const { prompt, referenceImages } = await request.json();
try {
const task = await client.textToImage.create({
model: 'gen4_image',
promptText: prompt,
ratio: '1280:720',
...(referenceImages && { referenceImages })
}).waitForTaskOutput();
return NextResponse.json({ imageUrl: task.output[0] });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : 'Generation failed' },
{ status: 500 }
);
}
}
示例:FastAPI 路由
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from runwayml import RunwayML
app = FastAPI()
client = RunwayML()
class ImageRequest(BaseModel):
prompt: str
model: str = "gen4_image"
ratio: str = "1280:720"
reference_images: list[dict] | None = None
@app.post("/api/generate-image")
async def generate_image(req: ImageRequest):
try:
params = {
"model": req.model,
"prompt_text": req.prompt,
"ratio": req.ratio,
}
if req.reference_images:
params["reference_images"] = req.reference_images
task = client.text_to_image.create(**params).wait_for_task_output()
return {"image_url": task.output[0]}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
提示
- 输出 URL 会在 24-48 小时后过期。 请立即将图像下载到自己的存储空间。
- 参考图像在提示词中使用
@Tag语法 — 标签必须与referenceImages数组中的tag字段一致。 - 对于本地文件,请始终先通过
+integrate-uploads上传,然后使用runway://URI。 gen4_image_turbo是最便宜的选项,每张图像仅需 2 个积分,适合原型开发。
评论
支持 Markdown