All Products
Search
Document Center

ApsaraVideo Live:CreateRtcMPUEventSub

Last Updated:Jul 15, 2026

Creates an event subscription for stream mixing and relaying.

Operation description

Creates an event subscription for stream mixing and relaying. When you create a subscription, you can configure parameters such as the callback URL, the application to subscribe to, and channel information.

QPS limit

The single-user QPS limit for this operation is 50 calls per second. If the limit is exceeded, API calls are throttled, which may affect your business. Call this operation appropriately.

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 Resource Access Management (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 supports 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 Alibaba Cloud Resource Name (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.

  • 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 to subscribe to. You can view your application IDs by navigating to ApsaraVideo Live > Live+ > ApsaraVideo Real-time Communication > Application Management. If no application exists, create one by clicking Create Application.

Note

The application ID consists of uppercase and lowercase letters, digits, underscores, and hyphens (-), with a maximum of 64 characters.

yourAppId

ChannelIds

string

No

The channel IDs of the stream mixing tasks for which you want to receive callbacks. You can specify multiple channel IDs separated by commas (,).

Note
  • If you leave this parameter empty, callbacks for all stream mixing and relaying tasks under the specified AppId are received by default.

  • When specifying multiple channel IDs, do not include duplicates. You can specify up to 20 channel IDs at a time.

  • Each channel ID consists of uppercase and lowercase letters, digits, underscores, and hyphens (-), with a maximum of 64 characters.

yourChannelIds

CallbackUrl

string

Yes

The callback URL. For the URL format, refer to the callback content specifications below.

Note

The callback URL protocol must be HTTP or HTTPS. The URL can contain only the following characters: a-z, A-Z, 0-9, -, _, ?, %, =, #, ., /, and +. The URL cannot exceed 2083 characters.

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

Callback content example

The callback content is sent to your business server as an HTTP/HTTPS POST request. The character encoding is UTF-8, and the request body is a JSON structure. When your business server responds with an HTTP status code of 200, the callback is considered successful. The following is an example of the callback content:

Note

To determine whether stream mixing and relaying is working properly, use both the callback notifications and the online stream status provided by the corresponding CDN vendor.

{
	"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 callback header contains the following fields:

FieldDescription
Content-TypeThe data type. Fixed value: application/json
Ali-Rtc-TimestampThe timestamp.
Ali-Rtc-SignatureThe signature value.

The callback body contains the following fields:

FieldTypeDescriptionExample
EventTypeIntegerThe callback event type. For stream mixing and relaying callbacks, the value is fixed to 1.1
MsgIdStringThe callback ID that uniquely identifies this callback.*****973C-4529-A334*****
AppIdStringThe ID of the subscribed application.yourAppId
SubIdStringThe subscription ID.Sub-******9799B2C4500******
TaskIdStringThe relay task ID.yourTaskId
CallbackTsIntegerThe timestamp in milliseconds when the callback request is initiated.1712656430476
PayloadJSON ObjectThe callback event information.-
  • Callback event information (Payload)

FieldTypeDescriptionExample
DstUrlStringThe destination URL for relaying.rtmp://domain/app/stream?auth
EventTsIntegerThe timestamp in milliseconds when the callback event occurs.1712656430384
EventCodeIntegerThe callback event code.1
ErrorCodeIntegerThe error code of the callback event.10001
ErrorMessageStringThe error message of the callback event.rtmp server init failed

Callback event codes

FieldValueDescriptionCallback frequency
MPU_STATE_PREPARING0The relay task is created and triggered.Called back only once.
MPU_STATE_ESTABLISHING1The relay task is establishing a connection.Called back every 5 seconds.
MPU_STATE_RUNNING2The relay task is running.Called back only once.
MPU_STATE_RECOVERING3The relay task is interrupted and recovering.Called back every 5 seconds.
MPU_STATE_TERMINATED4The relay task has ended, including normal stop, startup failure, or abnormal exit. The specific reason is indicated by ErrorCode and ErrorMessage.Called back only once.

The following figure shows an example of state transitions for callback events: Note:

  1. Callback messages may arrive at your business server out of order. You can sort events based on EventTs in the Payload. If you only need the latest state of a callback event, ignore subsequently arriving expired events.

  2. For stream mixing and relaying tasks created by calling CreateMixStreamRelayTask (new), the task automatically stops after all users leave the room for a period of time, and an MPU_STATE_TERMINATED callback is sent.

  3. Callback configurations only affect new tasks and do not affect existing tasks:

a. Tasks started before the callback configuration is enabled do not send callbacks.

b. Tasks started after the callback configuration is enabled send callbacks.

c. Tasks started before the callback configuration is deleted continue to send callbacks until the task ends.

d. Tasks started after the callback configuration is deleted do not send callbacks.

Callback error codes

When a relay task ends, the ErrorCode and ErrorMessage indicate the reason for termination.

Error codeError messageDescription
0The task stopped normally.
10001rtmp server init failedConnection establishment failed. The task ended abnormally.
10002rtmp server internal errorAn internal server error occurred. The task ended abnormally.
10003task idle timeoutThe task ended because it was idle for too long.

Callback authentication

Callback event authentication is enabled by default. The authentication logic is as follows:

  • When ApsaraVideo Live initiates a callback request, the HTTP(S) request header contains the Ali-Rtc-Timestamp and Ali-Rtc-Signature fields for signature verification by the callback message receiving server. The Ali-Rtc-Signature value is calculated as follows: Ali-Rtc-Signature=MD5SUM(MD5CONTENT), where MD5CONTENT=Callback URL|Ali-Rtc-Timestamp value|Authentication Key. The callback URL is the complete callback URL that you configured. The authentication key is the AppKey generated when you created the AppId.

  • When the callback message receiving server receives a callback message, it concatenates the callback URL, the Ali-Rtc-Timestamp value, and the authentication key, calculates the MD5 value to obtain an encrypted string, and then compares the calculated encrypted string with the Ali-Rtc-Signature field value in the HTTP(S) request header sent by ApsaraVideo Real-time Communication. If the values do not match, the request is invalid.

Callback retry on failure

When Alibaba Cloud initiates a callback request, the callback is considered successful only when your business server responds with an HTTP status code of 200. If the callback fails, Alibaba Cloud retries 7 times at intervals of 1 second, 2 seconds, 5 seconds, 10 seconds, 1 minute, 2 minutes, and 5 minutes. Each retry generates a corresponding callback record.

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

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

SubId

string

The subscription ID.

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. Parameter verification failed
400 MissingParam %s, please check and try again later. Parameter is missing, please check and try again.
400 InvalidAppId %s, please check and try again later. AppId is invalid, please check and try again.
500 InternalError InternalError
403 OperationDenied Your account has not enabled the Live service
403 Forbidden %s, please check and try again later. No permission, please check and try again.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.