Acquire a builder token
Acquire a builder token
https://api.sd-rtn.com/v1/projects/{appId}/rtsc/cloud-transcoder/builderTokens
Before you create a Cloud Transcoding task, call the builderTokens
endpoint to retrieve a builder token.
Request
Path parameters
The App ID of your project from Agora Console.
Request body
BODYrequired
- instanceId stringrequired
User-specified instance ID. The length must be within 64 characters. The supported character sets are:
- All lowercase English letters (a-z)
- All capital letters (A-Z)
- Numbers 0-9
-
,_
An
instanceId
can generate multiple builder tokens, but only one token can be used to initiate a request in a task. - services objectrequired
Show propertiesHide properties
- cloudTranscoder objectrequired
Show propertiesHide properties
- serviceType stringrequired
The service type. Use
"cloudTranscoderV2"
. - config objectrequired
Show propertiesHide properties
- transcoder objectrequired
Show propertiesHide properties
- idleTimeout numbernullable
Default:
300
Possible values:
1 to 86400
The maximum period (in seconds) that Cloud Transcoder can be idle. Idle means that all hosts corresponding to the audio and video streams processed by Cloud Transcoder have left the channel. If the idle state exceeds the set time, Cloud Transcoder is automatically destroyed.
- streamProcessMode stringnullable
Default:
mix
If this parameter is not specified, the working mode of Cloud transcoder is the merge mode. You can specify the following modes:
heterogeneous-single
: Heterogeneous single stream mode. The types of input stream and output stream can be different or the same. The currently supported stream types are RTC and CDN.single
: RTC stream relay mode. Relays the host's audio and video data and signaling in the source channel to the destination channel.
info-
If you set
streamProcessMode
toheterogeneous-single
orsingle
, then theaudioInputs
orvideoInputs
list may contain at most one item. -
If you need to mix audio, combine images, or mix audio and combine images, no
streamProcessMode
settings are required.
- audioInputs arraynullable
Audio input source list, supports two types: RTC audio stream and CDN audio stream. If you specify multiple input audio sources, the streams are mixed.
infoEitherrtc
orstreamUrl
must be filled in.Show propertiesHide properties
- streamUrl stringnullable
The URL of the audio source stream. Required when the audio input source is CDN.
- volume numbernullable
Default:
100
Possible values:
0 to 200
The volume of the audio source stream. This parameter only takes effect when the audio input source is CDN.
- repeat numbernullable
Default:
1
The number of times to play the media stream. This parameter only takes effect when the audio input source is CDN.
1
: Play the media stream once.-1
: Play the media stream in a loop.n
: Specify the number of times to play the media stream. Cannot be set to 0.
- rtc objectnullable
When the audio input source is RTC, this object is required.
Show propertiesHide properties
- rtcChannel stringrequired
The RTC channel name for the audio input source. Currently, only audio and video sources that subscribe to a single channel are supported. The audio source and video source must belong to the same channel.
- rtcUid numberrequired
The UID corresponding to the audio input source. The same UID must not exist in the RTC channel.
- rtcToken stringrequired
The token that the Cloud Transcoder uses to join the RTC channel for transcoding. Using a token ensures channel security and prevents malicious users from disrupting other users in the channel. See Token authentication for details.
The UID of Cloud Transcoder in the RTC channel is randomly assigned by Agora. Therefore, when generating a token, set the uid to
0
.
- videoInputs arraynullable
Video input source list, supports RTC video stream and CDN video stream. If you specify multiple input video sources, the streams are merged.
Show propertiesHide properties
- streamUrl stringnullable
The URL of the video source stream. Required when the video input source is CDN.
- repeat numbernullable
Default:
1
The number of times to play the media stream. This parameter only takes effect when the input source is CDN.
1
: Play the media stream once.-1
: Play the media stream in a loop.n
: Specify the number of times to play the media stream. Cannot be set to 0.
- rtc objectnullable
This object is required when the video input source is RTC.
Show propertiesHide properties
- rtcChannel stringrequired
The RTC channel name for the video input source. Currently, only audio and video sources that subscribe to a single channel are supported. The audio source and video source must belong to the same channel.
- rtcUid numberrequired
The UID corresponding to the video input source. The same UID must not exist in the RTC channel.
- rtcToken stringrequired
The token that the Cloud Transcoder uses to join the RTC channel for transcoding. Using a token ensures channel security and prevents malicious users from disrupting other users in the channel. See Token authentication for details.
The UID of Cloud Transcoder in the RTC channel is randomly assigned by Agora. Therefore, when generating a token, set the uid to
0
.
- placeholderImageUrl stringnullable
The URL of the placeholder image displayed when the user is offline. It must be a valid image URL and contain the
jpg
orpng
suffix. - region objectrequired
Show propertiesHide properties
- x numberrequired
Possible values:
0 to 3840
The x coordinate of the image on the canvas (px). The x coordinate is the horizontal displacement of the upper left corner of the image relative to the origin, where the upper left corner of the canvas is the origin.
- y numberrequired
Possible values:
0 to 3840
The y coordinate of the image on the canvas (px). The y coordinate is the vertical displacement of the upper left corner of the image relative to the origin, where the upper left corner of the canvas is the origin.
- width numberrequired
Possible values:
120 to 3840
The width of the screen (px).
- height numberrequired
Possible values:
120 to 3840
The height of the screen (px).
- zOrder numberrequired
Possible values:
2 to 100
The layer order of the host screen.
2
represents the layer above the placeholder layer.100
represents the top layer.
- canvas objectrequired
Show propertiesHide properties
- width numberrequired
Possible values:
120 to 3840
The width of the canvas (px).
- height numberrequired
Possible values:
120 to 3840
The height of the canvas (px).
- color numberrequired
Possible values:
0 to 16777215
The background color of the canvas. The RGB color value represented as a decimal number
- backgroundImage stringnullable
Canvas background image. Must be a valid image URL with a
jpg
orpng
suffix. If omitted, there is no canvas background image. - fillMode stringnullable
Default:
"FILL"
Fill mode for the canvas background image:
"FILL"
: Scale the image and crop it in the center while maintaining the aspect ratio."FIT"
: Scale the image to fill the display while maintaining the aspect ratio.
- watermarks arrayrequired
Show propertiesHide properties
- imageUrl stringrequired
The URL of the watermark image. It must be a valid URL with a
jpg
orpng
suffix. - region objectrequired
Show propertiesHide properties
- x numberrequired
Possible values:
0 to 3840
The x coordinate of the watermark on the canvas (px). The x coordinate is the horizontal displacement of the upper left corner of the image relative to the origin.
- y numberrequired
Possible values:
0 to 3840
The y coordinate of the watermark on the canvas (px). The y coordinate is the vertical displacement of the upper left corner of the image relative to the origin.
- width numberrequired
Possible values:
120 to 3840
The width of the watermark (px).
- height numberrequired
Possible values:
120 to 3840
The height of the watermark (px).
- zOrder numberrequired
Possible values:
0 to 100
The layer order of the watermark.
0
represents the bottom layer.100
represents the top layer.
- fillMode stringnullable
Default:
"FILL"
Watermark fill mode:
"FILL"
: Scale the image and crop it in the center while maintaining the aspect ratio."FIT"
: Scale the image to fill the display while maintaining the aspect ratio.
- outputs arrayrequired
Configure output settings to publish to an RTC channel or CDN address.
You must specify either
streamUrl
orrtc
.Show propertiesHide properties
- streamUrl stringnullable
CDN streaming address.
- rtc objectnullable
Required for publishing to an RTC channel.
Show propertiesHide properties
- rtcChannel stringrequired
The RTC channel name for the transcoded audio and video.
- rtcUid numberrequired
The UID of the RTC channel for the transcoded audio and video streams. Make sure this value is different from the UID of other users in the channel.
- rtcToken stringrequired
The token that the Cloud Transcoder uses to join the output RTC channel. Using a token ensures channel security and prevents malicious users from disrupting other users in the channel. See Token authentication for details.
When generating this token, use
outputs.rtc.rtcUid
to generate the token.
- audioOption objectnullable
Show propertiesHide properties
- profileType stringnullable
Default:
AUDIO_PROFILE_DEFAULT
Audio properties of the transcoded output:
"AUDIO_PROFILE_DEFAULT"
: 48 kHz sampling rate, music encoding, mono channel, maximum encoding bitrate is 64 Kbps."AUDIO_PROFILE_SPEECH_STANDARD"
: 32 kHz sampling rate, speech encoding, mono channel, maximum encoding bitrate is 18 Kbps."AUDIO_PROFILE_MUSIC_STANDARD"
: 48 KHz sampling rate, music encoding, mono channel, maximum encoding bitrate is 64 Kbps."AUDIO_PROFILE_MUSIC_STANDARD_STEREO"
: 48 KHz sampling rate, music encoding, stereo channel, maximum encoding bitrate is 80 Kbps."AUDIO_PROFILE_MUSIC_HIGH_QUALITY"
: 48 KHz sampling rate, music encoding, mono channel, maximum encoding bitrate is 96 Kbps."AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO"
: 48 kHz sampling rate, music encoding, dual channels, and a maximum encoding bitrate of 128 Kbps.
- videoOption objectnullable
Show propertiesHide properties
- width numberrequired
Possible values:
120 to 3840
The width of the transcoded output video (px).
- height numberrequired
Possible values:
120 to 3840
The height of the transcoded output video (px).
- bitrate numberrequired
Possible values:
1 to 10000
The bitrate of the transcoded output video.
- codec stringrequired
The codec used to transcode the output video.
Possible values:
"H264"
: Standard H.264 encoding."VP8"
: Standard VP8 encoding.
- fps numbernullable
Default:
15
Possible values:
1 to 30
The frame rate (fps) of the transcoded output video.
- mode stringnullable
Can be set to
RAW
, which means the output video is not transcoded. The encoding format of the input video remains unchanged.If the output video is transcoded, do not set this field. In
RAW
mode, the number of inputs set invideInputs
can only be 1.
Response
Response header
UUID (Universally Unique Identifier), used to identify this request.
If the request fails, print out the value in the log to troubleshoot the problem. If the response status code of the request is not 2XX, then the response header may not contain this field.
Response body
-
If the returned status code is
200
, the request was successful. The response body contains the result of the request.OK
- createTs number
Unix timestamp (seconds) when the
builderToken
was generated - instanceId string
The
instanceId
you specified in the request. - tokenName string
The value of the
builderToken
. Use this value when calling other methods for this instance.
-
If the returned status code is not
200
, the request failed.Non 200
- message string
Describes why the request failed.
Reference
- After calling the
Acquire
method successfully, you receive abuilderToken
in the response body. You can use abuilderToken
for a single cloud transcoding task. - The validity period of a
builderToken
for creating cloud transcoding is 5 minutes. However, to ensure successful cloud transcoding, best practice is to initiate the correspondingCreate
request within 2 seconds after eachAcquire
response is received. - Making batch
Create
requests after batchbuilderToken
requests may cause the request to fail.