Skip to main content

REST quickstart

Cloud Recording enables you to record and store real-time audio and video streams from channels. To implement Cloud Recording, you set up a self-hosted backend that interacts with Agora servers to manage recording tasks. This guide introduces the essential Cloud Recording RESTful APIs you use to manage the recording process.

info

The command-line examples in this guide are for demonstration purposes only. Do not use them directly in a production environment. Implement RESTful API requests through your application server or use Agora's Go backend middleware. For details, see Quickstart using middleware

Understand the tech

The basic process of implementing Cloud Recording is as follows:

  1. Get a resource ID

    Before starting a cloud recording, call the acquire method to obtain a cloud recording resource ID. After calling this method successfully, you get a resource ID in the response body.

  2. Start cloud recording

    Call the start method to join the channel and start a cloud recording. After calling this method successfully, you get a recording ID from the response body to identify the current recording process.

  3. Query the recording status

    Call the query method to check the recording status during the recording.

  4. Stop cloud recording

    Call the stop method to stop the cloud recording.

  5. Upload the recording file

    After the recording ends, the cloud recording service uploads the recording file to the third-party cloud storage you specify.

Prerequisites

To implement Cloud Recording, ensure that you have:

  • A valid Agora account and project. Obtain the following parameters from Agora Console:

  • Set up and enabled a supported third-party cloud storage service. Obtain the following parameters for your storage:

    • Bucket name
    • Access key
    • Secret key
    Supported third-party cloud storage services
  • Enabled the Agora Cloud Recording service for your project.

    Steps to enable cloud recording
    1. Log in to Agora Console, and click the Project Management icon on the left navigation panel.
    2. On the Project Management page, find the project for which you want to enable the cloud recording service, and click the edit icon.
    3. On the Edit Project page, find Cloud Recording, and click Enable. On the following screen, click Enable Cloud Recording.
    4. Click Apply. Now, you can use Agora Cloud Recording and see the usage statistics in the Usage page.
  • If your network has a firewall, follow the instructions in Firewall Requirements.

Implement cloud recording

The following figure shows the API call sequence to start and manage cloud recording:

The following APIs are optional and can be called multiple times. However, they must be called during a recording session, that is, after recording starts and before it ends:

Use basic HTTP authentication

The Cloud Recording RESTful APIs require basic HTTP authentication. You need to set the Authorization parameter in every HTTP request header. For details, see Basic HTTP authentication.

Get a resource ID

Call the acquire method to request a resource ID for Cloud Recording.

After calling this method successfully, you receive a resource ID in the response body. The resource ID is valid for five minutes. Start recording with this resource ID within the validity period. One resource ID can only be used for a single recording session.

  • The recording service is equivalent to a non-streaming client in the channel. The uid parameter in the request body is used to identify the recording service and cannot be the same as any existing user ID in the channel. For example, if there are two users already in the channel and their user IDs are 123 and 456, the uid cannot be "123" or "456".

  • Agora Cloud Recording does not support user IDs in string format (User Accounts). Ensure that every user in the channel has an integer user ID. The string content of the uid parameter must also be an integer.

Sample code

For testing purposes, use the following command in the terminal to call the acquire method.


_12
# Replace <appid> with the App ID of your Agora project
_12
curl --location --request POST 'https://api.agora.io/v1/apps/<appid>/cloud_recording/acquire' \
_12
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
_12
--header 'Authorization: Basic <Authorization>' \
_12
--header 'Content-Type: application/json' \
_12
--data-raw '{
_12
# Replace <YourChannelName> with the name of the channel you need to record
_12
"cname": "<YourChannelName>",
_12
# Replace <YourRecordingUID> with your user ID
_12
"uid": "<YourRecordingUID>",
_12
"clientRequest":{}
_12
}'

Start recording

Call the start method within five minutes of getting a resource ID to join a channel and start recording. You can choose either individual recording or composite recording as the recording mode.

If this method call succeeds, you receive a recording ID (sid) in the HTTP response body. This ID identifies the current recording.

info

After you obtain the recording ID sid, you can call the query, updateLayout, and stop methods before the time set (in hours) by resourceExpiredHour has passed.

Sample code

For testing purposes, use the following command in the terminal to call the start method.


_30
# Replace <appid> with the App ID of your Agora project
_30
# Replace <resourceid> with the resource ID obtained through the acquire method
_30
# Replace "<mode>" with "individual" for individual recording or "composite" for composite recording
_30
curl --location --request POST 'https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/mode/<mode>/start' \
_30
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
_30
--header 'Authorization: Basic <Authorization>' \
_30
--header 'Content-Type: application/json' \
_30
--data-raw '{
_30
# Replace <YourChannelName> with the name of the channel you need to record.
_30
"cname": "<YourChannelName>",
_30
# Replace <YourRecordingUID> with your user ID that identifies the recording service.
_30
"uid": "<YourRecordingUID>",
_30
"clientRequest": {
_30
# Replace <YourToken> with the temporary token you obtain from the console.
_30
"token": "<YourToken>",
_30
# Set the storageConfig related parameters.
_30
"storageConfig": {
_30
"secretKey": "<YourSecretKey>",
_30
"vendor": 0,
_30
"region": 0,
_30
"bucket": "<YourBucketName>",
_30
"accessKey": "<YourAccessKey>"
_30
},
_30
# Set the recordingConfig related parameters.
_30
"recordingConfig": {
_30
# Which is consistent with the "channelType" of the Agora <Vg k="VSDK" />.
_30
"channelType": 0
_30
}
_30
}
_30
}'

Query recording status

During a recording session, can call the query method to query the recording status. You can call this API multiple times.

When you call this method successfully, you receive the current recording status and related information about the recording file in the response body. See Best Practices in Integrating Cloud Recording for details about how to Monitor service status during a recording and Obtain the M3U8 file name.

Sample code

For testing purposes, use the following command in the terminal to call the query method.


_8
# Replace <appid> with the App ID of your Agora project
_8
# Replace <resourceid> with the resource ID obtained through the acquire method
_8
# Replace <sid> with the sid obtained through the start method
_8
# Replace "<mode>" with "individual" for individual recording or "composite" for composite recording
_8
curl --location --request GET 'https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/sid/<sid>/mode/<mode>/query' \
_8
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
_8
--header 'Authorization: Basic <Authorization>' \
_8
--header 'Content-Type: application/json'

Stop recording

Call the stop API to end the recording session.

When you call this method successfully, you receive the status of the recording file upload and information about the recording file in the response body.

Sample code

For testing purposes, use the following command in the terminal to call the stop method.


_17
# Replace <appid> with the App ID of your Agora project
_17
# Replace <resourceid> with the resource ID obtained through the acquire method
_17
# Replace <sid> with the sid obtained through the start method
_17
# Replace "<mode>" with "individual" for individual recording or "composite" for composite recording
_17
curl --location --request POST
_17
'https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/sid/<sid>/mode/<mode>/stop' \
_17
--header 'Content-Type: application/json;charset=utf-8' \
_17
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
_17
--header 'Authorization: Basic <Authorization>' \
_17
--data-raw '{
_17
# Replace <YourRecordingUID> with your user ID that identifies the recording service.
_17
"uid": "<YourRecordingUID>",
_17
# Replace <YourChannelName> with the name of the channel you are recording.
_17
"cname": "<YourChannelName>",
_17
"clientRequest":{
_17
}
_17
}'

Parameter settings
  • If the uid parameter in the request body is the same as a user ID in the channel, or if you use a non-integer user ID, the recording fails. For details, see the notes on the uid parameter in the section Get a cloud recording resource.
  • When the start request returns 200, it only means that the RESTful API request is successful. To ensure that the recording has started successfully and continues normally, call query to check the recording status. Errors such as unreasonable transcodingConfig parameter settings, incorrect third-party cloud storage information, or incorrect token information cause the query method to return 404. See Why do I get a 404 error when I call query after successfully starting a cloud recording? .
  • Set the maxIdleTime parameter based on your business needs. Within the time range set by maxIdleTime, the recording continues and billing is generated even if the channel is idle.

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

Sample project

Agora provides a Postman collection, which contains sample requests of RESTful API for a cloud recording. You can use the collection to quickly grasp the basic functionalities of the Cloud Recording RESTful APIs. You only need to import the collection to Postman and set your environment variables.

You can also use Postman to generate code snippets written in various programming languages. To do so, select a request, click Code, and select the desired language in GENERATE CODE SNIPPETS.

img

See also

  • To streamline the use of Agora RESTful APIs within your infrastructure, see Quickstart using middleware. The community middleware project provides RESTful APIs for tasks such as token generation and cloud recording management.

Next steps

Manage recorded files

After the recording starts, the Agora server splits the recorded content into multiple TS/WebM files and keeps uploading them to the third-party cloud storage until the recording stops. You can refer to Manage Recorded Files to learn about the naming rules, file sizes, and slicing rules of recording files.

Token authentication

To ensure communication security, in a formal production environment, you need to generate tokens on your app server. See Authenticate Your Users with Token.

vundefined