All Products
Search
Document Center

ApsaraVideo Live:CreateRtcMPUEventSub

Last Updated:Jun 12, 2025

Creates a subscription to mixed-stream relay events.

Operation description

You can call this operation to create a subscription to mixed-stream relay events. You can configure parameters such as the callback URL, application to which you want to subscribe, and channel information when you create a subscription.

QPS limit

You can call this operation up to 50 times per second per account. Requests that exceed this limit are dropped and you will experience service interruptions. We recommend that you take note of this limit when you call this operation.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a RAM policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that support authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding ARN in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services. For more information, see Common condition keys.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

live:CreateRtcMPUEventSub

create

*All Resource

*

None

None

Request parameters

Parameter

Type

Required

Description

Example

AppId

string

Yes

The ID of the application.

Note

The ID can be up to 64 characters in length and can contain letters, digits, underscores, and hyphens (-).

yourAppId

ChannelIds

string

No

The ID of the channel to which you want to send mixed-stream relay event callbacks. Separate multiple channel IDs with commas (,).

Note
  • If you leave this parameter empty, you are subscribed to mixed-stream relay events of all channels in the application.

  • You cannot specify duplicate channel IDs. You can specify up to 20 channel IDs in each call.

  • The ID can be up to 64 characters in length and contain letters, digits, underscores (_), and hyphens (-).

yourChannelIds

CallbackUrl

string

Yes

The callback URL.

Note

The callback URL can be up to 2,083 characters in length. You can use headers such as HTTP and HTTPS in callback URLs. The URL can contain letters, digits, and the following special characters: - _ ? % = # . / +

http://****.com/callback

Sample callback

Callbacks are sent to your application server as HTTP or HTTPS POST requests. The request is encoded in UTF-8 and the request body is a JSON struct. The callback request is successful if the HTTP status code 200 is returned. Sample code:

Note We recommend that you check both the callback information and the active stream status provided by your CDN vendor to determine whether the mixed-stream relay task is normal.

{
	"EventType": 1,
	"MsgId": "42bba8b5-94ab-468c-9dae-9b501dd****",
	"AppId": "rtcdev",
	"SubId": "Sub-9799B2C45009799B2*****",
	"TaskId": "mpucallbacktest",
	"CallbackTs": 1712656430476,
	"Payload": {
		"DstUrl": "rtmp://domain/app/stream?auth",
		"EventTs": 1712656430384,
		"EventCode": 1,
		"ErrorCode": 0,
		"ErrorMessage": ""
	}
}

Callback information

The following table describes the fields that are included in the callback header.

Field

Description

Content-Type

The data type. Set the value to application/json.

Ali-Rtc-Timestamp

The timestamp.

Ali-Rtc-Signature

The signature value.

The following table describes the fields that are included in the callback message.

Field

Type

Description

Example

EventType

Integer

The type of the callback event. 1 is returned for mixed-stream relay event callbacks.

1

MsgId

String

The unique ID of the callback.

*****973C-4529-A334*****

AppId

String

The ID of the application.

yourAppId

SubId

String

The ID of the subscription.

Sub-******9799B2C4500******

TaskId

String

The ID of the stream relay task.

yourTaskId

CallbackTs

Integer

The time when the callback request was initiated. The value must be a timestamp in milliseconds.

1712656430476

Payload

JSON Object

The information about the callback event.

-

  • The following table describes the fields in Payload.

Field

Type

Description

Example

DstUrl

String

The destination URL.

rtmp://domain/app/stream?auth

EventTs

Integer

The time when the callback event occurred. The value must be a timestamp in milliseconds.

1712656430384

EventCode

Integer

The callback event code.

1

ErrorCode

Integer

The error code.

10001

ErrorMessage

String

The error message.

rtmp server init failed

Callback event codes

Field

Value

Description

Callback interval

MPU_STATE_PREPARING

0

The stream relay task is created.

Only one callback is fired.

MPU_STATE_ESTABLISHING

1

The stream relay task is being connected.

Every 5 seconds

MPU_STATE_RUNNING

2

The stream relay task is in progress.

Only one callback is fired.

MPU_STATE_RECOVERING

3

The stream relay task is interrupted and being recovered.

Every 5 seconds

MPU_STATE_TERMINATED

4

The stream relay task ends. You can differentiate whether the task is completed, failed to start, or unexpectedly exited based on ErrorCode and ErrorMessage.

Only one callback is fired.

The following flowchart describes the lifecycle of a callback event:image Note:

  1. Callback information may be sent to your business server out of order. You can sort events by using EventTs in Payload. This allows you to ignore callbacks of expired events and helps you obtain the latest callback information.

  2. If you create a mixed-stream relay task by calling the StartLiveMPUTask (new) operation, the task automatically stops when all users in the room leave for a specific period of time. The MPU_STATE_TERMINATED callback is fired when the task stops.

  3. Callback configurations affect only incremental tasks. The following rules apply:

a. No callback is fired for tasks that are created before the callback configurations are set.

b. Callbacks are fired for tasks that are created after the callback configurations are set.

c. Callbacks are fired for tasks that are created before the callback configurations are deleted.

d. No callback is fired for tasks that are created before after the callback configurations are deleted.

Callback error codes

When a stream relay task ends, you can check the cause based on ErrorCode and ErrorMessage.

Error code

Error message

Description

0

The task is completed.

10001

rtmp server init failed

The connection failed to be established.

10002

rtmp server internal error

An internal error occurred and the task failed.

10003

task idle timeout

The task was idle for too long and timed out.

Callback authentication

By default, callback authentication is enabled. The following authentication logic applies:

  • When ApsaraVideo Live initiates a callback request, it includes the Ali-Rtc-Timestamp and Ali-Rtc-Signature headers in the HTTP or HTTPS request so that the callback message receiving server can authenticate the signature. The value of the Ali-Rtc-Signature header is calculated by using the following formula: Ali-Rtc-Signature = MD5SUM(MD5CONTENT). In the formula, MD5CONTENT is a string in the following format: Callback domain name|Ali-Rtc-Timestamp value|Authentication key. The callback domain name is the domain name in the callback URL. The authentication key is the AppKey of the application.

  • After receiving a callback message, the callback message receiving server concatenates the callback domain name, value of the Ali-Rtc-Timestamp header, and authentication key in the preceding format. The server calculates the MD5 value of the string to obtain an encrypted string. Then, the server compares the encrypted string with the value of the Ali-Rtc-Signature header in the HTTP or HTTPS request initiated by Real-Time Communication (RTC). If the two values are different, the request is invalid.

Callback retry

After Alibaba Cloud initiates a callback request, the callback is considered successful only if the HTTP status code 200 is returned by your business server. If a callback fails, ApsaraVideo Live resends the callback request 7 times at intervals of 1 second, 2 seconds, 5 seconds, 10 seconds, 60 seconds, 120 seconds, and 300 seconds. A callback record is generated each time a callback request is resent.

Response parameters

Parameter

Type

Description

Example

object

RequestId

string

The ID of the request.

******3B-0E1A-586A-AC29-742247******

SubId

string

The ID of the subscription.

Sub-******9799B2C4500******

Examples

Success response

JSON format

{
  "RequestId": "******3B-0E1A-586A-AC29-742247******",
  "SubId": "Sub-******9799B2C4500******"
}

Error codes

HTTP status code

Error code

Error message

Description

400

InvalidParam

%s

400

InvalidAppId

%s

500

InternalError

InternalError

403

OperationDenied

Your account has not enabled the Live service

403

Forbidden

%s

404

MissingParam

%s

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.