Skip to content
Start here

Create a relay

client.MoQ.Relays.New(ctx, params) (*RelayNewResponse, error)
POST/accounts/{account_id}/moq/relays

Provisions a new MoQ relay instance. Auto-creates a publish+subscribe token and a subscribe-only token. Token values are included in the response (shown once). Config is set to defaults (lingering subscribe enabled, 30s ceiling, upstreams off). Use PUT to modify.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
params RelayNewParams
AccountID param.Field[string]

Path param: Cloudflare account identifier.

Name param.Field[string]

Body param: Human-readable name for the relay.

ReturnsExpand Collapse
type RelayNewResponse struct{…}

Relay with auto-generated tokens (shown once).

Config RelayNewResponseConfig

upstreams and lingering_subscribe are mutually exclusive.

LingeringSubscribe RelayNewResponseConfigLingeringSubscribeOptional
Enabled boolOptional
MaxTimeoutMs int64Optional

Relay-level ceiling on lingering subscribe timeout (ms). Default 30000.

maximum300000
minimum0
Upstreams RelayNewResponseConfigUpstreamsOptional

Upstreams are external MOQT server publishers that a relay falls back to when it has no local publisher for a requested namespace/track.

Enabled boolOptional
Upstreams []RelayNewResponseConfigUpstreamsUpstreamOptional

Ordered list of upstream MOQT server publishers. Each entry is an object (not a bare string) so per-upstream configuration can be added in the future without another breaking change.

URL stringOptional

Upstream MOQT server publisher URL.

Created Time
formatdate-time
Modified Time
formatdate-time
Name string
TokenPublishSubscribe string

Full access token (publish + subscribe). Treat as sensitive.

TokenSubscribe string

Subscribe-only token. Treat as sensitive.

UID string

Server-generated unique identifier (32 hex chars).

Create a relay

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/cloudflare-go"
  "github.com/stainless-sdks/cloudflare-go/moq"
  "github.com/stainless-sdks/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  relay, err := client.MoQ.Relays.New(context.TODO(), moq.RelayNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    Name: cloudflare.F("Production Live Stream"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", relay.UID)
}
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "success": true,
  "result": {
    "config": {
      "lingering_subscribe": {
        "enabled": true,
        "max_timeout_ms": 0
      },
      "upstreams": {
        "enabled": true,
        "upstreams": [
          {
            "url": "url"
          }
        ]
      }
    },
    "created": "2019-12-27T18:11:19.117Z",
    "modified": "2019-12-27T18:11:19.117Z",
    "name": "Production Live Stream",
    "token_publish_subscribe": "eyJhbGciOiJFZDI1NTE5...",
    "token_subscribe": "eyJhbGciOiJFZDI1NTE5...",
    "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890"
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "success": true,
  "result": {
    "config": {
      "lingering_subscribe": {
        "enabled": true,
        "max_timeout_ms": 0
      },
      "upstreams": {
        "enabled": true,
        "upstreams": [
          {
            "url": "url"
          }
        ]
      }
    },
    "created": "2019-12-27T18:11:19.117Z",
    "modified": "2019-12-27T18:11:19.117Z",
    "name": "Production Live Stream",
    "token_publish_subscribe": "eyJhbGciOiJFZDI1NTE5...",
    "token_subscribe": "eyJhbGciOiJFZDI1NTE5...",
    "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890"
  }
}