OpenAI 비디오 생성

OpenAI 비디오 생성 (Video Generation)

LiteLLM에서 OpenAI의 비디오 생성 모델(Sora 포함)을 사용하는 방법을 알아봐요.

출처: 문서

본문

LiteLLM은 Sora를 포함한 OpenAI의 비디오 생성 모델을 지원해요.

빠른 시작

필요 API 키

import os
os.environ["OPENAI_API_KEY"] = "your-api-key"

기본 사용법

from litellm import video_generation, video_content
import os

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

# Generate a video
response = video_generation(
    prompt="A cat playing with a ball of yarn in a sunny garden",
    model="sora-2",
    seconds="8",
    size="720x1280"
)

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

# Download video content when ready
video_bytes = video_content(
    video_id=response.id,
)

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

LiteLLM Proxy 사용법

LiteLLM은 완전한 비디오 생성 워크플로를 위한 OpenAI API 호환 비디오 엔드포인트를 제공해요:

  • /videos/generations - 새 비디오 생성
  • /videos/remix - 참조 이미지로 기존 비디오 편집
  • /videos/status - 비디오 생성 상태 확인
  • /videos/retrieval - 완성된 비디오 다운로드

설정 — litellm proxy config.yaml에 추가:

model_list:
  - model_name: sora-2
    litellm_params:
      model: openai/sora-2
      api_key: os.environ/OPENAI_API_KEY

litellm 시작:

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

# RUNNING on http://0.0.0.0:4000

비디오 생성 요청 테스트:

curl --location 'http://localhost:4000/v1/videos' \
--header 'Content-Type: application/json' \
--header 'x-litellm-api-key: *** ' \
--data '{
    "model": "sora-2",
    "prompt": "A beautiful sunset over the ocean"
}'

비디오 상태 요청 테스트:

# Using custom-llm-provider header
curl --location 'http://localhost:4000/v1/videos/video_id' \
--header 'Accept: application/json' \
--header 'x-litellm-api-key: *** ' \
--header 'custom-llm-provider: openai'

비디오 검색 요청 테스트:

# Using custom-llm-provider header
curl --location 'http://localhost:4000/v1/videos/video_id/content' \
--header 'Accept: application/json' \
--header 'x-litellm-api-key: *** ' \
--header 'custom-llm-provider: openai' \
--output video.mp4

# Or using query parameter
curl --location 'http://localhost:4000/v1/videos/video_id/content?custom_llm_provider=openai' \
--header 'Accept: application/json' \
--header 'x-litellm-api-key: *** ' \
--output video.mp4

비디오 리믹스 요청 테스트:

# Using custom_llm_provider in request body
curl --location --request POST 'http://localhost:4000/v1/videos/video_id/remix' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'x-litellm-api-key: *** ' \
--data '{
    "prompt": "New remix instructions",
    "custom_llm_provider": "openai"
}'

# Or using custom-llm-provider header
curl --location --request POST 'http://localhost:4000/v1/videos/video_id/remix' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'x-litellm-api-key: *** ' \
--header 'custom-llm-provider: openai' \
--data '{
    "prompt": "New remix instructions"
}'

캐릭터, 편집, 확장 라우트

LiteLLM proxy가 지원하는 OpenAI 비디오 라우트:

  • POST /v1/videos/characters
  • GET /v1/videos/characters/{character_id}
  • POST /v1/videos/edits
  • POST /v1/videos/extensions

캐릭터 생성의 target_model_names 지원

POST /v1/videos/characters는 모델 기반 라우팅을 위한 target_model_names를 지원해요(비디오 생성과 동일한 동작).

curl --location 'http://localhost:4000/v1/videos/characters' \
--header "Authorization: Bearer ***" \
-F 'name=hero' \
-F 'target_model_names=gpt-5.6-terra' \
-F 'video=@/path/to/character.mp4'

target_model_names를 사용하면 LiteLLM이 인코딩된 캐릭터 ID를 반환해요:

{
  "id": "character_...",
  "object": "character",
  "created_at": 1712697600,
  "name": "hero"
}

해당 인코딩된 ID를 get에 직접 사용:

curl --location 'http://localhost:4000/v1/videos/characters/character_...' \
--header "Authorization: Bearer ***"

edit/extension용 인코딩 및 비-인코딩 비디오 ID

두 라우트 모두 일반 또는 인코딩된 video.id를 허용해요:

curl --location 'http://localhost:4000/v1/videos/edits' \
--header "Authorization: Bearer ***" \
--header 'Content-Type: application/json' \
--data '{
  "prompt": "Make this brighter",
  "video": { "id": "video_..." }
}'
curl --location 'http://localhost:4000/v1/videos/extensions' \
--header "Authorization: Bearer ***" \
--header 'Content-Type: application/json' \
--data '{
  "prompt": "Continue this scene",
  "seconds": "4",
  "video": { "id": "video_..." }
}'

custom_llm_provider 입력 소스

이 라우트들에서 custom_llm_provider는 다음을 통해 제공될 수 있어요:

  • 헤더: custom-llm-provider
  • 쿼리: ?custom_llm_provider=...
  • body: custom_llm_provider (지원되는 곳 extra_body.custom_llm_provider)

OpenAI 비디오 생성 요청 테스트:

curl http://localhost:4000/v1/videos \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sora-2",
    "prompt": "A cat playing with a ball of yarn in a sunny garden",
    "seconds": "8",
    "size": "720x1280"
  }'

지원 모델

모델명 설명 최대 길이 지원 크기
sora-2 OpenAI의 최신 비디오 생성 모델 8초 720x1280, 1280x720

비디오 생성 파라미터

  • prompt (필수): 원하는 비디오의 텍스트 설명
  • model (선택): 사용할 모델, 기본값 "sora-2"
  • seconds (선택): 비디오 길이(초) (예: "8", "16")
  • size (선택): 비디오 크기 (예: "720x1280", "1280x720")
  • input_reference (선택): 비디오 편집용 참조 이미지
  • user (선택): 추적용 사용자 식별자

비디오 콘텐츠 검색

# Download video content
video_bytes = video_content(
    video_id="video_1234567890"
)

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

완전한 워크플로

import litellm
import time

def generate_and_download_video(prompt):
    # Step 1: Generate video
    response = litellm.video_generation(
        prompt=prompt,
        model="sora-2",
        seconds="8",
        size="720x1280"
    )

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

    # Step 2: Wait for processing (in practice, poll status)
    time.sleep(30)

    # Step 3: Download video
    video_bytes = litellm.video_content(
        video_id=video_id
    )

    # Step 4: Save to file
    with open(f"video_{video_id}.mp4", "wb") as f:
        f.write(video_bytes)

    return f"video_{video_id}.mp4"

# Usage
video_file = generate_and_download_video(
    "A cat playing with a ball of yarn in a sunny garden"
)

참조 이미지로 비디오 편집

# Video editing with reference image
response = litellm.video_generation(
    prompt="Make the cat jump higher",
    input_reference=open("path/to/image.jpg", "rb"),  # Reference image
    model="sora-2",
    seconds="8"
)

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

오류 처리

from litellm.exceptions import BadRequestError, AuthenticationError

try:
    response = video_generation(
        prompt="A cat playing with a ball of yarn"
    )
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except BadRequestError as e:
    print(f"Bad request: {e}")

더 알아보기 (Learn more)

  • OpenAI 비디오 생성 API
  • LiteLLM 비디오 생성 기능