人気のモデル
動画生成は通常、画像生成よりも時間がかかります。動画の長さや品質設定によって処理時間が長くなることがあります。
ステップ 1: 動画を生成する
/generate/video/kling/kling-2.5 にプロンプトと動画パラメータを指定して POST リクエストを送信します。API は即座にジョブ ID を返します。
// 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", {
prompt: "a majestic eagle soaring over snow-capped mountains at sunrise",
duration: 5,
aspect_ratio: "16:9"
});
console.log(`Job ID: ${job.job_id}`);
curl -X POST https://api.krea.ai/generate/video/kling/kling-2.5 \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"prompt": "a majestic eagle soaring over snow-capped mountains at sunrise",
"duration": 5,
"aspect_ratio": "16:9"
}'
import requests
API_BASE = "https://api.krea.ai"
API_TOKEN = "YOUR_API_TOKEN"
response = requests.post(
f"{API_BASE}/generate/video/kling/kling-2.5",
headers={
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
},
json={
"prompt": "a majestic eagle soaring over snow-capped mountains at sunrise",
"duration": 5,
"aspect_ratio": "16:9"
}
)
job = response.json()
print(f"Job ID: {job['job_id']}")
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
apiBase := "https://api.krea.ai"
apiToken := "YOUR_API_TOKEN"
payload := map[string]interface{}{
"prompt": "a majestic eagle soaring over snow-capped mountains at sunrise",
"duration": 5,
"aspect_ratio": "16:9",
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", apiBase+"/generate/video/kling/kling-2.5", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer "+apiToken)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var job map[string]interface{}
json.NewDecoder(resp.Body).Decode(&job)
fmt.Printf("Job ID: %s\n", job["job_id"])
}
API トークンを置き換えてください上記のサンプルにある YOUR_API_TOKEN プレースホルダーを置き換えるには、krea.ai/settings/api-tokens で API トークンを生成する必要があります。ヘルプが必要な場合は、API Keys & Billing ページの手順に従ってください。
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "queued",
"created_at": "2025-01-15T10:30:00.000Z",
"estimated_time": "60-120 seconds"
}
ステップ 2: 結果をポーリングする
動画生成は画像生成よりも時間がかかります。/jobs/{job_id} を 5 秒ごとにポーリングして進捗を確認してください。
Webhook が利用できます!Webhook を設定すると、ジョブ完了時に通知を受け取れます。詳しくは Webhooks ガイド をご覧ください。
// 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}`);
curl -X GET https://api.krea.ai/jobs/YOUR_JOB_ID \
-H "Authorization: Bearer YOUR_API_TOKEN"
import time
def wait_for_video(job_id):
while True:
response = requests.get(
f"{API_BASE}/jobs/{job_id}",
headers={"Authorization": f"Bearer {API_TOKEN}"}
)
job = response.json()
if job["status"] == "completed":
return job["result"]["urls"][0]
if job["status"] in ("failed", "cancelled"):
raise Exception(f"Job failed: {job['status']}")
# Show progress if available
if "progress" in job:
print(f"Progress: {job['progress']}%")
else:
print(f"Status: {job['status']}")
time.sleep(5)
video_url = wait_for_video(job["job_id"])
print(f"Video ready: {video_url}")
func waitForVideo(jobID string) (string, error) {
for {
req, _ := http.NewRequest("GET", apiBase+"/jobs/"+jobID, nil)
req.Header.Set("Authorization", "Bearer "+apiToken)
resp, _ := client.Do(req)
var job map[string]interface{}
json.NewDecoder(resp.Body).Decode(&job)
resp.Body.Close()
switch job["status"] {
case "completed":
result := job["result"].(map[string]interface{})
urls := result["urls"].([]interface{})
return urls[0].(string), nil
case "failed", "cancelled":
return "", fmt.Errorf("job failed: %s", job["status"])
}
// Show progress if available
if progress, ok := job["progress"]; ok {
fmt.Printf("Progress: %.0f%%\n", progress)
} else {
fmt.Printf("Status: %s\n", job["status"])
}
time.Sleep(5 * time.Second)
}
}
{
"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 ガイド をご覧ください。
共通パラメータ
すべてのモデルの詳細なパラメータリストは、Model APIs ページを参照してください。
| パラメータ | 型 | 説明 |
|---|---|---|
prompt | string | 動画内容の詳細な説明 |
duration | number | 秒単位の動画の長さ。対応値はモデルによって異なります。 |
aspect_ratio | string | 16:9、9:16、1:1 などの動画のアスペクト比 |
start_image | string | 画像から動画のモデル用のオプションのソース画像 URL |
end_image | string | 対応モデル用のオプションの終了フレーム URL |
mode | string | 対応モデル用のオプションの品質モード |
model | string | 使用する動画生成モデル |
より良い動画のためのプロンプトのヒント:
- モーションやカメラの動きを具体的に指定する
- シーン、ライティング、雰囲気を描写する
- タイミングを盛り込む(例: 「ゆっくりパン」「素早くズーム」)
- スタイルリファレンスを含める(例: 「映画的」「ドキュメンタリースタイル」)
動画生成は画像生成よりもコストがかかります。モデル別の料金や API 残高のチャージ方法については、API Keys & Billing をご覧ください。