> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-docs.mentra.glass/llms.txt
> Use this file to discover all available pages before exploring further.

# Streams

> REST endpoints for managing RTMP stream outputs

## Add Stream Output

Add a restream output to an active managed stream.

### Endpoint

```
POST /api/streams/:streamId/outputs
```

### Headers

```
X-API-Key: <appApiKey>
X-Package-Name: <packageName>
```

### Parameters

* `streamId`: The managed stream identifier

### Request Body

```json theme={null}
{
  "url": "rtmp://streaming.service.com/live/stream-key",
  "name": "My Stream Output"
}
```

### Response

Success:

```json theme={null}
{
  "success": true,
  "outputId": "output-uuid",
  "message": "Output added successfully"
}
```

Error:

```json theme={null}
{
  "error": "MAX_OUTPUTS_REACHED",
  "message": "Maximum outputs per stream reached (10)"
}
```

### Implementation

* **File**: `packages/cloud/src/routes/streams.routes.ts:22-137`
* **Middleware**: `validateAppApiKey`
* **Service**: `ManagedStreamingExtension.addRestreamOutput()`

### Validation

* URL must start with `rtmp://` or `rtmps://`
* App must be actively viewing the stream
* Maximum 10 outputs per stream
* Maximum 10 outputs per app
* No duplicate URLs allowed

## Remove Stream Output

Remove a restream output from a managed stream.

### Endpoint

```
DELETE /api/streams/:streamId/outputs/:outputId
```

### Headers

```
X-API-Key: <appApiKey>
X-Package-Name: <packageName>
```

### Parameters

* `streamId`: The managed stream identifier
* `outputId`: The output identifier to remove

### Response

Success:

```json theme={null}
{
  "success": true,
  "message": "Output removed successfully"
}
```

Error:

```json theme={null}
{
  "error": "NOT_AUTHORIZED",
  "message": "App did not add this output"
}
```

### Implementation

* **File**: `packages/cloud/src/routes/streams.routes.ts:142-229`
* **Authorization**: Only the app that added an output can remove it

## List Stream Outputs

Get all restream outputs for a managed stream.

### Endpoint

```
GET /api/streams/:streamId/outputs
```

### Headers

```
X-API-Key: <appApiKey>
X-Package-Name: <packageName>
```

### Parameters

* `streamId`: The managed stream identifier

### Response

```json theme={null}
{
  "streamId": "stream-123",
  "outputs": [
    {
      "outputId": "output-uuid",
      "url": "rtmp://streaming.service.com/live/stream-key",
      "name": "My Stream Output",
      "addedBy": "com.example.app",
      "status": "active",
      "error": null
    }
  ],
  "total": 1,
  "maxPerStream": 10,
  "maxPerApp": 10
}
```

### Implementation

* **File**: `packages/cloud/src/routes/streams.routes.ts:234-307`
* **Authorization**: App must be viewing the stream

### Output Status

Possible status values:

* `active` - Output is streaming
* `connecting` - Attempting to connect
* `error` - Connection failed
* `unknown` - Status unavailable

## Error Codes

| Code | Error                      | Description                        |
| ---- | -------------------------- | ---------------------------------- |
| 400  | INVALID\_URL               | URL is missing or invalid format   |
| 403  | NOT\_A\_VIEWER             | App is not viewing the stream      |
| 403  | NOT\_AUTHORIZED            | App cannot modify this output      |
| 404  | STREAM\_NOT\_FOUND         | Managed stream not found           |
| 404  | OUTPUT\_NOT\_FOUND         | Output ID not found                |
| 409  | MAX\_OUTPUTS\_REACHED      | Stream has maximum outputs (10)    |
| 409  | MAX\_APP\_OUTPUTS\_REACHED | App has maximum outputs (10)       |
| 409  | DUPLICATE\_URL             | URL already exists as output       |
| 502  | CLOUDFLARE\_ERROR          | Cloudflare streaming service error |
| 500  | INTERNAL\_ERROR            | Internal server error              |

## Notes

* Managed streams are created by apps using the SDK
* Apps must be actively viewing a stream to manage outputs
* Each stream supports up to 10 simultaneous outputs
* Each app can add up to 10 outputs across all streams
* Outputs are managed through Cloudflare Stream service
* Only the app that added an output can remove it
