The Livepeer Go library provides convenient access to the Livepeer Studio API from applications written in Golang.
For full documentation and examples, please visit docs.livepeer.org.
go get github.com/livepeer/livepeer-go
package main
import (
"context"
livepeer "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeer.New(
livepeer.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.Create(ctx, components.NewStreamPayload{
Name: "test_stream",
})
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
- Create - Create a stream
- GetAll - Retrieve streams
- Get - Retrieve a stream
- Update - Update a stream
- Delete - Delete a stream
- Terminate - Terminates a live stream
- StartPull - Start ingest for a pull stream
- CreateClip - Create a clip
- GetClips - Retrieve clips of a livestream
- AddMultistreamTarget - Add a multistream target
- RemoveMultistreamTarget - Remove a multistream target
- GetAll - Retrieve Multistream Targets
- Create - Create a multistream target
- Get - Retrieve a multistream target
- Update - Update Multistream Target
- Delete - Delete a multistream target
- GetAll - Retrieve a Webhook
- Create - Create a webhook
- Get - Retrieve a webhook
- Update - Update a webhook
- Delete - Delete a webhook
- GetLogs - Retrieve webhook logs
- GetLog - Retrieve a webhook log
- ResendLog - Resend a webhook
- GetAll - Retrieve assets
- Create - Upload an asset
- CreateViaURL - Upload asset via URL
- Get - Retrieves an asset
- Update - Patch an asset
- Delete - Delete an asset
- GetClips - Retrieve clips of a session
- GetAll - Retrieve sessions
- Get - Retrieve a session
- GetRecorded - Retrieve Recorded Sessions
Create- Create a room⚠️ DeprecatedGet- Retrieve a room⚠️ DeprecatedDelete- Delete a room⚠️ DeprecatedStartEgress- Start room RTMP egress⚠️ DeprecatedStopEgress- Stop room RTMP egress⚠️ DeprecatedCreateUser- Create a room user⚠️ DeprecatedGetUser- Get user details⚠️ DeprecatedUpdateUser- Update a room user⚠️ DeprecatedDeleteUser- Remove a user from the room⚠️ Deprecated
- GetViewership - Query viewership metrics
- GetCreatorViewership - Query creator viewership metrics
- GetPublicViewership - Query public total views metrics
- GetUsage - Query usage metrics
- Create - Create a signing key
- GetAll - Retrieves signing keys
- Delete - Delete Signing Key
- Get - Retrieves a signing key
- Update - Update a signing key
- Create - Transcode a video
- Get - Retrieve Playback Info
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.Error | 404 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
package main
import (
"context"
"errors"
livepeergo "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/sdkerrors"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
var id string = "<value>"
ctx := context.Background()
res, err := s.Playback.Get(ctx, id)
if err != nil {
var e *sdkerrors.Error
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
You can override the default server globally using the WithServerIndex
option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://livepeer.studio/api |
None |
package main
import (
"context"
livepeergo "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithServerIndex(0),
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
request := components.NewStreamPayload{
Name: "test_stream",
Pull: &components.Pull{
Source: "https://myservice.com/live/stream.flv",
Headers: map[string]string{
"Authorization": "Bearer 123",
},
Location: &components.Location{
Lat: 39.739,
Lon: -104.988,
},
},
PlaybackPolicy: &components.PlaybackPolicy{
Type: components.TypeWebhook,
WebhookID: livepeergo.String("1bde4o2i6xycudoy"),
WebhookContext: map[string]any{
"streamerId": "my-custom-id",
},
RefreshInterval: livepeergo.Float64(600),
},
Profiles: []components.FfmpegProfile{
components.FfmpegProfile{
Width: 1280,
Name: "720p",
Height: 486589,
Bitrate: 3000000,
Fps: 30,
FpsDen: livepeergo.Int64(1),
Quality: livepeergo.Int64(23),
Gop: livepeergo.String("2"),
Profile: components.ProfileH264Baseline.ToPointer(),
},
},
Record: livepeergo.Bool(false),
Multistream: &components.Multistream{
Targets: []components.Target{
components.Target{
Profile: "720p",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
},
},
},
}
ctx := context.Background()
res, err := s.Stream.Create(ctx, request)
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
The default server can also be overridden globally using the WithServerURL
option when initializing the SDK client instance. For example:
package main
import (
"context"
livepeergo "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithServerURL("https://livepeer.studio/api"),
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
request := components.NewStreamPayload{
Name: "test_stream",
Pull: &components.Pull{
Source: "https://myservice.com/live/stream.flv",
Headers: map[string]string{
"Authorization": "Bearer 123",
},
Location: &components.Location{
Lat: 39.739,
Lon: -104.988,
},
},
PlaybackPolicy: &components.PlaybackPolicy{
Type: components.TypeWebhook,
WebhookID: livepeergo.String("1bde4o2i6xycudoy"),
WebhookContext: map[string]any{
"streamerId": "my-custom-id",
},
RefreshInterval: livepeergo.Float64(600),
},
Profiles: []components.FfmpegProfile{
components.FfmpegProfile{
Width: 1280,
Name: "720p",
Height: 486589,
Bitrate: 3000000,
Fps: 30,
FpsDen: livepeergo.Int64(1),
Quality: livepeergo.Int64(23),
Gop: livepeergo.String("2"),
Profile: components.ProfileH264Baseline.ToPointer(),
},
},
Record: livepeergo.Bool(false),
Multistream: &components.Multistream{
Targets: []components.Target{
components.Target{
Profile: "720p",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
},
},
},
}
ctx := context.Background()
res, err := s.Stream.Create(ctx, request)
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
APIKey |
http | HTTP Bearer |
You can configure it using the WithSecurity
option when initializing the SDK client instance. For example:
package main
import (
"context"
livepeergo "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
request := components.NewStreamPayload{
Name: "test_stream",
Pull: &components.Pull{
Source: "https://myservice.com/live/stream.flv",
Headers: map[string]string{
"Authorization": "Bearer 123",
},
Location: &components.Location{
Lat: 39.739,
Lon: -104.988,
},
},
PlaybackPolicy: &components.PlaybackPolicy{
Type: components.TypeWebhook,
WebhookID: livepeergo.String("1bde4o2i6xycudoy"),
WebhookContext: map[string]any{
"streamerId": "my-custom-id",
},
RefreshInterval: livepeergo.Float64(600),
},
Profiles: []components.FfmpegProfile{
components.FfmpegProfile{
Width: 1280,
Name: "720p",
Height: 486589,
Bitrate: 3000000,
Fps: 30,
FpsDen: livepeergo.Int64(1),
Quality: livepeergo.Int64(23),
Gop: livepeergo.String("2"),
Profile: components.ProfileH264Baseline.ToPointer(),
},
},
Record: livepeergo.Bool(false),
Multistream: &components.Multistream{
Targets: []components.Target{
components.Target{
Profile: "720p",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
},
},
},
}
ctx := context.Background()
res, err := s.Stream.Create(ctx, request)
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
go get github.com/livepeer/livepeer-go
package main
import (
"context"
livepeergo "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
request := components.NewStreamPayload{
Name: "test_stream",
Pull: &components.Pull{
Source: "https://myservice.com/live/stream.flv",
Headers: map[string]string{
"Authorization": "Bearer 123",
},
Location: &components.Location{
Lat: 39.739,
Lon: -104.988,
},
},
PlaybackPolicy: &components.PlaybackPolicy{
Type: components.TypeWebhook,
WebhookID: livepeergo.String("1bde4o2i6xycudoy"),
WebhookContext: map[string]any{
"streamerId": "my-custom-id",
},
RefreshInterval: livepeergo.Float64(600),
},
Profiles: []components.FfmpegProfile{
components.FfmpegProfile{
Width: 1280,
Name: "720p",
Height: 486589,
Bitrate: 3000000,
Fps: 30,
FpsDen: livepeergo.Int64(1),
Quality: livepeergo.Int64(23),
Gop: livepeergo.String("2"),
Profile: components.ProfileH264Baseline.ToPointer(),
},
},
Record: livepeergo.Bool(false),
Multistream: &components.Multistream{
Targets: []components.Target{
components.Target{
Profile: "720p",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
},
},
},
}
ctx := context.Background()
res, err := s.Stream.Create(ctx, request)
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
- Create - Create a stream
- GetAll - Retrieve streams
- Get - Retrieve a stream
- Update - Update a stream
- Delete - Delete a stream
- Terminate - Terminates a live stream
- StartPull - Start ingest for a pull stream
- CreateClip - Create a clip
- GetClips - Retrieve clips of a livestream
- AddMultistreamTarget - Add a multistream target
- RemoveMultistreamTarget - Remove a multistream target
- GetAll - Retrieve Multistream Targets
- Create - Create a multistream target
- Get - Retrieve a multistream target
- Update - Update Multistream Target
- Delete - Delete a multistream target
- GetAll - Retrieve a Webhook
- Create - Create a webhook
- Get - Retrieve a webhook
- Update - Update a webhook
- Delete - Delete a webhook
- GetLogs - Retrieve webhook logs
- GetLog - Retrieve a webhook log
- ResendLog - Resend a webhook
- GetAll - Retrieve assets
- Create - Upload an asset
- CreateViaURL - Upload asset via URL
- Get - Retrieves an asset
- Update - Patch an asset
- Delete - Delete an asset
- GetClips - Retrieve clips of a session
- GetAll - Retrieve sessions
- Get - Retrieve a session
- GetRecorded - Retrieve Recorded Sessions
Create- Create a room⚠️ DeprecatedGet- Retrieve a room⚠️ DeprecatedDelete- Delete a room⚠️ DeprecatedStartEgress- Start room RTMP egress⚠️ DeprecatedStopEgress- Stop room RTMP egress⚠️ DeprecatedCreateUser- Create a room user⚠️ DeprecatedGetUser- Get user details⚠️ DeprecatedUpdateUser- Update a room user⚠️ DeprecatedDeleteUser- Remove a user from the room⚠️ Deprecated
- GetViewership - Query viewership metrics
- GetCreatorViewership - Query creator viewership metrics
- GetPublicViewership - Query public total views metrics
- GetUsage - Query usage metrics
- Create - Create a signing key
- GetAll - Retrieves signing keys
- Delete - Delete Signing Key
- Get - Retrieves a signing key
- Update - Update a signing key
- Create - Transcode a video
- Get - Retrieve Playback Info