Text to video
Make a clip from words alone, and save it.
- Write the prompt: what is seen, what moves, where, how it is filmed.
- Run the job: send it, ask until it ends, save the clip.
- Read how it ended.
- Read what it cost.
1. Write the prompt
A video model reads the prompt as a shot list. Name each of these, and the clip comes back closer to what you had in mind.
| Part | Says | Example |
|---|---|---|
| Subject | who or what is in the frame | a baker in Tlemcen |
| Action | what moves | lifts a tray of makrout from a wood oven |
| Setting | the place, the hour, the light | warm morning light |
| Camera | the shot and its movement | close-up, slow push-in |
| Style | the look | documentary, natural colour |
Send a bakery. The model fills every gap on its own, and each run fills them differently.
Send A baker in Tlemcen lifts a tray of makrout from a wood oven, close-up, warm morning light, slow push-in.
2. Run the job
A clip takes minutes to make, so POST /v1/videos answers at once with a job, not the clip. The code below sends the job, asks every ten seconds until it ends, then saves the clip as makrout.mp4 or prints why there is none.
The model is alibaba/wan-3.0, asked for 6 seconds at 720p in 9:16 with sound: a phone story. Another model takes other values: Choose a video model.
import json
import os
import time
import urllib.request
API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/videos"
MODEL = "alibaba/wan-3.0"
PROMPT = (
"A baker in Tlemcen lifts a tray of makrout from a wood oven, "
"close-up, warm morning light, slow push-in"
)
def call(url, body=None):
request = urllib.request.Request(
url,
data=json.dumps(body).encode() if body else None,
headers={
"Authorization": "Bearer " + API_KEY,
"Content-Type": "application/json",
},
)
return urllib.request.urlopen(request)
with call(
ADDRESS,
{
"model": MODEL,
"prompt": PROMPT,
"duration": 6,
"resolution": "720p",
"aspect_ratio": "9:16",
"generate_audio": True,
},
) as response:
job = json.load(response)
while job["status"] in ("pending", "in_progress"):
time.sleep(10)
with call(ADDRESS + "/" + job["id"]) as response:
job = json.load(response)
if job["status"] == "completed":
print("charged", job["usage"]["cost"], "DA")
clip_address = ADDRESS + "/" + job["id"] + "/content?index=0"
with call(clip_address) as response:
with open("makrout.mp4", "wb") as clip:
clip.write(response.read())
else:
print(job["status"], job.get("error"))| You send | Holds |
|---|---|
model | a video model's ID |
prompt | the words from step 1 |
duration | the seconds of video, a whole number the model lists |
resolution | the size, as the model offers |
aspect_ratio | the frame's shape, as the model offers |
generate_audio | true for a clip with sound, on a model that makes it |
The clip's address is not a public link: call it with your API keyAPI keyThe key you create and send with every request that calls a model.More on API keys →, as the code does. Asking and fetching are free, however often. Each route in full: Clip status · Clip download.
Asking every ten seconds is one way to wait. A callback_url gets the job's end posted to your server instead: Video webhooks.
3. Read how it ended
pending and in_progress mean the job is still running. The other four are the end, and the job never moves again.
| Status | You get |
|---|---|
completed | the clip, at /v1/videos/{id}/content?index=0, and the charge in usage.cost |
failed | no clip; error holds the provider's reason |
cancelled | no clip: the job was cancelled |
expired | no clip: the job lapsed before a clip was made |
On failed, read error, change what it names, and send the job again: the failed one charged nothing.
4. Read what it cost
The clip is charged in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges → from your balanceBalanceWhat you can spend, in DA.More on Balance and charges → once, when the job reports completed: its seconds, at the rate of the variant the request picked, its resolution and, on some models, generate_audio. The completed answer's usage.cost carries the charge, the number the code prints.
Sending the job holds its most from that moment, and the charge is taken when the clip is delivered. A job that ends failed, cancelled or expired charges nothing and gives the hold back. The model's rate per second is on its page in Models. How a charge leaves your balance: Balance and charges.
Last modified on