Discussions

Ask a Question
Back to All

Encountering a `bad request` exception when calling `https://api.heygen.com/v1/streaming.start`.

I did not get a reply, I’m submitting a new ticket since this is time critical


Hi HeyGen Technical Support,

I am encountering a bad request exception when calling https://api.heygen.com/v1/streaming.start.

Could you please provide the correct way to execute this call? Below is the sequence I am following in my application:

Create Token
New Session
C#

var options = new RestClientOptions("https://api.heygen.com/v1/streaming.new");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddHeader("x-api-key", "****");
request.AddJsonBody("{"quality":"medium","voice":{"rate":1},"video_encoding":"VP8","disable_idle_timeout":false}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);

var root = JsonSerializer.Deserialize(response.Content);
var sessionStart = new SessionStart();
sessionStart.session_id = root.data.session_id;
sessionStart.sdp = root.data.sdp;
Start Session
C#

var json = JsonSerializer.Serialize(sessionStart);
options = new RestClientOptions("https://api.heygen.com/v1/streaming.start");
client = new RestClient(options);
request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddHeader("x-api-key", "****");
request.AddJsonBody(json, false);
response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
Thank you for your assistance.



I would like to clarify that this issue is occurring in a desktop application using C# and not a web application. Here are the details of the exception I'm encountering:

Exception Details:

Type: System.Net.Http.HttpRequestException
Message: Request failed with status code BadRequest
Source: RestSharp
Stack Trace:

at RestSharp.ResponseThrowExtension.ThrowIfError(RestResponse response)
at RestSharp.RestClientExtensions.PostAsync(IRestClient client, RestRequest request, CancellationToken cancellationToken)
I have checked the request details and ensured the headers and body are correctly formatted as follows:

New Session Request:

C#

var options = new RestClientOptions("https://api.heygen.com/v1/streaming.new");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddHeader("x-api-key", "NjdlZjE2YjkxMTJhNGY5NmFkM2I4YTcwNGQ3M2E2OTgtMTczMjIwNjc2MQ==");
request.AddJsonBody("{"quality":"medium","voice":{"rate":1},"video_encoding":"VP8","disable_idle_timeout":false}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);

var root = JsonSerializer.Deserialize(response.Content);
var sessionStart = new SessionStart();
sessionStart.session_id = root.data.session_id;
sessionStart.sdp = root.data.sdp;
Start Session Request:

C#

var json = JsonSerializer.Serialize(sessionStart);
options = new RestClientOptions("https://api.heygen.com/v1/streaming.start");
client = new RestClient(options);
request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddHeader("x-api-key", "NjdlZjE2YjkxMTJhNGY5NmFkM2I4YTcwNGQ3M2E2OTgtMTczMjIwNjc2MQ==");
request.AddJsonBody(json, false);
response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
Could you please help identify the issue or provide the correct way to execute the https://api.heygen.com/v1/streaming.start call?


This is the same code I copied from https://docs.heygen.com/reference/start-session where the language is set to c#

API. Below is the JSON object being sent in the request when calling the start:

JSON

{
"session_id": "947d8373-b6b9-11ef-93d4-0eb4d364c31c",
"sdp": {
"type": "offer",
"sdp": "v=0\r\no=- 2646596335125062747 1733809365 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\na=msid-semantic:WMS*\r\na=fingerprint:sha-256 AB:E0:8C:2C:B6:6A:76:59:EC:87:E2:19:78:89:B2:61:0B:A0:39:BF:75:81:B0:56:AC:4D:39:A8:77:F7:FD:3A\r\na=extmap-allow-mixed\r\na=group:BUNDLE 0 1 2\r\nm=video 9 UDP/TLS/RTP/SAVPF 96\r\nc=IN IP4 0.0.0.0\r\na=setup:actpass\r\na=mid:0\r\na=ice-ufrag:rbXIyscfdpKgboEC\r\na=ice-pwd:TCgzUqCmyJNzqSvgPievHqUkTCYTUWVM\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=extmap:1 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\\r\\na=ssrc:2676508055 cname:pion\r\na=ssrc:2676508055 msid:pion video\r\na=ssrc:2676508055 mslabel:pion\r\na=ssrc:2676508055 label:video\r\na=msid:pion video\r\na=sendonly\r\na=candidate:2272725929 1 udp 2130706431 192.168.44.126 34085 typ host\r\na=candidate:2272725929 2 udp 2130706431 192.168.44.126 34085 typ host\r\na=candidate:233762139 1 udp 2130706431 172.17.0.1 59282 typ host\r\na=candidate:233762139 2 udp 2130706431 172.17.0.1 59282 typ host\r\na=candidate:3897773152 1 udp 1694498815 18.191.242.145 38961 typ srflx raddr 0.0.0.0 rport 38961\r\na=candidate:3897773152 2 udp 1694498815 18.191.242.145 38961 typ srflx raddr 0.0.0.0 rport 38961\r\na=candidate:3897773152 1 udp 1694498815 18.191.242.145 38271 typ srflx raddr 0.0.0.0 rport 38271\r\na=candidate:3897773152 2 udp 1694498815 18.191.242.145 38271 typ srflx raddr 0.0.0.0 rport 38271\r\na=candidate:3897773152 1 udp 1694498815 18.191.242.145 34902 typ srflx raddr 0.0.0.0 rport 34902\r\na=candidate:3897773152 2 udp 1694498815 18.191.242.145 34902 typ srflx raddr 0.0.0.0 rport 34902\r\na=candidate:3897773152 1 udp 1694498815 18.191.242.145 56390 typ srflx raddr 0.0.0.0 rport 56390\r\na=candidate:3897773152 2 udp 1694498815 18.191.242.145 56390 typ srflx raddr 0.0.0.0 rport 56390\r\na=candidate:3897773152 1 udp 1694498815 18.191.242.145 57776 typ srflx raddr 0.0.0.0 rport 57776\r\na=candidate:3897773152 2 udp 1694498815 18.191.242.145 57776 typ srflx raddr 0.0.0.0 rport 57776\r\na=candidate:2014968695 1 udp 16777215 34.203.250.239 47518 typ relay raddr 0.0.0.0 rport 44295\r\na=candidate:2014968695 2 udp 16777215 34.203.250.239 47518 typ relay raddr 0.0.0.0 rport 44295\r\na=candidate:2014968695 1 udp 16777215 34.203.250.239 43037 typ relay raddr 192.168.44.126 rport 60656\r\na=candidate:2014968695 2 udp 16777215 34.203.250.239 43037 typ relay raddr 192.168.44.126 rport 60656\r\na=candidate:2014968695 1 udp 16777215 34.203.250.239 56011 typ relay raddr 192.168.44.126 rport 58444\r\na=candidate:2014968695 2 udp 16777215 34.203.250.239 56011 typ relay raddr 192.168.44.126 rport 58444\r\na=end-of-candidates\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111\r\nc=IN IP4 0.0.0.0\r\na=setup:actpass\r\na=mid:1\r\na=ice-ufrag:rbXIyscfdpKgboEC\r\na=ice-pwd:TCgzUqCmyJNzqSvgPievHqUkTCYTUWVM\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:111 opus/48000/2\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=extmap:1 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\\r\\na=ssrc:230906675 cname:pion\r\na=ssrc:230906675 msid:pion audio\r\na=ssrc:230906675 mslabel:pion\r\na=ssrc:230906675 label:audio\r\na=msid:pion audio\r\na=sendrecv\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=setup:actpass\r\na=mid:2\r\na=sendrecv\r\na=sctp-port:5000\r\na=ice-ufrag:rbXIyscfdpKgboEC\r\na=ice-pwd:TCgzUqCmyJNzqSvgPievHqUkTCYTUWVM\r\n"

Can you also provide the way to get the avatar url so I can use it to play the video of the avatar speaking?