> ## Documentation Index
> Fetch the complete documentation index at: https://red5.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure Stream Manager 2.0 for Red5 Pro Clusters

> Set up Stream Manager 2.0 for Red5 Pro clusters. Covers JWT auth, publish and subscribe API endpoints, and end-to-end server provisioning examples.

Stream Manager 2.0 is the centralized control plane for Red5 Pro cluster deployments. It handles node provisioning, load balancing, auto-scaling, failover, and geographic distribution so that your application always routes publishers and subscribers to the most appropriate server node. Every interaction with your cluster — starting streams, finding an available origin, or assigning edge nodes to viewers — passes through the Stream Manager API.

## How Stream Manager 2.0 works

Stream Manager sits between your client applications and the pool of Red5 Pro media nodes. When a publisher requests a server to stream to, Stream Manager selects an available origin node and returns its address. When a viewer requests a server to subscribe from, Stream Manager selects the best available edge node based on current load and geographic proximity.

<CardGroup cols={2}>
  <Card title="Node management" icon="server">
    Provisions, monitors, and terminates origin, edge, relay, and transcoder nodes in response to load.
  </Card>

  <Card title="Load balancing" icon="scale-balanced">
    Distributes publishers and subscribers across available nodes to prevent any single server from becoming a bottleneck.
  </Card>

  <Card title="Auto-scaling" icon="arrows-up-down">
    Scales the node pool up when capacity thresholds are exceeded and down when demand decreases.
  </Card>

  <Card title="Failover" icon="shield-check">
    Detects unhealthy nodes and reroutes traffic to healthy ones automatically.
  </Card>

  <Card title="Geo distribution" icon="globe">
    Routes clients to the geographically nearest node to reduce latency.
  </Card>

  <Card title="REST API" icon="webhook">
    Exposes authenticated REST endpoints for stream management, node queries, and cluster provisioning.
  </Card>
</CardGroup>

## Installation

Stream Manager 2.0 is deployed as part of the Red5 Pro cluster, most commonly through the official Terraform modules. Terraform handles provisioning the Stream Manager host, configuring the database backend, and bootstrapping the node group.

For full installation steps, see the [Stream Manager 2.0 installation overview](/red5-pro/installation/cloud-terraform).

## Finding the Stream Manager URL

After a Terraform deployment completes, the Stream Manager URL is printed in the Terraform output. Look for a value like:

```
stream_manager_url = "https://sm.example.com:443"
```

If you deployed to a cloud provider directly without Terraform, find the public IP or DNS name assigned to the Stream Manager host in your cloud provider's console, then append the port (default `443` for HTTPS or `5080` for HTTP).

<Tip>
  Save the Stream Manager URL as an environment variable in your deployment environment so your application can reference it without hard-coding the address.
</Tip>

## Admin credentials

Stream Manager 2.0 uses JWT-based authentication. The initial admin credentials are set during installation. If you deployed with Terraform, the credentials appear in the Terraform output or in the secrets you provided as input variables.

To retrieve credentials after a Terraform deployment:

```bash theme={null}
terraform output stream_manager_admin_user
terraform output stream_manager_admin_password
```

<Warning>
  Change the default admin password immediately after your first login. The default credentials are well known and must not remain in place on any internet-accessible deployment.
</Warning>

## API authentication

All Stream Manager 2.0 API requests require a JWT bearer token. You obtain the token by posting your credentials to the authentication endpoint.

### Obtain a JWT token

```bash theme={null}
curl -X POST "https://sm.example.com/as/v1/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "your-password"}'
```

The response includes an `accessToken` field:

```json theme={null}
{
  "accessToken": "eyJhbGciOiJSUzI1NiJ9...",
  "tokenType": "Bearer",
  "expiresIn": 3600
}
```

Include the token in the `Authorization` header of every subsequent request:

```bash theme={null}
curl -H "Authorization: Bearer eyJhbGciOiJSUzI1NiJ9..." \
  "https://sm.example.com/as/v1/streams"
```

## Core API endpoints

The Stream Manager REST API is organized around two primary use cases: finding a server for a publisher, and finding a server for a subscriber.

### Get a server for publishing

Before a publisher connects to your cluster, your application calls this endpoint to receive the origin node address the publisher should connect to.

```bash theme={null}
curl -X GET \
  "https://sm.example.com/as/v1/streams/live/{streamName}/publish" \
  -H "Authorization: Bearer {accessToken}"
```

A successful response returns the connection details for the assigned origin node:

```json theme={null}
{
  "serverAddress": "203.0.113.10",
  "scope": "live",
  "name": "myStream",
  "port": 1935,
  "protocol": "rtmp"
}
```

### Get a server for subscribing

Before a viewer connects to consume a stream, your application calls this endpoint to receive the edge node address the subscriber should connect to.

```bash theme={null}
curl -X GET \
  "https://sm.example.com/as/v1/streams/live/{streamName}/subscribe" \
  -H "Authorization: Bearer {accessToken}"
```

```json theme={null}
{
  "serverAddress": "203.0.113.55",
  "scope": "live",
  "name": "myStream",
  "port": 443,
  "protocol": "wss"
}
```

## End-to-end example

The following example shows a complete publish flow: authenticate, request an origin node, and connect a publisher.

<CodeGroup>
  ```javascript node.js theme={null}
  const SM_URL = "https://sm.example.com";
  const STREAM_NAME = "myStream";

  // Step 1: Authenticate
  const authResponse = await fetch(`${SM_URL}/as/v1/auth/login`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ username: "admin", password: "your-password" }),
  });
  const { accessToken } = await authResponse.json();

  // Step 2: Get an origin node for publishing
  const nodeResponse = await fetch(
    `${SM_URL}/as/v1/streams/live/${STREAM_NAME}/publish`,
    { headers: { Authorization: `Bearer ${accessToken}` } }
  );
  const { serverAddress, port } = await nodeResponse.json();

  // Step 3: Connect your publisher to the returned address
  console.log(`Publish to: rtmp://${serverAddress}:${port}/live/${STREAM_NAME}`);
  ```

  ```python python theme={null}
  import requests

  SM_URL = "https://sm.example.com"
  STREAM_NAME = "myStream"

  # Step 1: Authenticate
  auth = requests.post(
      f"{SM_URL}/as/v1/auth/login",
      json={"username": "admin", "password": "your-password"},
  )
  access_token = auth.json()["accessToken"]

  # Step 2: Get an origin node for publishing
  headers = {"Authorization": f"Bearer {access_token}"}
  node = requests.get(
      f"{SM_URL}/as/v1/streams/live/{STREAM_NAME}/publish",
      headers=headers,
  )
  data = node.json()
  print(f"Publish to: rtmp://{data['serverAddress']}:{data['port']}/live/{STREAM_NAME}")
  ```
</CodeGroup>

## Node group management

You can query the current state of your node group to inspect how many nodes are active and what their roles are.

### List active nodes

```bash theme={null}
curl -X GET "https://sm.example.com/as/v1/nodegroups" \
  -H "Authorization: Bearer {accessToken}"
```

### Inspect a specific node group

```bash theme={null}
curl -X GET "https://sm.example.com/as/v1/nodegroups/{nodeGroupName}" \
  -H "Authorization: Bearer {accessToken}"
```

<Note>
  Node group names are defined in your Terraform configuration or Stream Manager launch configuration. Use the exact name you specified during deployment.
</Note>
