Skip to main content
This tutorial takes you from a new account to a video that plays on your own website. You upload one MP4 file, create a playback token on your server, and embed the player. The last step shows that a copied link fails on another site. You need:
  • 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 curl and jq installed.
Each step has one block of commands or code, and the output you should see after it. Replace every value that starts with YOUR_ or ends with ....

Step 1: Create a project and an API key

  1. Open app.segmnt.cloud and sign in with Google or GitHub. Your free account is created on your first sign-in.
  2. Click New project. Enter a name, for example Course site.
  3. Open the project. Click API keys, then Create key. The dashboard creates a full key, which can call every route of this project.
  4. Copy the key. It starts with sk_. We show it only once.
Set the values in your terminal:
Check the key. Run this command:
Expected output, for a new project:
If you get 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.
  1. Open the project. Click Domains, then Add domain.
  2. Enter the exact host, for example courses.example.com. A subdomain counts as its own domain.
  3. 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. العربية: انسخ اسم السجل وقيمته ولا تُعِد كتابتهما؛ يبدأ الاسم بشرطة سفلية _.
  4. Click Verify.
DNS changes can take time to spread. If Verify fails, wait and click it again. Expected output: the domain shows the status Verified in the dashboard.

Step 3: Upload a video

Run these commands in the folder that holds your MP4 file. Change FILE to your file name. A file under 100 MiB has one part. Larger files need more parts. See Direct upload. First, create the upload:
Expected output: none. The file upload.json now holds the answer. Read the IDs with this command:
Expected output: an upload ID that starts with 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:
Expected output: the video as JSON, with "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:
Expected output: 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.
Expected output: none. The file token.json holds the answer. It looks like this, with the values shortened:
The 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. Replace YOUR_PLAYBACK_TOKEN with the value of $TOKEN from step 5. Use the vid_ ID from step 3.
Open the page. The video appears with its thumbnail. Press play. Expected output: the video plays on your page.

Step 7: Check the domain lock

Ask for the playlist with your token, and with an origin that you did not verify:
Expected output: a 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