Trim 12 Shorts from one recording with asyncio and a semaphore
Cut 12 Shorts from one recording with asyncio and httpx: 12 trims at $0.02 is $0.24. A semaphore of 4 caps in-flight requests; the limit is your choice.

A 12-clip batch from one recording is 12 independent trim jobs at $0.02 each, $0.24 in total, and they can run together. Use asyncio.run(main()) with an httpx.AsyncClient and a semaphore so only a few requests are in flight; the 4 below is a polite choice and not an API limit.
YouTube defines Shorts as vertical videos up to 3 minutes (read 2026-10-09), so each range is well inside the 900 s trim output cap.
Cost and limits
| Item | Value |
|---|---|
| Trim jobs | 12 |
| Rate per job | $0.02 |
| Total | $0.24 |
| Source recording | up to 1800 s |
| Each output | 0.2 s to 900 s |
Code
Each range gets its own Idempotency-Key, so rerunning the script re-reads the same jobs instead of billing again.
import asyncio, os, httpx
API = "https://api.sume.com"
H = {"Authorization": f"Bearer {os.environ['SUME_API_KEY']}"}
SRC = "https://media.sume.com/artifacts/artf_demo/long.mp4"
async def cut(c, sem, i, start, end):
async with sem:
r = await c.post(f"{API}/v1/video-trim", headers={
**H, "Idempotency-Key": f"shorts-{i}-{start}-{end}"},
json={"video_url": SRC, "start": start, "end": end})
r.raise_for_status()
return r.json()["data"]["request_id"]
async def main(ranges):
sem = asyncio.Semaphore(4)
async with httpx.AsyncClient(timeout=60) as c:
return await asyncio.gather(
*(cut(c, sem, i, s, e) for i, (s, e) in enumerate(ranges)))
jobs = asyncio.run(main([(i * 60, i * 60 + 45) for i in range(12)]))Then what
- The submit returns a job; poll
GET /v1/jobs/:id/statusforsume_status, then readGET /v1/jobs/:id/resultforvideo_url. - A 429 or 5xx should retry with the same key, never a new one.
- A source over 1800 s fails with
source_duration_exceeded; split it first. - The ranges here are placeholders; take real ones from your transcript.
Sources
Related posts
More in Developers
- TTS 1.0 rejects a model field: use the TTS router to pick sonic-3.6
Sume TTS 1.0 does not accept model. To choose an engine such as sonic-3.6 use /v1/tts-router/generate. Price is the same $0.0475 per 1,000 characters.
- Sume TTS pace test: 1,000 characters a minute decides the cap
Sume TTS stops at 20,000 characters or 1,200 seconds. The break-even is 1,000 characters a minute; measure your voice before a long read. Max $0.95 a job.
- Sume TTS speed 0.6 to 1.5: a 14-minute script and the 1,200 s cap
generation_config.speed runs 0.6 to 1.5. A 14-minute read slowed to 0.6 would need about 23 minutes and hit the 1,200-second cap; the price stays per character.
- Sume TTS: 20,000 characters or 1,200 seconds, which fails first?
At 15 characters a second, 20,000 characters is 1,333 seconds, so the 1,200-second audio cap trips first. Split near 15,000 characters per job.
Written by Sume