Skip to content

Voice Calls: Handle a Busy Service and Choose an Agent's Voice

Availability: Test environment Test environment only, where the dispatch setting is on; not yet confirmed by ear on a live call. Google text-to-speech only; speech-to-text language not with Deepgram or the live engine. Since 2026-11 /status

Two things partner teams meet first when they wire a voice call into their own product. A second call can be refused as busy while another one runs, and an agent can speak in the wrong voice until you set it. This page shows how to handle the first with a small retry loop and how to configure the second with updateAgent.

Starting a call uses an API key from your server (X-Api-Key, never in a browser). Changing an agent uses a dashboard login: Authorization: Bearer <jwt> and x-huat-platform: customer (see Authentication).

1. Start a call and handle the busy refusal

Section titled “1. Start a call and handle the busy refusal”
mutation StartVoiceCall($i: SdkStartVoiceCallInput!) {
sdkStartVoiceCall(input: $i) {
sessionId
agentId
livekitUrl
livekitToken
roomName
expiresAt
}
}
{ "i": { "agentId": 271, "clientId": "caller-42" } }

The result carries a LiveKit URL and a short-lived token for one fresh room. Give both to the caller’s browser or app and join immediately: the token is valid for about two minutes. engine is optional and defaults to WORKFLOW (the agent’s published workflow answers).

The test environment runs one call at a time across the whole environment. A second request is refused, and nothing is created or counted:

{
"errors": [
{
"message": "The voice service is busy with another call. Try again in about 30 seconds.",
"extensions": {
"code": "TOO_MANY_REQUESTS",
"status": 429,
"retryAfterSeconds": 30
}
}
],
"data": null
}

Treat extensions.code === "TOO_MANY_REQUESTS" as “wait and ask again”, not as a failure. Other refusals are different and should not be retried blindly: FORBIDDEN means voice calls are not enabled for the environment, and a “Daily voice call limit reached” error means the key’s daily cap is used up.

Things to know when you design the retry:

  • Outbound “call my phone” calls share the same slot (see Call my phone). A phone call in progress makes a browser call wait, and the other way round.
  • The slot of a call that nobody joins frees itself after about ten minutes, when the platform closes the unjoined session. If you start a call and never join, you hold the slot until then.
  • A quick burst of retries only adds load. Honour retryAfterSeconds, add a little jitter, and stop after a few tries.

Retry loop in TypeScript (Node 18 or later)

Section titled “Retry loop in TypeScript (Node 18 or later)”

Save it as an .mjs file. It reads the endpoint and key from the environment and uses no packages.

const GRAPHQL = process.env.WETEL_GRAPHQL; // your environment's /graphql URL
const API_KEY = process.env.WETEL_API_KEY;
const MUTATION = `
mutation StartVoiceCall($i: SdkStartVoiceCallInput!) {
sdkStartVoiceCall(input: $i) {
sessionId livekitUrl livekitToken roomName expiresAt
}
}`;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
export async function startVoiceCall(agentId, clientId, maxTries = 5) {
for (let attempt = 1; attempt <= maxTries; attempt++) {
const res = await fetch(GRAPHQL, {
method: "POST",
headers: { "content-type": "application/json", "x-api-key": API_KEY },
body: JSON.stringify({
query: MUTATION,
variables: { i: { agentId, clientId } },
}),
});
const body = await res.json();
const error = body.errors?.[0];
if (!error) return body.data.sdkStartVoiceCall;
const busy = error.extensions?.code === "TOO_MANY_REQUESTS";
if (!busy) throw new Error(error.message); // not retryable here
if (attempt === maxTries) throw new Error("Voice service still busy");
const wait = (error.extensions.retryAfterSeconds ?? 30) * 1000;
const jitter = Math.floor(Math.random() * 2000);
console.log(`busy, retrying in ${Math.round((wait + jitter) / 1000)} s`);
await sleep(wait + jitter);
}
}

The same in Python (standard library only)

Section titled “The same in Python (standard library only)”
import json
import os
import random
import time
import urllib.request
GRAPHQL = os.environ["WETEL_GRAPHQL"]
API_KEY = os.environ["WETEL_API_KEY"]
MUTATION = """
mutation StartVoiceCall($i: SdkStartVoiceCallInput!) {
sdkStartVoiceCall(input: $i) {
sessionId livekitUrl livekitToken roomName expiresAt
}
}"""
def start_voice_call(agent_id, client_id, max_tries=5):
payload = json.dumps(
{"query": MUTATION, "variables": {"i": {"agentId": agent_id, "clientId": client_id}}}
).encode()
for attempt in range(1, max_tries + 1):
request = urllib.request.Request(
GRAPHQL,
data=payload,
headers={"content-type": "application/json", "x-api-key": API_KEY},
)
with urllib.request.urlopen(request) as response:
body = json.load(response)
errors = body.get("errors")
if not errors:
return body["data"]["sdkStartVoiceCall"]
extensions = errors[0].get("extensions", {})
if extensions.get("code") != "TOO_MANY_REQUESTS":
raise RuntimeError(errors[0]["message"]) # not retryable here
if attempt == max_tries:
raise RuntimeError("Voice service still busy")
wait = extensions.get("retryAfterSeconds", 30) + random.uniform(0, 2)
print(f"busy, retrying in {wait:.0f} s")
time.sleep(wait)

If you join and no agent appears in the room within about 15 seconds, leave and request a new call the same way.

Voice, language and speaking rate are properties of the agent, set with updateAgent. The id is a separate argument and every field in input is optional, so send only what changes.

FieldWhat it sets
ttsVoiceThe full text-to-speech voice name, for example ms-MY-Wavenet-B.
ttsLangThe language the agent speaks, a BCP-47 code such as ms-MY.
speakingRateSpeaking rate from 0.25 to 4.0; 1.0 is normal.
sttLanguageCodeThe language callers mostly speak (the primary for speech recognition). When omitted it follows ttsLang.
sttAlternativeLanguageCodesUp to 3 extra languages callers may switch to. [] means the primary only. Duplicates and a repeat of the primary are rejected.

Example: an agent that speaks and listens in Malay, a little slower than normal.

mutation UpdateAgentVoice($id: ID!, $input: UpdateAgentInput!) {
updateAgent(id: $id, input: $input) {
id
ttsVoice
ttsLang
speakingRate
sttLanguageCode
sttAlternativeLanguageCodes
}
}
{
"id": "271",
"input": {
"ttsVoice": "ms-MY-Wavenet-B",
"ttsLang": "ms-MY",
"speakingRate": 0.9,
"sttLanguageCode": "ms-MY"
}
}

Pick the voice name and language from the same row of the voice list returned by agentConfigOptions; Choosing languages and voices explains the settings and how to mix languages.

  • They reach a call only where the environment has the voice-settings dispatch setting on. It is on for the test environment and off by default elsewhere, and the effect has not yet been confirmed by ear on a live call.
  • They are read when a new call starts. A call that is already running keeps the voice it started with; start a new call to hear a change.
  • The voice name decides the voice. The tier (voiceTier) is not sent to the call, so a name such as ms-MY-Wavenet-B is what you hear regardless of the tier field.
  • Text-to-speech applies with the default Google engine only. The speech-to-text language applies with the Gemini engine (as hints), the Google engine and the streaming Google engine. It does not apply with Deepgram speech-to-text or with the speech-to-speech live engine (engine: LIVE).
  • Only agents on the workflow engine use these settings on a call.
  • An agent still on the default voice (en-US-Standard-C) now speaks that voice on a call, so a voice that sounded different before may change. Set the voice you want explicitly.
  • The settings are validated, and an unusable value falls back to the voice worker’s own default instead of failing the call.
  1. Start a new call to the agent (section 1) and listen: the voice and pace should be audibly different from before the change.
  2. Read the agent back with the updateAgent result above (or the agent query) to confirm the stored values.
  3. If a call cannot start at all, check the Platform Status API: GET /status/v1 has a voice component, and a voice call needs it to be operational.
What you seeLikely causeWhat to do
TOO_MANY_REQUESTS, status 429, retryAfterSeconds 30Another call (or a phone call) holds the only slotWait and retry as in section 1; end calls you no longer need, and join every call you start.
The agent answers “Sorry, I ran into a problem processing that”The agent’s workflow is not published, or the run failedPublish the workflow (an unpublished or draft-only workflow runs no nodes), then start a new call.
workflowRuns(sessionId:) returns an empty list for the call’s sessionSame cause: no workflow ran for that sessionPublish the workflow and check again with a new call.
The voice did not changeThe call started before the update, or the engine does not apply itStart a new call; check the engine limits above.
FORBIDDEN “Voice calls are not enabled on this environment”The environment has no voice serviceAsk the Wetel team to enable it; nothing was started.

With the owner login, list the runs of the call’s session, newest first, then open one run for its node trace:

query RunsOfSession($sessionId: Int!) {
workflowRuns(sessionId: $sessionId) {
id
status
errorMessage
createdAt
}
}
query RunDetail($id: Int!) {
workflowRun(id: $id) {
id
status
errorMessage
nodeTrace
}
}

Use the sessionId that sdkStartVoiceCall returned. status shows how the run ended and nodeTrace lists the nodes it visited in order. No runs at all means the workflow never started. See Troubleshooting for more.

  • One call at a time on the test environment, shared with outbound phone calls. Do not load-test.
  • Production phone service is not available; the status page says where voice settings stand.
  • Live calls have been tested in English; Malay on a live call is not yet verified end to end.
  • A call is closed if nobody joins within about ten to fifteen minutes.