Server-side API connection
This document describes how to connect to the server-side API of the Digitized Virtual Human Open Platform. The server-side API uses the standard Alibaba Cloud OpenAPI solution. The SDK supports multiple programming languages, such as Java and Python. For a list of supported languages and SDK versions, see Digitized Virtual Human Open Platform SDK.
Overall connection flow
The overall connection flow for the digital human streaming media service is shown in the following figure. This flow applies to both 3D and 2D digital human streaming media services.

The following sections use Java as an example to demonstrate how to connect using the server-side SDK. For information about other languages, see Digitized Virtual Human Open Platform SDK. For information about connecting using the RTC stream pulling SDK, see Real-time streaming media service connection.
1. Import the API SDK
For Java applications, you can add the following dependency to your pom.xml file to obtain the Java SDK for the Digitized Virtual Human Open Platform.
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>avatar20220130</artifactId>
<version>${latest_version}</version>
</dependency>Use the latest version from the official Apache Maven repository. You can obtain the latest version here. For more information about the SDK and SDKs for other languages, see Digitized Virtual Human Open Platform SDK.
2. Initialize the SDK
The upgraded SDK includes comprehensive logic for handling parameters, return values, and requests. This lets you generate a separate client for each cloud product. Each client contains all the OpenAPI request methods for that product. This design isolates identity and authentication information between cloud products to improve security. The following example shows how to initialize the SDK for the Digitized Virtual Human Open Platform:
public static void main(String[] args) {
Config config = new com.aliyun.teaopenapi.models.Config();
config.setAccessKeyId("<accessKeyId>");
config.setAccessKeySecret("<accessKeySecret>");
config.setEndpoint("avatar.cn-zhangjiakou.aliyuncs.com");
Client client = new Client(config);
}You must obtain the `accessKeyId` and `accessKeySecret` from your Alibaba Cloud account. For more information, see Step 3: Create an AccessKey pair. The `endPoint` parameter currently defaults to avatar.cn-zhangjiakou.aliyuncs.com.
3. Call the OpenAPI
Start the digital human streaming media service
The following example starts a default digital human streaming media service. This service ingests the rendered video stream to an Alibaba Cloud RTC server. You can then pull the stream using the Alibaba Cloud RTC stream pulling SDK.
public static void main(String[] args) {
StartInstanceRequest startInstanceRequest = new StartInstanceRequest();
// Obtain the tenant ID from the business configuration details on the Digitized Virtual Human Open Platform.
startInstanceRequest.setTenantId(<tenantId>);
// Obtain the business AppId from the business configuration details on the Digitized Virtual Human Open Platform.
startInstanceRequest.setApp(new StartInstanceRequest.StartInstanceRequestApp().setAppId("<appId>"));
startInstanceRequest.setUser(new StartInstanceRequest.StartInstanceRequestUser().setUserId("<userId>").setUserName("<userName>"));
StartInstanceResponse startInstanceResponse = client.startInstance(startInstanceRequest);
// Get the SessionId after startup. This ID is required for subsequent text-to-speech API calls.
String sessionId = startInstanceResponse.getBody().getData().getSessionId();
}You can obtain the `tenantId` and `appId` after you activate the Digitized Virtual Human Open Platform service. For more information about the parameters, see StartInstance - Start a digital human.
The API response includes the `sessionId` field. This is the unique ID for managing the digital human instance. You must store this ID securely. If you lose the ID, you can retrieve it by calling the QueryRunningInstance - Query running digital human instances API.
The following example starts a digital human streaming media service that uses RTMP for stream ingest. This service ingests the rendered video stream to a specified RTMP server. You can then pull the stream using the server's protocol. For more information, see 3D stream ingest digital human connection guide.
public static void main(String[] args) {
StartInstanceRequest startInstanceRequest = new StartInstanceRequest();
// Obtain the tenant ID from the business configuration details on the Digitized Virtual Human Open Platform.
startInstanceRequest.setTenantId(<tenantId>);
// Obtain the business AppId from the business configuration details on the Digitized Virtual Human Open Platform.
startInstanceRequest.setApp(new StartInstanceRequest.StartInstanceRequestApp().setAppId("<appId>"));
startInstanceRequest.setUser(new StartInstanceRequest.StartInstanceRequestUser().setUserId("<userId>").setUserName("<userName>"));
// Custom RTMP
String chanelType = "RTMP";
Map<String, String> reqConfig = new HashMap<>();
reqConfig.put("url", "<RTMP_URL>");
reqConfig.put("token", "<RTMP_authentication_token>");
startInstanceRequest.setChannel(new StartInstanceRequest.StartInstanceRequestChannel().setType(chanelType).setReqConfig(reqConfig));
StartInstanceResponse startInstanceResponse = client.startInstance(startInstanceRequest);
// Get the SessionId after startup. This ID is required for subsequent text-to-speech API calls.
String sessionId = startInstanceResponse.getBody().getData().getSessionId();
} This example shows how to call the API for a stream ingest digital human. The `<RTMP_URL>` and `<RTMP_authentication_token>` values are the RTMP ingest information provided by the backend of your target platform. For more information, see the `ReqConfig` parameter description in StartInstance - Start a digital human.
The API response includes the `sessionId` field. This is the unique ID for managing the digital human instance. You must store this ID securely. If you lose the ID, you can retrieve it by calling the QueryRunningInstance - Query running digital human instances API.
Make the digital human speak text
After you start the digital human streaming media service, you can make it speak text.
public static void main(String[] args) {
SendMessageRequest sendMessageRequest = new SendMessageRequest();
// Obtain the tenant ID from the business configuration details on the Digitized Virtual Human Open Platform.
sendMessageRequest.setTenantId(<tenantId>);
// Pass the SessionId (obtained from the StartInstance return value).
sendMessageRequest.setSessionId(<sessionId>);
// Pass the text content to be spoken.
sendMessageRequest.setTextRequest(new SendMessageRequest.SendMessageRequestTextRequest().setCommandType("START").setSpeechText("Hello, I am the smart digital human Xiaomeng. It's a pleasure to meet you all.")
.setId(UUID.randomUUID().toString()));
SendMessageResponse sendMessageResponse = client.sendMessage(sendMessageRequest);
}This example shows how to make the digital human speak text. For more information, see SendMessage - Send a text message.
Stop the digital human streaming media service
You can stop the digital human streaming media service.
public static void main(String[] args) {
StopInstanceRequest stopInstanceRequest = new StopInstanceRequest();
// Obtain the tenant ID from the business configuration details on the Digitized Virtual Human Open Platform.
stopInstanceRequest.setTenantId(<tenantId>);
// Pass the SessionId (obtained from the StartInstance return value).
stopInstanceRequest.setSessionId(<sessionId>);
StopInstanceResponse stopInstanceResponse = client.stopInstance(stopInstanceRequest);
}For more information, see StopInstance - Stop a digital human.
You must manage the lifecycle of the digital human on the server-side. The platform does not automatically stop the digital human streaming media service.
For more detailed information about how to use the preceding APIs, see the API Reference.
Next step: Read Client-side SDK connection to learn how the client connects to the real-time digital human streaming media service.