# MoQ # Relays ## List relays `client.MoQ.Relays.List(ctx, params) (*SinglePage[RelayListResponse], error)` **get** `/accounts/{account_id}/moq/relays` Lists all MoQ relays for the account. Returns only metadata. Config, status, and tokens are omitted. Results are cursor-paginated (keyset on the `created` timestamp). Use `created_before` / `created_after` with the `created` value of the first/last item in a page to fetch the adjacent page. `result_info` reports the page `count` and the `total` matching the cursor filters. ### Parameters - `params RelayListParams` - `AccountID param.Field[string]` Path param: Cloudflare account identifier. - `Asc param.Field[bool]` Query param: Sort order by `created`. When true, results are returned oldest-first (ascending); otherwise newest-first (descending, the default). - `CreatedAfter param.Field[Time]` Query param: Cursor for pagination. Returns relays created strictly after this RFC 3339 timestamp (typically the `created` value of the last item on the current page, to fetch the next page). - `CreatedBefore param.Field[Time]` Query param: Cursor for pagination. Returns relays created strictly before this RFC 3339 timestamp (typically the `created` value of the first item on the current page, to fetch the previous page). - `PerPage param.Field[int64]` Query param: Maximum number of relays to return per page. ### Returns - `type RelayListResponse struct{…}` Abbreviated relay for list responses. - `Created Time` - `Modified Time` - `Name string` - `UID string` ### Example ```go 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"), ) page, err := client.MoQ.Relays.List(context.TODO(), moq.RelayListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "success": true, "result": [ { "created": "2019-12-27T18:11:19.117Z", "modified": "2019-12-27T18:11:19.117Z", "name": "name", "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890" } ], "result_info": { "count": 0, "total": 0 } } ``` ## Get a relay `client.MoQ.Relays.Get(ctx, relayID, query) (*RelayGetResponse, error)` **get** `/accounts/{account_id}/moq/relays/{relay_id}` Retrieves a single MoQ relay including config and status. Tokens are NOT included. ### Parameters - `relayID string` - `query RelayGetParams` - `AccountID param.Field[string]` Cloudflare account identifier. ### Returns - `type RelayGetResponse struct{…}` Full relay details (no tokens). - `Config RelayGetResponseConfig` origin_fallback and lingering_subscribe are mutually exclusive. - `LingeringSubscribe RelayGetResponseConfigLingeringSubscribe` - `Enabled bool` - `MaxTimeoutMs int64` Relay-level ceiling on lingering subscribe timeout (ms). Default 30000. - `OriginFallback RelayGetResponseConfigOriginFallback` - `Enabled bool` - `Origins []RelayGetResponseConfigOriginFallbackOrigin` Ordered list of upstream origin relays. Each entry is an object (not a bare string) so per-origin configuration can be added in the future without another breaking change. - `URL string` Upstream origin relay URL. - `Created Time` - `Modified Time` - `Name string` - `UID string` - `Status RelayGetResponseStatus` "connected" when active, omitted otherwise. - `const RelayGetResponseStatusConnected RelayGetResponseStatus = "connected"` ### Example ```go 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.Get( context.TODO(), "a1b2c3d4e5f67890a1b2c3d4e5f67890", moq.RelayGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", relay.UID) } ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "success": true, "result": { "config": { "lingering_subscribe": { "enabled": true, "max_timeout_ms": 0 }, "origin_fallback": { "enabled": true, "origins": [ { "url": "url" } ] } }, "created": "2019-12-27T18:11:19.117Z", "modified": "2019-12-27T18:11:19.117Z", "name": "Production Live Stream", "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890", "status": "connected" } } ``` ## 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, origin fallback off). Use PUT to modify. ### Parameters - `params RelayNewParams` - `AccountID param.Field[string]` Path param: Cloudflare account identifier. - `Name param.Field[string]` Body param: Human-readable name for the relay. ### Returns - `type RelayNewResponse struct{…}` Relay with auto-generated tokens (shown once). - `Config RelayNewResponseConfig` origin_fallback and lingering_subscribe are mutually exclusive. - `LingeringSubscribe RelayNewResponseConfigLingeringSubscribe` - `Enabled bool` - `MaxTimeoutMs int64` Relay-level ceiling on lingering subscribe timeout (ms). Default 30000. - `OriginFallback RelayNewResponseConfigOriginFallback` - `Enabled bool` - `Origins []RelayNewResponseConfigOriginFallbackOrigin` Ordered list of upstream origin relays. Each entry is an object (not a bare string) so per-origin configuration can be added in the future without another breaking change. - `URL string` Upstream origin relay URL. - `Created Time` - `Modified 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). ### Example ```go 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) } ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "success": true, "result": { "config": { "lingering_subscribe": { "enabled": true, "max_timeout_ms": 0 }, "origin_fallback": { "enabled": true, "origins": [ { "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" } } ``` ## Update a relay `client.MoQ.Relays.Update(ctx, relayID, params) (*RelayUpdateResponse, error)` **put** `/accounts/{account_id}/moq/relays/{relay_id}` Updates a relay's name and/or configuration. Partial updates: omitted fields are preserved. Config sub-objects replace as whole objects when present. origin_fallback and lingering_subscribe are mutually exclusive. ### Parameters - `relayID string` - `params RelayUpdateParams` - `AccountID param.Field[string]` Path param: Cloudflare account identifier. - `Config param.Field[RelayUpdateParamsConfig]` Body param: origin_fallback and lingering_subscribe are mutually exclusive. - `LingeringSubscribe RelayUpdateParamsConfigLingeringSubscribe` - `Enabled bool` - `MaxTimeoutMs int64` Relay-level ceiling on lingering subscribe timeout (ms). Default 30000. - `OriginFallback RelayUpdateParamsConfigOriginFallback` - `Enabled bool` - `Origins []RelayUpdateParamsConfigOriginFallbackOrigin` Ordered list of upstream origin relays. Each entry is an object (not a bare string) so per-origin configuration can be added in the future without another breaking change. - `URL string` Upstream origin relay URL. - `Name param.Field[string]` Body param ### Returns - `type RelayUpdateResponse struct{…}` Full relay details (no tokens). - `Config RelayUpdateResponseConfig` origin_fallback and lingering_subscribe are mutually exclusive. - `LingeringSubscribe RelayUpdateResponseConfigLingeringSubscribe` - `Enabled bool` - `MaxTimeoutMs int64` Relay-level ceiling on lingering subscribe timeout (ms). Default 30000. - `OriginFallback RelayUpdateResponseConfigOriginFallback` - `Enabled bool` - `Origins []RelayUpdateResponseConfigOriginFallbackOrigin` Ordered list of upstream origin relays. Each entry is an object (not a bare string) so per-origin configuration can be added in the future without another breaking change. - `URL string` Upstream origin relay URL. - `Created Time` - `Modified Time` - `Name string` - `UID string` - `Status RelayUpdateResponseStatus` "connected" when active, omitted otherwise. - `const RelayUpdateResponseStatusConnected RelayUpdateResponseStatus = "connected"` ### Example ```go 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.Update( context.TODO(), "a1b2c3d4e5f67890a1b2c3d4e5f67890", moq.RelayUpdateParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", relay.UID) } ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "success": true, "result": { "config": { "lingering_subscribe": { "enabled": true, "max_timeout_ms": 0 }, "origin_fallback": { "enabled": true, "origins": [ { "url": "url" } ] } }, "created": "2019-12-27T18:11:19.117Z", "modified": "2019-12-27T18:11:19.117Z", "name": "Production Live Stream", "uid": "a1b2c3d4e5f67890a1b2c3d4e5f67890", "status": "connected" } } ``` ## Delete a relay `client.MoQ.Relays.Delete(ctx, relayID, body) (*RelayDeleteResponse, error)` **delete** `/accounts/{account_id}/moq/relays/{relay_id}` Soft-deletes a MoQ relay. ### Parameters - `relayID string` - `body RelayDeleteParams` - `AccountID param.Field[string]` Cloudflare account identifier. ### Returns - `type RelayDeleteResponse interface{…}` ### Example ```go 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.Delete( context.TODO(), "a1b2c3d4e5f67890a1b2c3d4e5f67890", moq.RelayDeleteParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", relay) } ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "success": true, "result": {} } ``` # Tokens ## Rotate a token `client.MoQ.Relays.Tokens.Rotate(ctx, relayID, params) (*RelayTokenRotateResponse, error)` **post** `/accounts/{account_id}/moq/relays/{relay_id}/tokens/rotate` Generates a new token for the specified type. The old token is immediately invalidated. Token value is shown once in the response. ### Parameters - `relayID string` - `params RelayTokenRotateParams` - `AccountID param.Field[string]` Path param: Cloudflare account identifier. - `Type param.Field[RelayTokenRotateParamsType]` Body param: Which token type to rotate. - `const RelayTokenRotateParamsTypePublishSubscribe RelayTokenRotateParamsType = "publish_subscribe"` - `const RelayTokenRotateParamsTypeSubscribe RelayTokenRotateParamsType = "subscribe"` ### Returns - `type RelayTokenRotateResponse struct{…}` - `Token string` New token value (shown once). Treat as sensitive. - `Type RelayTokenRotateResponseType` - `const RelayTokenRotateResponseTypePublishSubscribe RelayTokenRotateResponseType = "publish_subscribe"` - `const RelayTokenRotateResponseTypeSubscribe RelayTokenRotateResponseType = "subscribe"` ### Example ```go 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"), ) response, err := client.MoQ.Relays.Tokens.Rotate( context.TODO(), "a1b2c3d4e5f67890a1b2c3d4e5f67890", moq.RelayTokenRotateParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Type: cloudflare.F(moq.RelayTokenRotateParamsTypePublishSubscribe), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.Token) } ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "success": true, "result": { "token": "eyJhbGciOiJFZDI1NTE5...", "type": "publish_subscribe" } } ```