Get started quickly with Sora 2 Video Generation Sync API
Looking for a more stable solution?This page introduces the Sync API (suitable for quick testing). For a more stable production environment solution, we recommend using the Async API.
About @sama in ExamplesYou may notice @sama used in examples. This is OpenAI CEO Sam Altman’s authorized ID, allowing his likeness to appear in videos.This is optional:
✓ Can use @sama or other verified IDs
✓ Can skip it and use normal scene descriptions (e.g., “a cat in a garden”)
✗ Cannot upload real person photos (will be rejected and charged)
Want yourself in the video? Requires Cameo certification in Sora iOS app. See FAQ
The simplest usage method - generate videos using only text descriptions.
Copy
curl -X POST "https://api.laozhang.ai/v1/chat/completions" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "sora_video2", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "A happy cat playing with a ball in a sunny garden" } ] } ] }'
Enable streaming output to view generation progress in real-time.
Copy
import openaiimport reclient = openai.OpenAI( api_key="YOUR_API_KEY", base_url="https://api.laozhang.ai/v1")stream = client.chat.completions.create( model="sora_video2", messages=[ { "role": "user", "content": [ { "type": "text", "text": "A cute cat playing with a ball in a sunny garden" } ] } ], stream=True)# Store full content to extract video linkfull_content = ""print("Generation progress:\n")for chunk in stream: if chunk.choices[0].delta.content: content = chunk.choices[0].delta.content print(content, end='', flush=True) full_content += contentprint("\n")# Extract video linkvideo_url_match = re.search(r'https://[^\s\)]+\.mp4', full_content)if video_url_match: video_url = video_url_match.group(0) print(f"\n✅ Video link: {video_url}") print("⚠️ Video valid for 1 day, download immediately!")else: print("\n❌ Video link not found, generation may have failed")
When "stream": true is enabled, API returns SSE (Server-Sent Events) format:
Copy
data: {"id":"foaicmpl-xxx","object":"chat.completion.chunk","created":1759759480,"model":"sora_video2","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}data: {"id":"foaicmpl-xxx","object":"chat.completion.chunk","created":1759759480,"model":"sora_video2","choices":[{"index":0,"delta":{"content":"```json\n{\n \"prompt\": \"A happy cat playing with a ball in a sunny garden\",\n \"mode\": \"Vertical Mode\"\n}\n```\n\n"},"finish_reason":null}]}data: {"id":"foaicmpl-xxx","object":"chat.completion.chunk","created":1759759480,"model":"sora_video2","choices":[{"index":0,"delta":{"content":"> ⌛️ Task is in queue, please wait patiently...\n\n"},"finish_reason":null}]}data: {"id":"foaicmpl-xxx","object":"chat.completion.chunk","created":1759759480,"model":"sora_video2","choices":[{"index":0,"delta":{"content":"> 🏃 Progress: 36.0%\n\n"},"finish_reason":null}]}data: {"id":"foaicmpl-xxx","object":"chat.completion.chunk","created":1759759480,"model":"sora_video2","choices":[{"index":0,"delta":{"content":"> ✅ Video generated successfully, [Click here](https://sora.gptkey.asia/assets/sora/xxx.mp4) to view video~~~\n\n"},"finish_reason":null}]}data: {"id":"foaicmpl-xxx","object":"chat.completion.chunk","created":1759759480,"model":"sora_video2","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":17,"completion_tokens":244,"total_tokens":261}}data: [DONE]
Remember to download videos immediately!Generated video URLs are valid for only 1 day. Please download to local storage after generation to avoid losing videos.
Model Selection
sora_video2: Vertical screen (704×1280), suitable for mobile viewing
sora_video2-landscape: Horizontal screen (1280×704), suitable for widescreen displays