Skip to main content

Azure Video Generation

LiteLLM supports Azure OpenAI's video generation models including Sora with full end-to-end integration.

PropertyDetails
DescriptionAzure OpenAI's video generation models including Sora-2
Provider Route on LiteLLMazure/
Supported Modelssora-2
Cost Trackingโœ… Duration-based pricing ($0.10/second)
Logging Supportโœ… Full request/response logging
Guardrails Supportโœ… Content moderation and safety checks
Proxy Server Supportโœ… Full proxy integration with virtual keys
Spend Managementโœ… Budget tracking and rate limiting
Link to Provider DocAzure OpenAI Video Generation โ†—

Quick Startโ€‹

Required API Keysโ€‹

import os 
os.environ["AZURE_OPENAI_API_KEY"] = "your-azure-api-key"
os.environ["AZURE_OPENAI_API_BASE"] = "https://your-resource.openai.azure.com/"
os.environ["AZURE_OPENAI_API_VERSION"] = "2024-02-15-preview"

Basic Usageโ€‹

from litellm import video_generation, video_status, video_retrieval
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/"
os.environ["AZURE_OPENAI_API_VERSION"] = "2024-02-15-preview"

# 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,
model="azure/sora-2"
)

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_retrieval(
video_id=response.id,
model="azure/sora-2"
)

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

Usage - LiteLLM Proxy Serverโ€‹

Here's how to call Azure video generation models with the LiteLLM Proxy Server

1. Save key in your environmentโ€‹

export AZURE_OPENAI_API_KEY="your-azure-api-key"
export AZURE_OPENAI_API_BASE="https://your-resource.openai.azure.com/"
export AZURE_OPENAI_API_VERSION="2024-02-15-preview"

2. Start the proxyโ€‹

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
api_version: "2024-02-15-preview"

3. Test itโ€‹

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

Supported Modelsโ€‹

Model Name
sora-2
sora-2-pro
sora-2-pro-high-res

Logging & Observabilityโ€‹

Request/Response Loggingโ€‹

All video generation requests are automatically logged with:

  • Request details: prompt, model, duration, size
  • Response details: video ID, status, creation time
  • Cost tracking: duration-based pricing calculation
  • Performance metrics: request latency, processing time

Logging Providersโ€‹

Video generation works with all LiteLLM logging providers:

  • Datadog: Real-time monitoring and alerting
  • Helicone: Request tracing and debugging
  • LangSmith: LangChain integration and tracing
  • Custom webhooks: Send logs to your own endpoints

Example: Enable Datadog logging

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

Video Generation Parametersโ€‹

  • prompt (required): Text description of the desired video
  • model (optional): Model to use, defaults to "azure/sora-2"
  • seconds (optional): Video duration in seconds (e.g., "8", "16")
  • size (optional): Video dimensions (e.g., "720x1280", "1280x720")
  • input_reference (optional): Reference image for video editing
  • user (optional): User identifier for tracking

Video Content Retrievalโ€‹

# Download video content
video_bytes = video_retrieval(
video_id="video_1234567890",
model="azure/sora-2"
)

# 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_retrieval(
video_id=video_id,
model="azure/sora-2"
)

# 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 Remix (Video Editing)โ€‹

# Video editing with reference image
response = litellm.video_remix(
prompt="Make the cat jump higher",
input_reference=open("path/to/image.jpg", "rb"), # Reference image as file object
model="azure/sora-2",
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}")