All Products
Search
Document Center

ApsaraVideo Live:CreateEventSub

Last Updated:Jan 14, 2026

Creates a callback to subscribe to channel or user events.

Operation description

You can call this operation to create a callback to subscribe to channel or user events. When you create a callback, you can configure parameters such as the callback URL and event type.

QPS limit

You can call this operation up to 100 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 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:CreateEventSub

*Rtc

acs:live::{#accountId}:rtc/{#AppId}

None None

Request parameters

Parameter

Type

Required

Description

Example

AppId

string

Yes

The application ID.

9qb1****

ChannelId

string

No

The channel ID. You can call the ListEventSub operation to query the channel ID.

Note
  • This parameter is required if you specify the Users.N parameter.

  • If you set this parameter to * or do not specify this parameter, all channels are subscribed to.

  • Each application ID allows only one all-channel subscription.

123333

Users

array

No

The user whose events you want to subscribe to. If you leave this parameter empty, the events of all users in the channel are subscribed to, including the events of the streamer and viewers. Specify this parameter in the following format:

Users.1=****
Users.2=****
......

string

No

The user ID.

user1

Events

array

Yes

Subscribe to events.

string

Yes

The type of the event. Valid values:

  • ChannelEvent: channel events.

  • UserEvent: user events in the channel.

ChannelEvent

CallbackUrl

string

Yes

The callback URL. For more information about the content of the messages that are sent to the callback URL, see the Callback section in this topic.

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

CallBack

Callback messages are sent to the callback URL that is specified by the CallbackUrl parameter. The following sample code provides an example:

Request:

POST /callbackURL

Body
application/json

{
    "MsgId": "Message ID",
    "MsgTimestamp": 12312324, // The UNIX timestamp when the message was sent.
    "SubscribeID": "Subscription ID",
    "AppId":"",     // The ID of the application in which the message was generated.
    "ChannelID":"", // The ID of the channel in which the message was generated.
    "Contents": [
      {
        "Event": "UserEvent",// The type of the event that is subscribed to. In this case, the type is user event.
        "UserEvent": {
          "UserId": "80331631628*****",    // The user ID.
          "EventTag": "Publish",    // The event. Valid values: Join, Leave, Publish, Unpublish, and Roleupdate.
          "SessionId": "0dr15rrnhkz0jnvz6o8sxo0*****", // The ID of the session in which the event was generated.
          "Timestamp": 1609854786,    // The UNIX timestamp when the event occurred.
          "Reason": 1, // The reason for joining or leaving the channel. This parameter is available only if the event is a Join event.
          "Role": 1, // The role of the user. The roles include streamer and viewer.
          "CurrentMedias":"1,2,3"// The types of the streams that were ingested by the user.
        }
      },
      {
        "Event": "ChannelEvent",// The type of the event that is subscribed to. In this case, the type is channel event.
        "ChannelEvent": {
          "ChannelId": "88888****",
          "EventTag": "Open",   // The event. Valid values: Open and Close.
          "Timestamp": 1609854530 // The UNIX timestamp when the event occurred.
        }
      }
   ]
}

Response 
HTTP STATUS 200

Parameters of a user event

ParameterTypeRequiredDescription
UserIdstringYesThe user ID.
SessionIdstringYesThe session ID.
EventTagstringYesThe event. Valid values:Join: The user joined the channel.Leave: The user left the channel.PublishVideo: The user ingested a video stream.PublishAudio: The user ingested an audio stream.PublishScreen: The user ingested a stream for screen sharing.UnpublishVideo: The user stopped ingesting a video stream.UnpublishAudio: The user stopped ingesting an audio stream.UnpublishScreen: The user stopped ingesting a stream for screen sharing.Roleupdate: The role of the user was changed.
TimestampnumberYesThe timestamp when the event occurred.
ReasonintegerYesThe reason for joining or leaving the channel. This parameter is available only if the event is a Join event. Valid values:1: The user joined or left the channel as needed.2: The user reconnected to join the channel again when the user was already in the channel.3: The user performed stream relay across channels.4: The user left the channel due to a timeout.5: The user started a new session and was forced to go offline in the current session.6: The user was kicked out of the channel.7: The channel was closed.
RoleintegerYesThe role of the user. Valid values:1: streamer2: viewer
CurrentMediasintegerYesThe type of the stream. Valid values:1: audio2: video3: screen sharing

Parameters of a channel event

ParameterTypeRequiredDescription
EventTagstringYesThe event. Valid values:Open: The channel was opened.Close: The channel was closed.
TimestampnumberYesThe timestamp when the event occurred.

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 Ali-Rtc-Timestamp is calculated based on 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.

Exception handling

A keep-alive mechanism is implemented between clients that have joined a channel or started stream ingest and the Alibaba Cloud server. If the server does not receive heartbeat information from a client for 90 seconds, the server considers that the client timed out and the user left the channel and then fires callbacks. Heartbeats fail to be detected if a network disconnection occurs or the application accidentally exits.

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The request ID.

760bad53276431c499e30dc36f6b****

SubscribeId

string

The subscription ID.

ad53276431c****

Examples

Success response

JSON format

{
  "RequestId": "760bad53276431c499e30dc36f6b****",
  "SubscribeId": "ad53276431c****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InputInvalid %s. Illegal input parameters
400 QuotaLimitError %s. For each AppId, a maximum of 20 subscriptions are allowed at the same time, and only one full channel subscription is allowed.
400 ErrorInvalidCallBackUrl %s. The CallBackURL is invalid, please check and try again.
500 ServerError %s. Unknown error, please try again later or submit a ticket for consultation.
403 NoAuth %s. No permission
404 ResourceNotExist %s. The requested resource does not exist, please check and try again

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.