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 always set to defaults (upstreams off) and cannot be supplied here — sending a non-empty config is rejected (21014); null or {} is accepted as absent. Use PUT to configure the relay after it exists.

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.

minLength1
ReturnsExpand Collapse
type RelayNewResponse struct{…}

Relay with its auto-created default token pair (one full-access [publish, subscribe] and one [subscribe]-only), each with its one-time secret, wrapped in the issuers envelope.

Config RelayNewResponseConfig
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 string

Upstream MOQT server publisher URL. Must be an absolute URL with a host and a scheme crique can dial: moqt:// (raw QUIC) or https:// (WebTransport). Validated on update (PUT); rejected with 21013.

formaturi
Created Time
formatdate-time
Issuers []RelayNewResponseIssuer

Token collection (discriminated union on type). On create this holds the auto-created default pair, each including its one-time secret.

CloudflareTokens []RelayNewResponseIssuersCloudflareToken

Always present ([] when empty).

Created Time
formatdate-time
Expires Time

Mandatory; no more than 1 year after created.

formatdate-time
Jti string

Token identity and registry key (32 hex chars).

Operations []RelayNewResponseIssuersCloudflareTokensOperation

Signed allowlist of what the token may do. V1 coarse roles; the array form extends to fine-grained MoQT message names later without a breaking change.

One of the following:
const RelayNewResponseIssuersCloudflareTokensOperationPublish RelayNewResponseIssuersCloudflareTokensOperation = "publish"
const RelayNewResponseIssuersCloudflareTokensOperationSubscribe RelayNewResponseIssuersCloudflareTokensOperation = "subscribe"
Label stringOptional

Optional, customer-set.

Secret stringOptional

The signed JWT. Present ONLY in create / auto-create responses (shown once); never returned by list, never stored.

Issuer RelayNewResponseIssuersIssuer
Type RelayNewResponseIssuersType
Modified Time
formatdate-time
Name string
UID string

Server-generated unique identifier (32 hex chars).

Create a relay

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/moq"
  "github.com/cloudflare/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": {
      "upstreams": {
        "enabled": true,
        "upstreams": [
          {
            "url": "https://example.com"
          }
        ]
      }
    },
    "created": "2019-12-27T18:11:19.117Z",
    "issuers": [
      {
        "cloudflare_tokens": [
          {
            "created": "2019-12-27T18:11:19.117Z",
            "expires": "2019-12-27T18:11:19.117Z",
            "jti": "f3a1b2c3d4e5f67890a1b2c3d4e5f678",
            "operations": [
              "publish",
              "subscribe"
            ],
            "label": "primary-encoder",
            "secret": "eyJhbGciOiJFZDI1NTE5..."
          }
        ],
        "issuer": "cloudflare",
        "type": "cloudflare_jwt"
      }
    ],
    "modified": "2019-12-27T18:11:19.117Z",
    "name": "Production Live Stream",
    "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890"
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "success": true,
  "result": {
    "config": {
      "upstreams": {
        "enabled": true,
        "upstreams": [
          {
            "url": "https://example.com"
          }
        ]
      }
    },
    "created": "2019-12-27T18:11:19.117Z",
    "issuers": [
      {
        "cloudflare_tokens": [
          {
            "created": "2019-12-27T18:11:19.117Z",
            "expires": "2019-12-27T18:11:19.117Z",
            "jti": "f3a1b2c3d4e5f67890a1b2c3d4e5f678",
            "operations": [
              "publish",
              "subscribe"
            ],
            "label": "primary-encoder",
            "secret": "eyJhbGciOiJFZDI1NTE5..."
          }
        ],
        "issuer": "cloudflare",
        "type": "cloudflare_jwt"
      }
    ],
    "modified": "2019-12-27T18:11:19.117Z",
    "name": "Production Live Stream",
    "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890"
  }
}