- Create the upload. You get one pre-signed URL for each part.
- PUT each part to its URL. Keep the
ETagheader of each answer. - Complete the upload with the list of part numbers and ETags.
- We encode the video. Poll the video until it is
ready, or subscribe to thevideo.readywebhook.
Before you start
- A project ID (
prj_...) and an API key for that project (sk_...). - Base URL:
https://api.segmnt.cloud - Send the key as
Authorization: Bearer <key>on the API calls. Do not send it to the part URLs.
Limits
Small files (under 100 MiB) have one part.
The size limit is checked 3 times: when you create the upload (declared
sizeBytes), when you complete it (real size), and before encoding (real
duration). If the real file is over the limit, the video ends as failed with
failure.code = plan_limit_reached, and the file is removed.
If the real file is not the same size as the sizeBytes you declared (larger or
smaller), the video ends as failed with size_mismatch. No encoding starts.
Step 1: Create the upload
201):
Idempotency-Key is optional but we recommend it. If your request times out,
send it again with the same key and you get the same upload. The header works
with a server API key. With an upload token (browser upload), the header is
ignored. The single-use token protects you instead.
The answer has fresh part URLs, so you can send the parts again after the old
part URLs expire (part URLs work for 4 hours).
Treat the part URLs like secrets. Do not log them.
We do not ask for a phone number or an SMS code to upload. A blocked account
always gets 403 account_banned, and the ban check always applies. See
Phone verification.
Step 2: PUT the parts
Cut the file into pieces ofpartSizeBytes. PUT the raw bytes of piece N to
the URL for partNumber N. Send the part’s exact size as Content-Length: the
part URL signs it, so a different length is refused. Content-Type is not
checked. No auth header is needed.
Read the ETag response header and keep it with the part number.
Browsers can read ETag because our storage exposes it in CORS. See
Browser for what a browser can and cannot do on your own domain.
You can send parts in parallel (4 at a time is a good start) and in any order.
Step 3: Complete
202 with the video, now with status: "processing".
Complete is safe to retry. If the upload is already complete, you get 202 with
the current video.
A complete for a valid upload always answers 202, even when the encoder is
busy. The video waits in one shared queue and shows processing until it is
ready. Complete never fails because the encoder is busy. A complete can answer
429 rate_limited if you send too many requests. Wait the Retry-After
seconds, then send the same request again. Do not cancel and do not upload
again. See Uploading many videos (bulk import).
Step 4: Wait for the result
The video goesprocessing then ready (or failed). Poll
GET /v1/projects/{projectId}/videos/{videoId} until the status changes, or
subscribe to the video.ready webhook. The webhook is live: register your
own HTTPS endpoint and we send the event when a video becomes ready. See
Feature status.
In rare cases our team can hold a video for review (status held). It does not
play until the hold ends. See Moderation and held videos.
Cancel only stops an upload that has not finished. To delete a video you
have already completed, see Manage videos.
Cancel an upload
204. The parts and the video are removed. Calling it again is safe.
If the upload is already complete, you get 409 upload_closed.
Open uploads that are not completed are removed after expiresAt.
Resume an interrupted upload
Status: Available. See Feature status.If the connection drops, the page reloads, or a part link expires, you do not need to start again. Ask for the upload status, send only the parts that are missing, then complete the upload.
- Get the status. Call
GETon the upload. - Check each part. A part with
"uploaded": trueis already in storage. Keep itsetagif the answer has one. A part with"uploaded": falsehas a newurl. Send that part. - PUT the missing parts. Use the new
url. Send the part’ssizeBytesasContent-Length. Keep theETagof each part. - Complete. Send the parts with their ETags. You can also send only the
part numbers, or an empty body (
{}). If an ETag is missing, we read that part from storage.
200), shortened:
urlis only in the answer for a part that is missing, or that was stored at the wrong size. A part that is already stored has nourl.recommendedParallelismis 4. Send at most 4 parts at a time.- Each new
urlworks for up to 4 hours, and never pastexpiresAt. Get the status again if a link expires. - A
completedorfailedupload returns thevideoand an emptypartslist. A completed upload is done: poll the video or wait for the webhook. A failed video has afailure.code. Start a new upload to try again. - An
abortedupload, or an open upload past itsexpiresAt, returns409 upload_closed. Start a new upload. A completed or failed upload keeps returning its video, also afterexpiresAt.
400 invalid_parts, a part is missing or was
stored at the wrong size. The detail names the part when it can. The upload
stays open. Use the detail to fix the part, then complete again.
If the detail says the upload did not arrive correctly, it does not name a
part. Call the status again, PUT each part that has a url, then complete
again. If no part has a url, start a new upload.
Browser upload token. A token can call GET for its own upload. A token
past its expiry still works for its own upload, while the upload is open and
before its expiresAt. After that, the token gets 401 unauthorized. A token
can never create another upload or read another upload.
Rate limit. GET allows 30 calls a minute for each upload ID. A 429
answer has a Retry-After header. Wait that many seconds, then try again.
Uploading many videos (bulk import)
You can move a whole library in one run: hundreds of files, the same 4 steps for each. Three rules keep the run safe. 1. Keep up to 10 uploads open at a time. Create uploads and send parts for several files at once. A project can have 10 uploads open. An upload is open until you complete it, cancel it, or it expires. The eleventh create answers429 too_many_open_uploads. Complete one open upload, or cancel it, then
create the next. Completing an upload frees its place at once, even while its
video is still encoding.
2. Complete each upload. Do not wait for encoding. Complete answers 202
for every valid upload. Encoding does not refuse it and does not make you
retry. Videos from all customers share one encode queue. They start in arrival
order as the encoder has room, and each shows processing until it is ready.
Do not cancel, and do not upload the file again, because a video is still
waiting.
- If complete answers
429 rate_limited, wait theRetry-Afterseconds, then send the same complete request again, with the same parts. Your file is not lost. - Do not cancel a finished upload. Cancelling removes the stored file and the video, and you must upload the whole file again.
- Do not upload the same file again. It creates a second video.
expiresAt). Complete
each upload before then.
3. Track each video to the end. Use the video.ready webhook,
or poll GET /v1/projects/{projectId}/videos/{videoId}, until each video is
ready or failed. A failed video names the file to check. Do not embed a
video before it is ready.
For a copy-paste retry loop that honours Retry-After, see
Code samples.
How long a bulk import takes
Upload speed does not set the total time. Encoding does. We do not promise a time, because the queue is shared by all customers. The wait depends on how many videos are waiting when you upload. Measure the first batch of your own import, and plan the rest from that. Encode time grows with the length and the quality of the source file.Errors
Errors useapplication/problem+json. Use the code field in your code, not the text.
Errors on the part
PUT come from storage, not from our API. See the next section.
Retry rules
Do not retry
400, 401, 403 and 404 from the API without a change.
Code examples
These examples were run against the current release. The Node, Python and PHP
examples each
uploaded a 250 MiB file (3 parts) and the video reached processing.
The create, complete, cancel and error paths are also covered by our test
suite.
Node.js (18+)
Python 3 (pip install requests)
PHP / Laravel
memory_limit of at least 512 MB, or stream the part.
Browser
A browser can upload on your own domain with a browser upload token. The token is short-lived, single-use and capped in size. Your server creates it; the browser never sees your API key. The flow:- Your server calls
POST /v1/projects/{projectId}/upload-tokenswith yourfullAPI key. The body names the verifieddomain, amaxSizeBytesand thecontentType. - Your server sends the returned
tokento the browser. - The browser calls
createandcompletewithAuthorization: Bearer <token>from that domain. It alsoPUTs each part to its pre-signed URL and reads theETag. - The
PUTwork still goes straight to storage: the file never passes through the API.
create and its matching complete, and nothing
else: it cannot list, delete or play. A second create gets
409 token_used. The part PUT needs no auth header, and our storage allows
the PUT from any origin and exposes the ETag header.
Rules:
Create the token on your server:
201):
create and complete with the token instead of a key.
Bans, plan limits and the review hold (where it is on) still apply.
If you cannot mint an upload token on your server, the older path still works: your server callscreateandcomplete, and the browser onlyPUTs the parts. The browser cannot callcreateorcompletewith an API key from your own domain; only the token path above, or our dashboard origin, is allowed.