Google AI Studio를 이용한 Veo 비디오 생성

Google AI Studio를 이용한 Veo 비디오 생성 (Veo Video Generation with Google AI Studio)

LiteLLM의 pass-through 엔드포인트를 통해 Google의 Veo 모델로 비디오를 생성하는 방법을 안내할게요. 별도 설정 없이 Google AI Studio의 Veo 비디오 생성 API를 바로 사용할 수 있어요.

출처: 문서

본문

LiteLLM의 pass-through 엔드포인트를 통해 Google의 Veo 모델로 비디오를 생성해요.

Quick Start

LiteLLM은 별도 설정 없이 pass-through 라우트를 통해 Google AI Studio의 Veo 비디오 생성 API를 사용할 수 있게 해줘요.

1. 환경에 Google AI Studio API 키 추가하기

export GEMINI_API_KEY="your_google_ai_studio_api_key"

2. LiteLLM 프록시 시작하기

litellm

# RUNNING on http://0.0.0.0:4000

3. 비디오 생성하기

  • Python
  • Curl
import requests
import time
import json

# Configuration
BASE_URL = "http://localhost:4000/gemini/v1beta"
API_KEY = "anything"  # Use "anything" as the key

headers = {
    "x-goog-api-key": API_KEY,
    "Content-Type": "application/json"
}

# Step 1: Initiate video generation
def generate_video(prompt):
    url = f"{BASE_URL}/models/veo-3.0-generate-preview:predictLongRunning"
    payload = {
        "instances": [{
            "prompt": prompt
        }]
    }
    
    response = requests.post(url, headers=headers, json=payload)
    response.raise_for_status()
    
    data = response.json()
    return data.get("name")  # Operation name

# Step 2: Poll for completion
def wait_for_completion(operation_name):
    operation_url = f"{BASE_URL}/{operation_name}"
    
    while True:
        response = requests.get(operation_url, headers=headers)
        response.raise_for_status()
        
        data = response.json()
        
        if data.get("done", False):
            # Extract video URI
            video_uri = data["response"]["generateVideoResponse"]["generatedSamples"][0]["video"]["uri"]
            return video_uri
        
        time.sleep(10)  # Wait 10 seconds before next poll

# Step 3: Download video
def download_video(video_uri, filename="generated_video.mp4"):
    # Replace Google URL with LiteLLM proxy URL
    litellm_url = video_uri.replace(
        "https://generativelanguage.googleapis.com/v1beta", 
        BASE_URL
    )
    
    response = requests.get(litellm_url, headers=headers, stream=True)
    response.raise_for_status()
    
    with open(filename, 'wb') as f:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                f.write(chunk)
    
    return filename

# Complete workflow
prompt = "A cat playing with a ball of yarn in a sunny garden"

print("Generating video...")
operation_name = generate_video(prompt)

print("Waiting for completion...")
video_uri = wait_for_completion(operation_name)

print("Downloading video...")
filename = download_video(video_uri)

print(f"Video saved as: {filename}")
# Step 1: Initiate video generation
curl -X POST "http://localhost:4000/gemini/v1beta/models/veo-3.0-generate-preview:predictLongRunning" \
  -H "x-goog-api-key: *** \
  -H "Content-Type: application/json" \
  -d '{
    "instances": [{
      "prompt": "A cat playing with a ball of yarn in a sunny garden"
    }]
  }'

# Response will include operation name:
# {"name": "operations/generate_12345"}

# Step 2: Poll for completion
curl -X GET "http://localhost:4000/gemini/v1beta/operations/generate_12345" \
  -H "x-goog-api-key: ***

# Step 3: Download video (when done=true)
curl -X GET "http://localhost:4000/gemini/v1beta/files/VIDEO_ID:download?alt=media" \
  -H "x-goog-api-key: *** \
  --output generated_video.mp4

완전한 예시

오류 처리와 로깅이 포함된 완전한 동작 예시는 Veo Video Generation Cookbook을 참고하세요.

동작 방식

  • 비디오 생성 요청: Veo의 predictLongRunning 엔드포인트에 프롬프트를 보내요.
  • 작업 폴링: 완료될 때까지 장기 실행 작업을 모니터링해요.
  • 파일 다운로드: 자동 리다이렉트 처리를 이용해 LiteLLM의 pass-through를 통해 생성된 비디오를 다운로드해요.

LiteLLM이 처리하는 것:

  • ✅ Google AI Studio 인증
  • ✅ 요청 라우팅 및 프록시
  • ✅ 파일 다운로드의 자동 리다이렉트 처리

구성 옵션

환경 변수

export GEMINI_API_KEY="your_google_ai_studio_api_key"

더 알아보기 (Learn more)