Start a Call
Get a single-use ticket for one call to a published agent
curl -X POST https://api.voice213.com/api/agents/public/k3x9m2p7q4wz/callimport { AgentCall } from "@voice213/agent-client";
// AgentCall asks for the ticket and opens the socket itself
const call = new AgentCall({ agentId: "k3x9m2p7q4wz" });
await call.start();import json
import urllib.request
request = urllib.request.Request("https://api.voice213.com/api/agents/public/k3x9m2p7q4wz/call", method="POST")
with urllib.request.urlopen(request, timeout=15) as response:
ticket = json.load(response)
print(f"{ticket['wsUrl']}?token={ticket['token']}"){
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhaWQiOiI2YWMyYWFi…",
"wsUrl": "wss://api.voice213.com/ws/agent"
}{
"error": "This agent cannot be called from this website",
"code": "ORIGIN"
}{
"error": "RATE_LIMITED"
}Returns a single-use ticket for one call to a published agent: a token, and the address of the call socket to open with it. The SDK asks for it when you call start(). You only need this endpoint for a client of your own. See Realtime Protocol.
It needs no key. Calls are paid from the agent owner's call minutes, so the endpoint is protected in two ways:
- Allowed websites. If the agent has a list, a request from a browser on a site that isn't on it is refused with
403 ORIGIN. The list is checked through theOriginheader browsers send. The Voice213 public page is always allowed. With an empty list, any site, and any client without anOrigin(a server or an app), can start calls. - A rate limit. Each IP address can ask for 20 tickets an hour.
The ticket is valid for two minutes and opens one call. A ticket requested with an Origin only opens a socket from that same origin. Asking for a ticket is free. Minutes count from the moment the call connects, and a call under 3 seconds isn't counted.
Path
The agent's public id, from its Publish page.
Body
application/jsonOptional. The visit token from an earlier answer (a call or a chat on the public page). The agent then starts the call knowing what this visitor already said in the visit. Without one, or with an expired one, a new visit starts.
Response
application/jsonErrors
| Status | Error | When |
|---|---|---|
403 | ORIGIN (in code) | The request came from a website that isn't in the agent's Allowed websites |
404 | This agent is not available | No agent has this id, the agent is a draft, or its link and widget are turned off |
429 | RATE_LIMITED | This IP address asked for 20 tickets in the last hour |
503 | MAINTENANCE (in code) | Voice213 is down for maintenance |
Whether the account has minutes and free lines is checked when the socket opens. See the error codes.
Was this page helpful?