メインコンテンツへスキップ

人気のモデル


画像から動画への生成では、入力した画像とモーション生成を組み合わせます。出力は元画像との視覚的な一貫性を保ちながら、リアルな動きを加えます。

ステップ 1: 画像を準備する

まず、元となる画像を用意します。ファイルをアップロードする、URL を参照する、または base64 データ URI を指定する、のいずれかの方法を利用できます。
// npm install @krea-ai/sdk
import { openAsBlob } from "node:fs";
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

// Option 1: Upload a local file and use the hosted asset URL
const file = await openAsBlob("./input-image.jpg", { type: "image/jpeg" });
const asset = await krea.assets.upload(file, {
  description: "Input image",
});
const imageUrl = asset.image_url;

// Option 2: Using image URL
// const imageUrl = "https://example.com/input-image.jpg";

ステップ 2: 動画を生成する

画像とモーションパラメータを指定して、/generate/video/kling/kling-2.5 に POST リクエストを送信します。
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

const job = await krea.video("kling/kling-2.5", {
  start_image: imageUrl,
  prompt: "gentle camera pan from left to right, subtle depth",
  duration: 5,
  aspect_ratio: "16:9"
});

console.log(`Job ID: ${job.job_id}`);
API トークンを置き換えてください上記の例にある YOUR_API_TOKEN プレースホルダを置き換えるには、krea.ai/settings/api-tokens で API トークンを生成する必要があります。手順については API キーと請求 のページを参照してください。
レスポンス例
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "queued",
  "created_at": "2025-01-15T10:30:00.000Z",
  "estimated_time": "60-120 seconds"
}

ステップ 3: 結果をポーリングする

/jobs/{job_id} を 5 秒ごとにポーリングして、動画生成の進行状況を確認します。
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

async function waitForVideo(jobId) {
  const completed = await krea.jobs.wait(jobId, { intervalMs: 5000 });
  return completed.result.urls[0];
}

const videoUrl = await waitForVideo(job.job_id);
console.log(`Video ready: ${videoUrl}`);
完了時のレスポンス例
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "created_at": "2025-01-15T10:30:00.000Z",
  "completed_at": "2025-01-15T10:31:45.000Z",
  "result": {
    "urls": ["https://gen.krea.ai/videos/your-video.mp4"]
  }
}
Webhook が利用可能ですジョブが完了したときに通知を受け取るために Webhook を設定できます。詳しくは Webhooks ガイド を参照してください。

主なパラメータ

すべてのモデルの詳細なパラメータ一覧は、モデル API のページを参照してください。
パラメータ説明
start_imagestring元画像の URL
promptstring望ましい動きやカメラワークの説明
durationnumber動画の長さ(秒)。指定できる値はモデルによって異なります。
aspect_ratiostring動画のアスペクト比(例: 16:99:161:1)
end_imagestring対応モデル向けの、オプションの終了フレーム URL
modestring品質モードを公開しているモデル向けのオプション
モーションプロンプトのヒント:
  • カメラワーク(パン、ズーム、ドリー、ティルト)を記述する
  • 動きの方向と速度を指定する
  • 奥行きや視差効果に言及する
  • 控えめなアニメーションには、抑制された表現のカメラ用語を使う
  • ダイナミックな演出には、より強い動作動詞を使う