# Create a live

`POST /api/v1/videos/live`

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": []
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started


Request body: multipart/form-data

Type: object

- `channelId` (required)
  Type: integer
  
  Channel id that will contain this live video

- `saveReplay` (optional)
  Type: boolean

- `replaySettings` (optional)
  Reference: [LiveVideoReplaySettings](https://sourcey-peertube.pages.dev/api-rest-reference/models/livevideoreplaysettings.md); Type: LiveVideoReplaySettings

- `permanentLive` (optional)
  Type: boolean
  
  User can stream multiple times in a permanent live

- `latencyMode` (optional)
  Type: LiveVideoLatencyMode
  
  User can select live latency mode if enabled by the instance
  
  allOf:
    Reference: [LiveVideoLatencyMode](https://sourcey-peertube.pages.dev/api-rest-reference/models/livevideolatencymode.md); Type: LiveVideoLatencyMode
    
    The live latency mode (Default = `1`, High latency = `2`, Small Latency = `3`)
    
    enum: [1,2,3]

- `thumbnailfile` (optional)
  Type: string, binary
  
  Live video/replay thumbnail file

- `previewfile` (optional)
  Type: string, binary
  
  Deprecated in PeerTube v8.1, use thumbnailfile instead
  
  deprecated: true

- `privacy` (optional)
  Reference: [VideoPrivacySet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videoprivacyset.md); Type: VideoPrivacySet
  
  privacy id of the video (see [/videos/privacies](#operation/getVideoPrivacyPolicies))
  
  enum: [1,2,3,4,5]

- `category` (optional)
  Reference: [VideoCategorySet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videocategoryset.md); Type: VideoCategorySet
  
  category id of the video (see [/videos/categories](#operation/getCategories))
  
  Example:
  
  ```json
  15
  ```

- `licence` (optional)
  Reference: [VideoLicenceSet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videolicenceset.md); Type: VideoLicenceSet
  
  licence id of the video (see [/videos/licences](#operation/getLicences))
  
  Example:
  
  ```json
  2
  ```

- `language` (optional)
  Reference: [VideoLanguageSet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videolanguageset.md); Type: VideoLanguageSet
  
  language id of the video (see [/videos/languages](#operation/getLanguages))
  
  Example:
  
  ```json
  "en"
  ```

- `description` (optional)
  Type: string
  
  Live video/replay description

- `support` (optional)
  Type: string
  
  A text tell the audience how to support the creator
  
  Example:
  
  ```json
  "Please support our work on https://soutenir.framasoft.org/en/ <3"
  ```

- `nsfw` (optional)
  Type: boolean
  
  Whether or not this live video/replay contains sensitive content

- `nsfwSummary` (optional)
  Type: any
  
  More information about the sensitive content of the video

- `nsfwFlags` (optional)
  Reference: [NSFWFlag](https://sourcey-peertube.pages.dev/api-rest-reference/models/nsfwflag.md); Type: NSFWFlag
  
  
  NSFW flags (can be combined using bitwise or operator)
  - `0` NONE
  - `1` VIOLENT
  - `2` EXPLICIT_SEX
  
  
  enum: [0,1,2,4]

- `name` (required)
  Type: string
  
  Live video/replay name
  
  minLength: 3
  
  maxLength: 120

- `tags` (optional)
  Type: Array<string>
  
  Live video/replay tags (maximum 5 tags each between 2 and 30 characters)
  
  minItems: 1
  
  maxItems: 5
  
  Items:
    Type: string
    
    minLength: 2
    
    maxLength: 30

- `commentsPolicy` (optional)
  Reference: [VideoCommentsPolicySet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videocommentspolicyset.md); Type: VideoCommentsPolicySet
  
  Comments policy of the video (Enabled = `1`, Disabled = `2`, Requires Approval = `3`)
  
  enum: [1,2,3]

- `recommendationScope` (optional)
  Reference: [VideoRecommendationScopeSet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videorecommendationscopeset.md); Type: VideoRecommendationScopeSet
  
  Videos that can be recommended next to a video:
    - `1` All videos
    - `2` Only videos of the platform that owns the reference video (or of the current platform if no video is given)
    - `3` Only videos of the account that owns the reference video
    - `4` Only videos of the channel of the reference video
  
  This is a preference of the video owner: applications displaying recommendations may not apply it
  
  
  enum: [1,2,3,4]

- `aiUsage` (optional)
  Reference: [VideoAIUsageSet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videoaiusageset.md); Type: VideoAIUsageSet
  
  **PeerTube >= 9.0** Use of AI in the video, declared by the video creator:
    - `1` Not specified
    - `2` No AI-generated content: nothing seen or heard in the video has been generated by AI
    - `3` Contains AI-generated content: some parts of the video have been generated by AI
    - `4` AI-generated: the whole video, or most of it, has been generated by AI
  
  
  enum: [1,2,3,4]

- `commercialContent` (optional)
  Reference: [VideoCommercialContentSet](https://sourcey-peertube.pages.dev/api-rest-reference/models/videocommercialcontentset.md); Type: VideoCommercialContentSet
  
  **PeerTube >= 9.0** Commercial content in the video, declared by the video creator:
    - `1` None
    - `2` Promotional content: the creator promotes their own products, services or business
    - `3` Paid partnership: a third party paid, or provided goods or services, in exchange for the promotion
  
  
  enum: [1,2,3]

- `downloadEnabled` (optional)
  Type: boolean
  
  Enable or disable downloading for the replay of this live video

- `schedules` (optional)
  Type: Array<LiveSchedule>
  
  Items:
    Reference: [LiveSchedule](https://sourcey-peertube.pages.dev/api-rest-reference/models/liveschedule.md); Type: LiveSchedule

Responses:

- 200: successful operation

Content type: application/json

Type: VideoUploadResponse

Schema: [VideoUploadResponse](https://sourcey-peertube.pages.dev/api-rest-reference/models/videouploadresponse.md)

- `video` (optional)
  Type: object
  
  - `id` (optional)
    Reference: [id](https://sourcey-peertube.pages.dev/api-rest-reference/models/id.md); Type: id
    
    object id for the video
  
  - `uuid` (optional)
    Type: UUIDv4
    
    universal identifier for the video, that can be used across instances
    
    allOf:
      Reference: [UUIDv4](https://sourcey-peertube.pages.dev/api-rest-reference/models/uuidv4.md); Type: UUIDv4, uuid
      
      minLength: 36
      
      maxLength: 36
      
      pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
      
      Example:
      
      ```json
      "9c9de5e8-0a1e-484a-b099-e80766180a6d"
      ```
  
  - `shortUUID` (optional)
    Reference: [shortUUID](https://sourcey-peertube.pages.dev/api-rest-reference/models/shortuuid.md); Type: shortUUID

- 400: Disambiguate via `code`:
- default type for a validation error
- `live_conflicting_permanent_and_save_replay` for conflicting parameters set


- 403: Disambiguate via `code`:
- `live_not_enabled` for a disabled live feature
- `live_not_allowing_replay` for a disabled replay feature
- `max_instance_lives_limit_reached` for the absolute concurrent live limit
- `max_user_lives_limit_reached` for the user concurrent live limit


## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/videos/live' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  --form-string 'channelId=0' \
  --form-string 'saveReplay=true' \
  --form-string 'replaySettings={"privacy":1}' \
  --form-string 'permanentLive=true' \
  --form-string 'privacy=1' \
  --form-string 'category=15' \
  --form-string 'licence=2' \
  --form-string 'language=en' \
  --form-string 'description=string' \
  --form-string 'support=Please support our work on https://soutenir.framasoft.org/en/ <3' \
  --form-string 'nsfw=true' \
  --form-string 'nsfwFlags=0' \
  --form-string 'name=string' \
  --form-string 'tags=string' \
  --form-string 'commentsPolicy=1' \
  --form-string 'recommendationScope=1' \
  --form-string 'aiUsage=1' \
  --form-string 'commercialContent=1' \
  --form-string 'downloadEnabled=true' \
  --form-string 'schedules={"startAt":"2024-01-15T09:30:00Z"}'
```

### JavaScript

```javascript
const form = new FormData();
form.append('channelId', '0');
form.append('saveReplay', 'true');
form.append('replaySettings', '{"privacy":1}');
form.append('permanentLive', 'true');
form.append('privacy', '1');
form.append('category', '15');
form.append('licence', '2');
form.append('language', 'en');
form.append('description', 'string');
form.append('support', 'Please support our work on https://soutenir.framasoft.org/en/ <3');
form.append('nsfw', 'true');
form.append('nsfwFlags', '0');
form.append('name', 'string');
form.append('tags', 'string');
form.append('commentsPolicy', '1');
form.append('recommendationScope', '1');
form.append('aiUsage', '1');
form.append('commercialContent', '1');
form.append('downloadEnabled', 'true');
form.append('schedules', '{"startAt":"2024-01-15T09:30:00Z"}');
const response = await fetch('https://peertube2.cpy.re/api/v1/videos/live', {
  method: 'POST',
  headers: {"Authorization":"Bearer YOUR_TOKEN"},
  body: form,
});
console.log(await response.text());
```

### Python

```python
import requests
from contextlib import ExitStack

with ExitStack() as stack:
    files = [
        ('channelId', (None, '0')),
        ('saveReplay', (None, 'true')),
        ('replaySettings', (None, '{"privacy":1}')),
        ('permanentLive', (None, 'true')),
        ('privacy', (None, '1')),
        ('category', (None, '15')),
        ('licence', (None, '2')),
        ('language', (None, 'en')),
        ('description', (None, 'string')),
        ('support', (None, 'Please support our work on https://soutenir.framasoft.org/en/ <3')),
        ('nsfw', (None, 'true')),
        ('nsfwFlags', (None, '0')),
        ('name', (None, 'string')),
        ('tags', (None, 'string')),
        ('commentsPolicy', (None, '1')),
        ('recommendationScope', (None, '1')),
        ('aiUsage', (None, '1')),
        ('commercialContent', (None, '1')),
        ('downloadEnabled', (None, 'true')),
        ('schedules', (None, '{"startAt":"2024-01-15T09:30:00Z"}')),
    ]
    response = requests.request('POST', 'https://peertube2.cpy.re/api/v1/videos/live', headers={"Authorization":"Bearer YOUR_TOKEN"}, files=files)
    print(response.text)
```
