ExamplescriptBeginnerRunnablechat-lab
Sora 2 quickstart: create, track and download a video with the OpenAI API
Create a 4-second, 720x1280 Sora 2 video with videos.create, list your videos, check the job's status and download the result. Runnable Python.
Key Facts
- Level
- Beginner
- Runtime
- Python • OpenAI API
- Pattern
- Single-turn interaction with inspectable output
- Interaction
- Live sandbox • Script
- Code last changed
- 29 October 2025
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
1-sora-quickstart.py
python
import sys
import time
from openai import OpenAI
openai = OpenAI()
# --------------------------------------------------------------
# Create a new video
# --------------------------------------------------------------
# Takes about 2 minutes
video = openai.videos.create(
model="sora-2",
prompt="YouTuber, black t-shirt, in a professional studio setup, sitting at his desk talking directly into a Shure SM7B microphone on a boom arm. He says with a smirk: 'Wait... did an AI just generate me to teach you about AI? That's pretty meta...' Dark background with a soft blue LED light glow. Professional lighting setup with key light and rim light. Shot on Sony FX6, cinematic depth of field, crisp focus, vertical format 9:16.",
size="720x1280",
seconds="4",
)
print("Video generation started:", video)
# --------------------------------------------------------------
# List all videos
# --------------------------------------------------------------
time.sleep(5)
videos_list = openai.videos.list().data
# --------------------------------------------------------------
# Check the last's video status
# --------------------------------------------------------------
video = openai.videos.retrieve(videos_list[0].id)
print("Video status:", video.status)
# --------------------------------------------------------------
# Download video
# --------------------------------------------------------------
progress = getattr(video, "progress", 0)
bar_length = 30
while video.status in ("in_progress", "queued"):
video = openai.videos.retrieve(video.id)
progress = getattr(video, "progress", 0)
filled_length = int((progress / 100) * bar_length)
bar = "=" * filled_length + "-" * (bar_length - filled_length)
status_text = "Queued" if video.status == "queued" else "Processing"
sys.stdout.write(f"\r{status_text}: [{bar}] {progress:.1f}%")
sys.stdout.flush()
time.sleep(2)
sys.stdout.write("\n")
if video.status == "failed":
message = getattr(
getattr(video, "error", None), "message", "Video generation failed"
)
print(message)
sys.exit(1)
print("Video generation completed:", video)
print("Downloading video content...")
content = openai.videos.download_content(video.id, variant="video")
content.write_to_file(f"output/{video.id}.mp4")
print(f"Wrote output/{video.id}.mp4")
Related principles
- P2VisibilityEnsure that background work remains perceptibleWhen the system is operating asynchronously or outside the user’s immediate focus, it should provide persistent and proportionate signals that work is continuing.Open principle →
- P4TrustApply progressive disclosure to system agencyProvide the minimum information necessary by default, while enabling users to inspect additional detail when confidence, understanding, or intervention is required.Open principle →
- P5DelegationReplace implied magic with clear mental modelsThe product should help users understand what the system can do, what it is currently doing, what it cannot do, and what conditions govern its behaviour.Open principle →
- P7TrustEstablish trust through inspectabilityUsers should be able to examine how a result was produced when confidence, accountability, or decision quality is important.Open principle →
- P9OrchestrationRepresent delegated work as a system, not merely as a conversationWhere work involves multiple steps, agents, dependencies, or concurrent activities, it should be represented as a structured system rather than solely as a message stream.Open principle →