mcpField
I
integrate-image

integrate-image

github.com/runwaymlクリエイティブ・メディア7449 回インストール2 日前に更新
リポジトリ

integrate-image について

Integrate Image Generationは、開発者がRunwayの画像生成をサーバー側コードに組み込むためのスキルです。Node.jsとPythonのSDK例、APIルートの構成、モデル選択、参照画像の利用方法を扱います。

主な機能

  1. 01Runwayのテキスト画像生成API呼び出し
  2. 02画像生成モデルの選択
  3. 03タグ付き参照画像による生成誘導
  4. 04画像のアスペクト比設定
  5. 05サーバー側ルートの実装例

活用シーン

  1. 01サーバーアプリに画像生成を追加
  2. 02参照画像で生成画像を誘導
  3. 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_flashGoogle 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();

共通パラメーター

パラメーター型説明
modelstringモデル ID(必須)
promptTextstring画像のテキスト説明(必須)
ratiostringアスペクト比。例:'1280:720'、'720:1280'、'1080:1080'
referenceImagesarray任意。視覚的なガイダンスに使用する { 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 クレジットで最も低コストの選択肢です。プロトタイピングに適しています。

コメント