- A Google or GitHub account, to sign in to the dashboard.
- A domain or subdomain that you control, for example
courses.example.com, and access to its DNS settings. - A short MP4 file under 100 MiB.
- A terminal with
curlandjqinstalled.
YOUR_ or ends with ....
Step 1: Create a project and an API key
- Open app.segmnt.cloud and sign in with Google or GitHub. Your free account is created on your first sign-in.
- Click New project. Enter a name, for example
Course site. - Open the project. Click API keys, then Create key. The dashboard
creates a
fullkey, which can call every route of this project. - Copy the key. It starts with
sk_. We show it only once.
401, the key is wrong. Copy it again. See
Authentication.
Step 2: Verify your domain
Playback works only on domains that you verify. Add the host in the dashboard. A free account can verify one domain.- Open the project. Click Domains, then Add domain.
-
Enter the exact host, for example
courses.example.com. A subdomain counts as its own domain. -
Add the TXT record that the dashboard shows to your DNS provider. The name
starts with
_segmnt-verify.:Copy the name and the value. Do not retype them. The name starts with an underscore (_), and in Arabic text it can be shown at the wrong end of the name. A copied record always verifies. العربية: انسخ اسم السجل وقيمته ولا تُعِد كتابتهما؛ يبدأ الاسم بشرطة سفلية_. - Click Verify.
Step 3: Upload a video
Run these commands in the folder that holds your MP4 file. ChangeFILE to your
file name. A file under 100 MiB has one part. Larger files need more parts. See
Direct upload.
First, create the upload:
upload.json now holds the answer. Read the IDs
with this command:
upl_, then a video ID that
starts with vid_.
Next, send the file to the part URL, then complete the upload. The part URL
needs no API key:
"status":"processing". The encode
starts now.
You can also upload in the dashboard. Open the project, click Upload, and
choose the file. Then open the video, copy its ID, and set VIDEO_ID to that ID.
Step 4: Wait until the video is ready
Run this loop. It checks the status every 10 seconds and stops when the video is no longer processing:processing on each line, then ready. The time depends on
the length of the video.
In a production system, subscribe to the
video.ready event instead of polling.
See Webhooks.
Step 5: Create a playback token on your server
Run this command on your server, not in a browser. The API key stays on the server. The token is safe to send to a browser, because it works only for this video and this domain.token.json holds the answer. It looks like
this, with the values shortened:
domain must be a verified domain of your project. Otherwise the answer is
400 invalid_request.
A token lasts 4 hours by default. For a longer video, add expiresInSeconds to
the body. The maximum is 86400. Create a new token each time you show the video.
For cURL, Node.js and PHP examples, see
Create playback tokens on your server.
Step 6: Embed the player
Paste this code into the page on your verified domain. ReplaceYOUR_PLAYBACK_TOKEN with the value of $TOKEN from step 5. Use the vid_ ID
from step 3.
Step 7: Check the domain lock
Ask for the playlist with your token, and with an origin that you did not verify:403 answer with the header X-Segmnt-Error: domain_mismatch.
A copied link does not play on another site. Your video is now protected by a
token and a domain lock.
Free and Starter play through our embed (our player, with our logo). Pro and
Agency can use their own player.
If a step fails
For every error code, see Errors.
Next steps
- Authentication: base URL, key scopes, and how playback tokens differ from API keys.
- Direct upload: files larger than 100 MiB, and parallel parts.
- Create playback tokens on your server: cURL, Node.js and PHP examples.
- Webhooks: get a
video.readyevent instead of polling.