Azure Video Generation

Azure Video Generation

LiteLLM은 완전한 end-to-end 통합으로 Sora를 포함한 Azure OpenAI의 비디오 생성 모델을 지원해요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 Sora-2를 포함한 Azure OpenAI의 비디오 생성 모델
LiteLLM 라우트 azure/
지원 모델 sora-2
비용 추적 ✅ 시간 기반 가격 ($0.10/초)
로깅 지원 ✅ 전체 요청/응답 로깅
가드레일 지원 ✅ 콘텐츠 심사 및 안전 검사
Proxy 지원 ✅ 가상 키가 포함된 전체 proxy 통합
지출 관리 ✅ 예산 추적 및 rate limiting
공급자 문서 Azure OpenAI Video Generation

빠른 시작 (Quick Start)

필수 API 키

import os

os.environ["AZURE_OPENAI_API_KEY"] = "your-azure-api-key"
os.environ["AZURE_OPENAI_API_BASE"] = "https://your-resource.openai.azure.com/"

기본 사용법

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

os.environ["AZURE_OPENAI_API_KEY"] = "your-azure-api-key"
os.environ["AZURE_OPENAI_API_BASE"] = "https://your-resource.openai.azure.com/"

# Generate video
response = video_generation(
    model="azure/sora-2",
    prompt="A cat playing with a ball of yarn in a sunny garden",
    seconds="8",
    size="720x1280",
)
print(f"Video ID: {response.id}")
print(f"Initial Status: {response.status}")

# Check status until video is ready
while True:
    status_response = video_status(
        video_id=response.id
    )
    print(f"Current Status: {status_response.status}")
    if status_response.status == "completed":
        break
    elif status_response.status == "failed":
        print("Video generation failed")
        break
    time.sleep(10)  # Wait 10 seconds before checking again

# 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 Server 사용법

1. 환경에 키 저장

export AZURE_OPENAI_API_KEY="your-azure-api-key"
export AZURE_OPENAI_API_BASE="https://your-resource.openai.azure.com/"

2. Proxy 시작

config.yaml:

model_list:
  - model_name: azure-sora-2
    litellm_params:
      model: azure/sora-2
      api_key: os.environ/AZURE_OPENAI_API_KEY
      api_base: os.environ/AZURE_OPENAI_API_BASE

CLI:

$ litellm --model azure/sora-2
# Server running on http://0.0.0.0:4000

3. 테스트

curl:

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

OpenAI Python SDK:

import openai

client = openai.OpenAI(
    api_key="anything",
    base_url="http://0.0.0.0:4000"
)

# request sent to model set on litellm proxy, `litellm --model`
response = client.videos.create(
    model="azure-sora-2",
    prompt="A cat playing with a ball of yarn in a sunny garden",
    seconds=8,
    size="720x1280",
)
print(response)

지원 모델 (Supported Models)

모델 이름
sora-2
sora-2-pro
sora-2-pro-high-res

로깅 & 관측성 (Logging & Observability)

요청/응답 로깅

모든 비디오 생성 요청은 자동으로 로깅돼요:

  • 요청 세부 정보: prompt, model, duration, size
  • 응답 세부 정보: video ID, status, creation time
  • 비용 추적: 시간 기반 가격 계산
  • 성능 지표: request latency, processing time

로깅 공급자

비디오 생성은 모든 LiteLLM 로깅 공급자와 동작해요:

  • Datadog: 실시간 모니터링 및 알림
  • Helicone: 요청 추적 및 디버깅
  • LangSmith: LangChain 통합 및 추적
  • 사용자 지정 webhooks: 자체 엔드포인트로 로그 전송

예시: Datadog 로깅 활성화

general_settings:
  alerting: ["datadog"]
  datadog_api_key: os.environ/DATADOG_API_KEY

비디오 생성 파라미터

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

비디오 콘텐츠 조회 (Video Content Retrieval)

# 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)

완전한 워크플로 (Complete Workflow)

import litellm
import time

def generate_and_download_video(prompt):
    # Step 1: Generate video
    response = litellm.video_generation(
        prompt=prompt,
        model="azure/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_remix(
    video_id="video_456",
    prompt="Make the cat jump higher",
    input_reference=open("path/to/image.jpg", "rb"),  # Reference image as file object
    seconds="8",
)
print(f"Video ID: {response.id}")

에러 처리 (Error Handling)

from litellm.exceptions import BadRequestError, AuthenticationError

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

더 알아보기 (Learn more)