---
title: Create a relay
---

[Skip to content](#%5Ftop) 

[API Reference](https://developers.cloudflare.com/api/python)

[MoQ](https://developers.cloudflare.com/api/python/resources/moq)

[Relays](https://developers.cloudflare.com/api/python/resources/moq/subresources/relays)

Copy Markdown

Open in **Claude**

Open in **ChatGPT**

Open in **Cursor**

---

**Copy Markdown**

**View as Markdown**

# Create a relay

moq.relays.create(RelayCreateParams\*\*kwargs)  \-> [RelayCreateResponse](https://developers.cloudflare.com/api/python/resources/moq#%28resource%29%20moq.relays%20%3E%20%28model%29%20relay%5Fcreate%5Fresponse%20%3E%20%28schema%29)

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](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).

**Example:**`Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY`

##### ParametersExpand Collapse 

account\_id: str

Cloudflare account identifier.

name: str

Human-readable name for the relay.

minLength1

##### ReturnsExpand Collapse 

class RelayCreateResponse: …

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: Config

upstreams: Optional\[ConfigUpstreams\]

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

enabled: Optional\[bool\]

upstreams: Optional\[List\[ConfigUpstreamsUpstream\]\]

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: str

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

formaturi

created: datetime

formatdate-time

issuers: List\[Issuer\]

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

cloudflare\_tokens: List\[IssuerCloudflareToken\]

Always present (\[\] when empty).

created: datetime

formatdate-time

expires: datetime

Mandatory; no more than 1 year after `created`.

formatdate-time

jti: str

Token identity and registry key (32 hex chars).

operations: List\[Literal\["publish", "subscribe"\]\]

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:

"publish"

"subscribe"

label: Optional\[str\]

Optional, customer-set.

secret: Optional\[str\]

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

issuer: Literal\["cloudflare"\]

type: Literal\["cloudflare\_jwt"\]

modified: datetime

formatdate-time

name: str

uid: str

Server-generated unique identifier (32 hex chars).

### Create a relay

Python

HTTPHTTP

TypeScriptTypeScript

PythonPython

GoGo

TerraformTerraform

```
import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
relay = client.moq.relays.create(
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    name="Production Live Stream",
)
print(relay.uid)
```

200 example

```
{
  "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

200 example

```
{
  "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"
  }
}
```