Turn a roleplay debrief into an avatar feedback clip in Python
Take the written debrief from a roleplay or survey session and render it as a 16:9 Sume avatar clip with a retry-safe key, a 12 to 168 word check and polling.
To turn a written roleplay debrief into a spoken avatar clip on Sume, POST the text as script to /v1/avatar-1.0/talking-video with a saved avatar handle, then poll the status URL from the response until data.sume_status is completed. The sample below does that for a debrief that estimates between 4 and 60 seconds, using an idempotency key so a retry does not bill twice.
Where the debrief comes from is up to you. A live roleplay product such as Synthesia's Sessions, launched October 1, 2026, produces its own analysis in its own interface; this post assumes you have already copied the text into your system.
The code
It needs SUME_API_KEY and a ready avatar handle. The word check uses the docs' 2.8 words per second estimate, so 12 to 168 words is roughly 4 to 60 seconds.
| Item | Value |
|---|---|
| Endpoint | POST /v1/avatar-1.0/talking-video |
| Retry safety | Idempotency-Key header |
| Terminal statuses | completed, failed, canceled |
| Duration window | 4 to 60 seconds |
| Standard rate | $0.184 a second, no product image |
import os, time, requests
from urllib.parse import urljoin
BASE = "https://api.sume.com"
H = {"Authorization": "Bearer " + os.environ["SUME_API_KEY"]}
def feedback_clip(handle, debrief, key):
n = len(debrief.split())
if not 12 <= n <= 168:
raise ValueError(f"{n} words: outside the 4-60 s window")
body = {"avatar_handle": handle, "script": debrief,
"quality": "standard", "aspect_ratio": "16:9"}
r = requests.post(BASE + "/v1/avatar-1.0/talking-video",
headers={**H, "Idempotency-Key": key},
json=body, timeout=30)
r.raise_for_status()
d = r.json()["data"]
while True:
s = requests.get(urljoin(BASE, d["status_url"]), headers=H, timeout=30)
status = s.json()["data"]["sume_status"]
if status == "completed":
break
if status in ("failed", "canceled"):
raise RuntimeError(status)
time.sleep(5)
res = requests.get(urljoin(BASE, d["result_url"]), headers=H, timeout=30)
return res.json()
if __name__ == "__main__":
text = "You opened well and named the budget concern early. " * 3
print(feedback_clip("my_avatar", text, "debrief-2026-10-08-001"))Before you run it
Create the avatar first and wait until it is ready; the avatar docs describe creation as its own job with the $0.95 charge, and GET /v1/avatar-1.0/avatars lists the handles you can use. The script above uses my_avatar as a placeholder, so replace it with a real handle.
The loop polls every 5 seconds with no timeout, which is fine for a sketch. In production, add a deadline and log the status URL so a stuck job can be found later.
Notes on the sample
The key should be unique per debrief: reuse it only to retry the same request. The result is printed as returned; the avatar docs say completed results can include public media.sume.com video artifacts, so read the video URL from that JSON rather than assuming a field name.
At 100 words (about 36 seconds) a Standard clip is about $6.57. A 168-word debrief hits the 60-second ceiling and costs about $11.04; anything longer needs splitting, which the planner post shows.
Sources
Related posts
More in Developers
- 12 Wan 3.0 clips in parallel in Python: ThreadPoolExecutor, width 4
A Python batch for Sume: ThreadPoolExecutor at width 4 (Pro concurrency), one Idempotency-Key per item, polling by next_poll_after_seconds. Cost included.
- Vercel 800 s max duration: do you still need a Sume webhook?
Vercel Pro allows 800 s functions and a 30-minute beta. A Sume video job can still outlast one request, so use async or webhook mode and return in seconds.
- Verify x-sume-webhook-signature in Node: sume-v1 HMAC, raw body
A node:crypto verifier for Sume's sume-v1 signature that refuses an empty secret, checks the 5-minute window, and accepts either entry during a rotation.
- Video upscale hold: omit duration_seconds and Sume reserves 5 s
Sume video upscale reserves from duration_seconds, or 5 seconds when you omit it. Hold table for 5, 15 and 30 seconds at $0.009 per second and the 402 case.
Written by Sume