Created
June 4, 2025 10:58
-
-
Save AlexanderHolmeset/eb25ca9d300ae6658cfae937d0d4610b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set environment variables or edit the corresponding values here. | |
$endpoint = "XXXXXXXXXXXXXXXXX" | |
$api_key = "XXXXXXXXXXXXXXXXX" | |
$api_version = 'preview' | |
$headers = @{ | |
"api-key" = $api_key | |
"Content-Type" = "application/json" | |
} | |
# 1. Create a video generation job | |
# Videoresolutions to choose from: 480x480, 480x854, 854x480, 720x720, 720x1280, 1280x720, 1080x1080, 1080x1920, 1920x1080. | |
$create_url = "$endpoint/openai/v1/video/generations/jobs?api-version=$api_version" | |
$body = @" | |
{ | |
"prompt": "Detailed close up view of a astronauts eyes framed by a knitted fabric mask", | |
"width": 1920, | |
"height": 1080, | |
"n_seconds": 15, | |
"model": "sora" | |
} | |
"@ | |
$response = Invoke-RestMethod -Uri $create_url -Method Post -Headers $headers -Body $body -ContentType "application/json" | |
# 2. Poll for job status | |
$status_url = "$endpoint/openai/v1/video/generations/jobs/$($response.id)?api-version=$api_version" | |
$status_reponse = Invoke-RestMethod -Uri $status_url -Method Get -Headers $headers -ContentType "application/json" | |
while ($status_reponse.status -ne "succeeded" -and $status_reponse.status -ne "failed" -and $status_reponse.status -ne "cancelled") { | |
Start-Sleep -Seconds 5 # Wait before polling again | |
$status_reponse = Invoke-RestMethod -Uri $status_url -Method Get -Headers $headers -ContentType "application/json" | |
Write-Host "Job status: $($status_reponse.status)" | |
} | |
# 3. Download the generated video | |
$video_url = "$endpoint/openai/v1/video/generations/$($status_reponse.generations.id)/content/video?api-version=$api_version" | |
Invoke-RestMethod -Uri $video_url -Method Get -Headers $headers -OutFile "output.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment