#Pls code sora 2

1 messages · Page 1 of 1 (latest)

uncut vaultBOT
#

Hi @limpid wyvern. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Certainly! Here’s example code for generating a video using the Sora 2 model via the OpenAI API. This code uses Python and the official OpenAI SDK. You need to provide your API key and set your prompt and parameters as desired.

from openai import OpenAI

openai = OpenAI()

video = openai.videos.create(
    model="sora-2",
    prompt="A video of a cool cat on a motorcycle in the night",
)

print("Video generation started:", video)

progress = getattr(video, "progress", 0)
bar_length = 30

while video.status in ("in_progress", "queued"):
    # Refresh status
    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"

    print(f"\r{status_text}: [{bar}] {progress:.1f}%", end="")
    import time; time.sleep(2)

print()  # Move to next line after progress loop

if video.status == "failed":
    message = getattr(
        getattr(video, "error", None), "message", "Video generation failed"
    )
    print(message)
else:
    print("Video generation completed:", video)
    print("Downloading video content...")

    content = openai.videos.download_content(video.id, variant="video")
    content.write_to_file("video.mp4")

    print("Wrote video.mp4")

This script:

  • Starts a video generation job with Sora 2.
  • Polls for progress.
  • Downloads the resulting MP4 when complete.

You can also use curl:

#
curl -X POST "<https://api.openai.com/v1/videos"> \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F prompt="Wide tracking shot of a teal coupe driving through a desert highway, heat ripples visible, hard sun overhead." \
  -F model="sora-2" \
  -F size="1280x720" \
  -F seconds="8"

Replace the prompt and parameters as needed. After the job completes, download the video using the returned video ID.

For more details, see the official documentation: Video generation with Sora and API reference
Sources: Video generation with Sora, Retrieve results

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@limpid wyvern Kapa.ai is still learning and improving, please let me know how I did by reacting below.