RunwayML - 비디오 생성

RunwayML - 비디오 생성 (Video Generation)

RunwayML의 Gen-4 비디오 생성 기능을 LiteLLM에서 사용하는 방법을 알아봐요. 텍스트 프롬프트와 이미지로 비디오를 생성할 수 있어요.

출처: 문서

본문

LiteLLM은 RunwayML의 Gen-4 비디오 생성 API를 지원해서, 텍스트 프롬프트와 이미지로 비디오를 생성할 수 있어요.

빠른 시작

from litellm import video_generation
import os

os.environ["RUNWAYML_API_KEY"] = "your-api-key"

# Generate video from text and image
response = video_generation(
    model="runwayml/gen4_turbo",
    prompt="A high quality demo video of litellm ai gateway",
    input_reference="https://media.licdn.com/dms/image/v2/D4D0BAQFqOrIAJEgtLw/company-logo_200_200/company-logo_200_200/0/1714076049190/berri_ai_logo?e=2147483647&v=beta&t=7tG_KRZZ4MPGc7Iin79PcFcrpvf5Hu6rBM4ptHGU1DY",
    seconds=5,
    size="1280x720"
)

print(f"Video ID: {response.id}")
print(f"Status: {response.status}")

인증

RunwayML API 키를 설정해요:

import os

os.environ["RUNWAYML_API_KEY"] = "your-api-key"

지원 파라미터

파라미터 타입 필수 설명
model string 사용할 모델 (예: runwayml/gen4_turbo)
prompt string 비디오에 대한 텍스트 설명
input_reference string/file 참조 이미지의 URL 또는 파일 경로
seconds int 아니오 비디오 길이 (5 또는 10초)
size string 아니오 비디오 크기 (1280x720 또는 720x1280). ratio 형식(1280:720)도 사용 가능

완전한 워크플로

from litellm import video_generation, video_status, video_content
import os
import time

os.environ["RUNWAYML_API_KEY"] = "your-api-key"

# 1. Generate video
response = video_generation(
    model="runwayml/gen4_turbo",
    prompt="A high quality demo video of litellm ai gateway",
    input_reference="https://media.licdn.com/dms/image/v2/D4D0BAQFqOrIAJEgtLw/company-logo_200_200/company-logo_200_200/0/1714076049190/berri_ai_logo?e=2147483647&v=beta&t=7tG_KRZZ4MPGc7Iin79PcFcrpvf5Hu6rBM4ptHGU1DY",
    seconds=5,
    size="1280x720"
)

video_id = response.id
print(f"Video generation started: {video_id}")

# 2. Check status until completed
while True:
    status_response = video_status(video_id=video_id)
    print(f"Status: {status_response.status}")

    if status_response.status == "completed":
        print("Video generation completed!")
        break
    elif status_response.status == "failed":
        print("Video generation failed")
        break

    time.sleep(10)  # Wait 10 seconds before checking again

# 3. Download video content
video_bytes = video_content(video_id=video_id)

# 4. Save to file
with open("generated_video.mp4", "wb") as f:
    f.write(video_bytes)

print("Video saved successfully!")

비동기 사용법

from litellm import avideo_generation, avideo_status, avideo_content
import os
import asyncio

os.environ["RUNWAYML_API_KEY"] = "your-api-key"

async def generate_video():
    # Generate video
    response = await avideo_generation(
        model="runwayml/gen4_turbo",
        prompt="A serene lake with mountains in the background",
        input_reference="https://example.com/lake.jpg",
        seconds=5,
        size="1280x720"
    )

    video_id = response.id
    print(f"Video generation started: {video_id}")

    # Poll for completion
    while True:
        status_response = await avideo_status(video_id=video_id)
        print(f"Status: {status_response.status}")

        if status_response.status == "completed":
            break
        elif status_response.status == "failed":
            print("Video generation failed")
            return

        await asyncio.sleep(10)

    # Download video
    video_bytes = await avideo_content(video_id=video_id)

    # Save to file
    with open("generated_video.mp4", "wb") as f:
        f.write(video_bytes)

    print("Video saved successfully!")

asyncio.run(generate_video())

LiteLLM Proxy 사용법

config.yaml:

model_list:
  - model_name: gen4-turbo
    litellm_params:
      model: runwayml/gen4_turbo
      api_key: os.environ/RUNWAYML_API_KEY

Proxy 시작:

litellm --config /path/to/config.yaml

Proxy를 통해 비디오 생성:

curl --location 'http://localhost:4000/v1/videos' \
--header 'Content-Type: application/json' \
--header 'x-litellm-api-key: *** ' \
--data '{
    "model": "runwayml/gen4_turbo",
    "prompt": "A high quality demo video of litellm ai gateway",
    "input_reference": "https://media.licdn.com/dms/image/v2/D4D0BAQFqOrIAJEgtLw/company-logo_200_200/company-logo_200_200/0/1714076049190/berri_ai_logo?e=2147483647&v=beta&t=7tG_KRZZ4MPGc7Iin79PcFcrpvf5Hu6rBM4ptHGU1DY",
    "ratio": "1280:720"
}'

비디오 상태 확인:

curl --location 'http://localhost:4000/v1/videos/{video_id}' \
--header 'x-litellm-api-key: ***'

비디오 콘텐츠 다운로드:

curl --location 'http://localhost:4000/v1/videos/{video_id}/content' \
--header 'x-litellm-api-key: *** ' \
--output video.mp4

지원 모델

모델 설명 길이 가로세로 비율
runwayml/gen4_turbo 빠른 비디오 생성 5-10s 1280x720, 720x1280

오류 처리

from litellm import video_generation, video_status
import time

try:
    response = video_generation(
        model="runwayml/gen4_turbo",
        prompt="A scenic mountain view",
        input_reference="https://example.com/mountain.jpg",
        seconds=5
    )

    # Poll for completion
    max_attempts = 60  # 10 minutes max
    attempts = 0

    while attempts = max_attempts:
        print("Video generation timed out")

except Exception as e:
    print(f"Error: {str(e)}")

비용 추적

LiteLLM은 RunwayML 비디오 생성 비용을 자동으로 추적해요:

from litellm import video_generation, completion_cost

response = video_generation(
    model="runwayml/gen4_turbo",
    prompt="A high quality demo video of litellm ai gateway",
    input_reference="https://media.licdn.com/dms/image/v2/D4D0BAQFqOrIAJEgtLw/company-logo_200_200/company-logo_200_200/0/1714076049190/berri_ai_logo?e=2147483647&v=beta&t=7tG_KRZZ4MPGc7Iin79PcFcrpvf5Hu6rBM4ptHGU1DY",
    seconds=5,
    size="1280x720"
)

# Calculate cost
cost = completion_cost(completion_response=response)
print(f"Video generation cost: ${cost}")

API 레퍼런스

완전한 API 세부 사항은 LiteLLM이 따르는 OpenAI 비디오 생성 API 스펙을 참고해요.

지원 기능

기능 지원
Video Generation
Image-to-Video
Status Checking
Content Download
Cost Tracking
Logging
Fallbacks
Load Balancing

더 알아보기 (Learn more)

  • RunwayML API 공식 문서
  • OpenAI 비디오 생성 API