integrate-image について
Integrate Image Generationは、開発者がRunwayの画像生成をサーバー側コードに組み込むためのスキルです。Node.jsとPythonのSDK例、APIルートの構成、モデル選択、参照画像の利用方法を扱います。
主な機能
- 01Runwayのテキスト画像生成API呼び出し
- 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は画像 1 枚あたり 2 クレジットで最も低コストの選択肢です。プロトタイピングに適しています。
コメント
Markdown 対応