Creating and watching a livestream is easy! The example below uses
Create Stream API to create and watch a
livestream.
Stream Creation
We can use the Livepeer SDK to create a stream. The example below uses the
Create Stream API.
import { Livepeer } from "livepeer";
const apiKey = 'YOUR_API_KEY';
const livepeer = new Livepeer({apiKey});
const streamData = {
name: "test_stream"
};
livepeer
.stream.create(streamData)
.then((response) => {
console.log("Stream created:", response);
})
.catch((error) => {
console.error("Error creating stream:", error);
});
import { Livepeer } from "livepeer";
const apiKey = 'YOUR_API_KEY';
const livepeer = new Livepeer({apiKey});
const streamData = {
name: "test_stream"
};
livepeer
.stream.create(streamData)
.then((response) => {
console.log("Stream created:", response);
})
.catch((error) => {
console.error("Error creating stream:", error);
});
from livepeer import Livepeer
# Initialize the Livepeer client with your API key
api_key = "YOUR_API_KEY"
livepeer = Livepeer(api_key)
stream_data = {
"name": "test_stream"
}
try:
# Create the stream
response = livepeer.stream.create(stream_data)
print("Stream created:", response)
except Exception as e:
print("Error creating stream:", e)
package main
import (
"fmt"
"os"
"github.com/livepeer/livepeer-go"
)
func main() {
// Initialize the Livepeer client with your API key
apiKey := "YOUR_API_KEY"
client := livepeer.NewLivepeerClient(apiKey)
streamData := map[string]interface{}{
"name": "test_stream",
}
// Create the stream
response, err := client.Stream.Create(streamData)
if err != nil {
fmt.Printf("Error creating stream: %v\n", err)
os.Exit(1)
}
fmt.Printf("Stream created: %+v\n", response)
}
You can find all the information required to broadcast to the stream in the
response object.
The RTMP ingest URL of Livepeer Studio is rtmp://rtmp.livepeer.com/live
, and
the streamKey
is present in the response object. You can use these two values
to broadcast to the stream.
You can also use WebRTC WHIP to broadcast, using the URL
https://playback.livepeer.studio/webrtc/{streamKey}
. This is used for
in-browser broadcasting.
To learn more about other stream functions such as stopping a stream,
recording a stream, and more, see the Stream
API.
Play a Stream
To learn how to play a stream, see the
Play a Livestream guide.