# Update template (/en/api-reference/api-ref/rtmp-gateway/update-template)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Updates an existing Media Gateway flow configuration template.

- OpenAPI: /openapi/media-gateway/media-gateway.en.yaml
- Operation ID: update-media-gateway-template
- Method: PATCH
- Path: /{region}/v1/projects/{appId}/rtls/ingress/stream-templates/{templateId}
- Endpoint: https://api.agora.io/{region}/v1/projects/{appId}/rtls/ingress/stream-templates/{templateId}

## Servers

- https://api.agora.io

This method updates a flow configuration template.


:::info[Note]
- The parameters supported for the update are the following: `transcoding.video`, `transcoding.audio`, and `jitterBuffer`. This means that, for example, if you only want to update the `fps` field of `transcoding.video`, you need to pass in the entire `transcoding.video` field with the modified `fps` field and other fields unchanged.
- `transcoding.video`, `transcoding.audio`, and `jitterBuffer` are independent of each other. If only `transcoding.video` is passed in, then only its parameters will be updated and the parameters of `transcoding.audio` and `jitterBuffer` will not be affected.
:::

:::info[Note]
- This interface can only be called if the flow configuration template already exists.
- Modifications to a flow configuration template will only take effect after the stream is re-pushed. Considering the synchronization delay between the gateway and the database, wait 3 minutes after calling this interface before re-pushing the stream.
:::

## Authorization

This endpoint requires authentication.

- `basicAuth`
- `hmacAuth`

## Parameters

- `region` (path, required, string) - Region for the streaming key or stream. Supported values are `na` for North America, `eu` for Europe, `ap` for Asia except mainland China, and `cn` for mainland China.
  - Allowed: `na` | `eu` | `ap` | `cn`

  :::warning[Important]
  Make sure that:
  
  - The `region` value is the same as for the input source stream.
  - The domain names for setting the `region` parameter and streaming are the same.
  - The `region` value is in lowercase.
  :::
- `appId` (path, required, string) - The app ID provided by Agora to each developer. After creating a project in Agora Console, you can get an app ID. The app ID is a unique identifier for a project.
- `templateId` (path, required, string) - The flow configuration template ID. The value can contain only lowercase letters, uppercase letters, and numbers, and cannot exceed 12 bytes. Set the value according to your business use case. For example, use `"720p"` and `"1080p"` for different target resolutions, or `"gameA"` and `"gameB"` for different game use cases.
  - Example: `720p`
  - Max length: `12`
  - Pattern: `^[A-Za-z0-9]+$`
- `X-Request-ID` (header, optional, string) - The UUID (Universally Unique Identifier) of the request. After you pass in this field, the Agora server returns this field in the response header. It is recommended to assign `X-Request-ID` a value. If omitted, the Agora server automatically generates a UUID and returns it.
  - Example: `6d35d43f-f4c5-4b3a-9df4-8f0d7e1d5f0a`

## Request body

- `settings` (object, required)

  :::info[Note]
  To ensure a successful request, do not set the required fields to `null` or leave them empty.
  :::
  - `settings.transcoding` (object, required) - Audio and video transcoding configuration.
    - `settings.transcoding.video` (object)
      - `settings.transcoding.video.enabled` (boolean) - Whether to enable video transcoding.
        - Default: `false`
      - `settings.transcoding.video.mode` (string) - Video transcoding mode. `force` forces transcoding. `adaptive` enables transcoding when the source stream contains B-frames.
        - Allowed: `force` | `adaptive`
        - Default: `force`
      - `settings.transcoding.video.codec` (string) - Codec format for transcoding.
        - Allowed: `H.264` | `VP8`
        - Default: `H.264`
      - `settings.transcoding.video.width` (integer) - Encoding width of the main stream in pixels. If not specified or set to `0`, the source stream width is used unless `height` is set.
        - Range: `[0, 3840]`

        :::info[Note]
        If the ABR function is enabled, this field is required.
        :::
      - `settings.transcoding.video.height` (integer) - Encoding height of the main stream in pixels. If not specified or set to `0`, the source stream height is used unless `width` is set.
        - Range: `[0, 3840]`

        :::info[Note]
        If the ABR function is enabled, this field is required.
        :::
      - `settings.transcoding.video.fps` (integer) - Video encoding frame rate in fps. If not specified or set to `0`, the source stream frame rate is used.
        - Range: `[0, 60]`
      - `settings.transcoding.video.bitrate` (integer) - Encoding bitrate of the main stream in Kbps. If omitted, the source stream bitrate is used. If set to `0`, Agora automatically chooses a bitrate based on width and height.
        - Range: `[0, 20000]`

        :::info[Note]
        If you enable low-speed streaming (provide the following `simulcastStream` object), this field is required. If you do not enable low-speed streaming, it is recommended to use the automatically matched bitrate without setting the bitrate yourself.
        :::
      - `settings.transcoding.video.advancedOptions` (object)
        - `settings.transcoding.video.advancedOptions.pvc` (object)
          - `settings.transcoding.video.advancedOptions.pvc.enabled` (boolean) - Whether to enable PVC.
            - Default: `false`
          - `settings.transcoding.video.advancedOptions.pvc.saveBitrateRatio` (integer) - Bitrate saving ratio for PVC. For example, `20` means saving 20 percent of the bitrate. This parameter is effective only when `video.bitrate` is missing or `0`.
        - `settings.transcoding.video.advancedOptions.superResolution` (object)
          - `settings.transcoding.video.advancedOptions.superResolution.enabled` (boolean) - Whether to enable Super Resolution.
            - Default: `false`
          - `settings.transcoding.video.advancedOptions.superResolution.alphaBlending` (integer) - Super Resolution intensity. Larger values indicate higher intensity.
            - Default: `128`
            - Range: `[1, 256]`
      - `settings.transcoding.video.simulcastStream` (object) - Low-quality video stream configuration. If provided, Media Gateway enables the low-quality stream and uses these transcoding parameters.
        - `settings.transcoding.video.simulcastStream.width` (integer) - Width in pixels. The value must be less than `video.width`. If omitted or set to `0`, `video.width / 2` is used.
          - Range: `[0, 3840]`
        - `settings.transcoding.video.simulcastStream.height` (integer) - Height in pixels. The value must be less than `video.height`. If omitted or set to `0`, `video.height / 2` is used.
          - Range: `[0, 3840]`
        - `settings.transcoding.video.simulcastStream.fps` (integer) - Frame rate in fps. The value must be less than or equal to `video.fps`. If omitted or set to `0`, the default value is `15`.
          - Default: `15`
          - Range: `[0, 60]`
        - `settings.transcoding.video.simulcastStream.bitrate` (integer) - Bitrate of the low-quality video stream in Kbps. The value must be less than `video.bitrate`. If omitted or set to `0`, Agora chooses an appropriate bitrate based on resolution and fps.

          :::info[Note]
          When enabling the low-quality stream and specifying low-quality `bitrate`, you need to specify `video.bitrate` at the same time.
          :::
      - `settings.transcoding.video.simulcastStreamLayers` (array) - Layer transcoding parameters for adaptive bitrate. If specified, ABR is enabled.

        :::info[Note]
        - You can set either `simulcastStream` or `simulcastStreamLayer`. If you set both, `simulcastStream` setting does not take effect.
        
        - For resolution and bitrate settings for main and ABR streams, recommended values, and viewer subscription settings, refer to [Adaptive bitrate (beta)](/en/realtime-media/rtmp-gateway/build/process-media/enable-adaptive-bitrate).
        :::
        - `settings.transcoding.video.simulcastStreamLayers.items` (object)
          - `settings.transcoding.video.simulcastStreamLayers.items.id` (integer, required) - Layer ID.
            - Range: `[1, 7]`
          - `settings.transcoding.video.simulcastStreamLayers.items.width` (integer) - Encoding width of the layer in pixels. If specified, this value must be smaller than `video.width` and decrease monotonically as layer ID increases.
          - `settings.transcoding.video.simulcastStreamLayers.items.height` (integer) - Encoding height of the layer in pixels. If specified, this value must be smaller than `video.height` and decrease monotonically as layer ID increases.
          - `settings.transcoding.video.simulcastStreamLayers.items.fps` (integer) - Encoding frame rate of the layer in fps. If specified, this value must be smaller than `video.fps`. If omitted or set to `0`, the main stream frame rate is used.
          - `settings.transcoding.video.simulcastStreamLayers.items.bitrate` (integer, required) - Encoding bitrate of the layer in Kbps. This value must be smaller than `video.bitrate` and decrease monotonically by layer ID.
    - `settings.transcoding.audio` (object)
      - `settings.transcoding.audio.enabled` (boolean) - Whether to enable audio transcoding.
        - Default: `true`
      - `settings.transcoding.audio.profile` (integer) - Encoded audio use case. The default value `0` means 48 KHz sampling rate, music encoding, mono, and a maximum encoding rate of 64 Kbps. Contact Agora technical support for other profile settings.
        - Default: `0`
      - `settings.transcoding.audio.bitrate` (integer) - Audio encoding bitrate in Kbps. If omitted, the value is determined by `profile`.
        - Range: `[64, 320]`
  - `settings.jitterBuffer` (object) - Network jitter buffer. Takes effect only when video transcoding is enabled.
    - `settings.jitterBuffer.size` (integer) - Maximum buffer length in ms. Media Gateway adds this value to the end-to-end delay to reduce lag caused by network jitter.
      - Default: `500`
    - `settings.jitterBuffer.maxSize` (integer) - Maximum buffer length in ms. This value must be greater than `jitterBuffer.size`. When the jitter buffer exceeds this value, Media Gateway enables acceleration until it returns to `jitterBuffer.size`.
      - Default: `1000`

### Request body example

```json
{
  "settings": {
    "transcoding": {
      "video": {
        "enabled": true,
        "codec": "H.264",
        "width": 1280,
        "height": 720,
        "fps": 24,
        "bitrate": 2200,
        "simulcastStream": {
          "width": 960,
          "height": 540,
          "fps": 24,
          "bitrate": 1670
        }
      }
    }
  }
}
```

## Request examples

### curl

```bash
curl --location -g --request PUT 'https://api.agora.io/{{region}}/v1/projects/{{appId}}/rtls/ingress/stream-templates/{{templateId}}' \
--data '
{
    "settings": {
        "transcoding": {
            "video": {
                "enabled": true,
                "codec": "H.264",
                "width": 1280,
                "height": 720,
                "fps": 24,
                "bitrate": 2200,
                "simulcastStream": {
                    "width": 960,
                    "height": 540,
                    "fps": 24,
                    "bitrate": 1670
                }
            }
        }
    }
}'
```


## Responses

### 200

The request succeeded and updated the template.

- `status` (string) - The status of this request. `success` means the request succeeds.
### 401

The request failed. A `401 (Unauthorized)` response status code means the request is not authorized.

- `status` (string) - Request status.
- `message` (string) - Description of why the request failed.
### default

The request failed. A `401 (Unauthorized)` response status code means the request is not authorized.

- `status` (string) - Request status.
- `message` (string) - Description of why the request failed.

## Response examples

### 200

```json
{
  "status": "success"
}
```
### 401

```json
{
  "status": "error",
  "message": "Describes why the request failed."
}
```
### default

```json
{
  "status": "error",
  "message": "Describes why the request failed."
}
```
