A call button on your website, answered by the agent
A WebRTC client lets a visitor call the agent from the browser. Your backend asks the platform for a temporary password, hands it to the page, and the page starts the call with one script. The secret key never reaches the browser.
Create the client
In Telephony › WebRTC clients choose the agent and list the domains where the button will be used, with localhost for local tests. You get the client name (wc_…) and a secret key (wk_…), shown only once.
1. Your backend asks for a temporary password
The password is valid for 60 seconds and for one call.
curl -X POST https://developers.swissai.dev/api/webrtc/token \
-H "X-Api-Key: wk_your_secret_key" \
-H "Content-Type: application/json" \
-d '{"client": "wc_3f9a1c2b7d4e", "identity": "visitor-1842"}'
// 200
{ "wss": "wss://pbx.swissai.dev:8089", "domain": "pbx.swissai.dev",
"user": "w4c1f09ab37de5521", "pass": "…", "target": "sip:ag_7f3a2b91@pbx.swissai.dev", "expires_in": 60 }
2. The page starts the call
Load the script and pass it the response as it is. onState receives connecting, calling, connected and idle; onError the reason when the call cannot start.
<button id="call">Call us</button>
<script src="https://developers.swissai.dev/js/call.js"></script>
<script>
document.getElementById('call').onclick = async () => {
const params = await (await fetch('/call-token', { method: 'POST' })).json(); // your backend
SwissCall.start(params, { onState: s => console.log(s), onError: m => alert(m) });
};
</script>
Same agent, same tools, also in text
The agent on the button is the same that answers the phone, with its prompt and tools. With the same client name and key your backend can also send it text messages through the chat API and read the customer's calls and costs with GetCalls. Both calls can be tried from the Test area of the dashboard, with the code to copy.
Frequently asked questions
Why does the password come from my backend?
Because the secret key must stay on the server. The page only ever sees a password valid for 60 seconds and one call.
Which browsers work?
Any modern browser with WebRTC and microphone access, on desktop and mobile.
Do browser calls cost the same as phone calls?
Yes. They count as minutes from the plan like any other call.
Related pages
- A SIP URI for every voice agent
- Tools: the agent calls your HTTP endpoints
- First-level customer support on the phone, answered by an AI agent
Try it with your own calls
Create an account, set up the agent in the dashboard and call it from the browser. 30-day free trial with 100 minutes, no card required.
Start for freeTalk to the demo agent