Tutorials

Restream API: create and control multistream destinations from your own code

How your own code can create a restream, name its source, manage each destination and read back errors, with the refusals to expect along the way.

dcast Team
7 min read
Share:
man, microphone, music, musician, recording, singer, rapper, rap, singing, audio equipment, recording studio, microphone, sin
On this page

If you run a multistream setup, sooner or later you want your own code to handle it instead of someone clicking through a dashboard. With the DCAST restream API your code creates a restream, names its source and manages each destination. When a request is refused, the answer tells you which field to fix. This guide walks through the calls in the order you will use them, the refusals you should expect, and the checks worth running before a real event.

Upload, stream and sell your videos. Start on the free plan — no card needed.

Get Started Free

What your code can do with a restream

Restreaming sends one broadcast to several platforms at once, so your audience can watch where they already are. The partner API gives your code the same objects you would otherwise set up by hand. You decide where the video comes from, attach destinations, and read back what each destination is doing.

The partner interface has operations to list restreams, read one, create one, replace one and delete one. It also has an operation that updates a single destination and one that rotates the key of a destination. Starting and stopping a restream, starting and stopping its input, and fetching the encoder addresses and the preview address are separate operations too. Your code reads the account's restream accounts through one more operation. This guide describes only the behaviour that you can rely on, so it does not promise what a key rotation or a stop does after the call.

Create a restream and choose its source

Creation is the first call, and you do not need every destination ready for it. You can create a restream from your code before it has any destination at all. That suits a flow where your own system reserves the restream first and a later step collects stream keys from your users.

The source you name, such as RTMP, SRT or WebRTC, is the one that is stored and answered back. An SRT restream therefore waits for an SRT feed and not for something else. Compare the stored source in the answer with the one you sent and log any mismatch, so a mapping mistake in your code shows up on the first test and not during an event.

To restream one of your existing broadcasts, you link that broadcast as the source. A broadcast that belongs to another account is refused, so your code can only link what the key owner holds. If a request links a broadcast and also names a different source protocol, it is refused as well, so your code never gets a restream it did not ask for.

You may also leave the source out. A restream linked to one of your broadcasts then pulls from it, and any other restream waits for an RTMP feed. Naming the source is still the better habit in code you plan to maintain, because it documents your intent. If you name a source the platform cannot take in, the request is refused by name instead of being quietly turned into an RTMP restream. Treat that refusal as a bug in your own mapping and fix the mapping instead of retrying.

Destinations and the fields each one needs

Your code sends destinations as a list of objects. If the value is not a list, or one entry is not an object, the request is refused with the field named and no restream is created. You can correct the payload and send it again without hunting for a leftover restream to clean up.

Each destination names a platform. The options include YouTube, Twitch, Facebook, Instagram, TikTok and Kick, as well as a custom address for any other service. Do not hard-code which platform needs which field. A destination without a stream key, or a custom destination without its address, cannot be switched on until the missing field is filled in. Platforms with a known ingest address only need the key, so let the answer tell your form which input to flag.

If you let your users type their own addresses, expect one more refusal. An address that points into a private network is refused before anything is saved. Show that message to the person who typed it, because sending the same request again will fail the same way.

Update a restream and keep the switch honest

When you update a restream, switching a destination off or on is written as you sent it. An update that leaves the switch out keeps what was stored. That gives you a clean rule for partial edits: send the switch only when you mean to change it. If you rebuild the whole destination list from your own database, include the switch on every entry so the stored result matches your records.

The completeness rule applies here too. A destination missing its key or its address cannot be stored as switched on, and platforms with a known address only need the key. If you clear the key of a destination, it drops out of the active list instead of failing in the middle of a broadcast. A destination you switched off stays off even when every field is filled in, so your code can treat the switch as a statement of intent. After any update, read the restream again and confirm the destination you changed shows the state you expected.

Read destination state and errors

When you read a restream, each destination shows whether it is switched on, its last error and the moment that error happened. Build your monitoring around those three values. Store the error text together with its time, so your support team can tell a failure from an hour ago from one that is still current.

Plan for one difference between keys. A read-only key sees whether each destination is switched on but not the error text, because that text can carry the address of the destination. A status screen that only displays restreams can use a read-only key, but you should not expect error messages on it. If your support staff need the text, fetch it from a part of your system that holds a key allowed to see it.

Start a restream and read the refusal

Starting a restream asks for a key that is allowed to operate restreams, while creating and editing ask for a write permission and deleting asks for a delete permission. If your integration creates restreams in one service and starts them in another, issue the keys accordingly and give each service only what it needs.

When a start cannot go ahead, the answer names each switched-on destination and the field it is missing. It also tells a restream with nothing switched on apart from one where nothing is filled in. Use that difference in your own messages. In the first case your user has to switch a destination on, and in the second they have to complete the key or the address that is named.

How many destinations can run at the same time depends on your plan. Check that limit before you design a feature that fans one source out to many platforms, and decide what your code shows when a customer asks for more destinations than their plan runs.

Keys, read-only access and a test before the event

Keep your API key on your server, and give a dashboard that only displays your restreams a read-only key. Never place a key in a page your visitors load, because anyone who reads it can act as your account. The stream keys of destinations deserve the same care, since anyone who holds one can broadcast to that channel.

Before an important event, test each destination with a short private broadcast, because every platform has its own rules for new streams. A good routine is to create the restream from your code, switch on one destination at a time, start it, then read the restream and look at the last error and its time for each destination. Fix every destination that shows an error before you go public, and keep the test script so you can run it again before the next event.

API documentation for this topic

d

dcast Team

Professional video streaming experts helping creators succeed.

Start Your Video Business Today

Upload, stream and sell your videos. Start on the free plan — no card needed.

Get Started Free