> For the complete documentation index, see [llms.txt](https://support.maytapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.maytapi.com/account-and-channels/voice-calls-webrtc.md). Agents can also search and read this documentation through its [MCP server](https://support.maytapi.com/~gitbook/mcp).

# Voice Calls with Audio (WebRTC) — Beta

> Answer incoming WhatsApp voice calls and place outgoing ones with **real two-way audio**. The call audio is delivered to your application over a standard WebRTC connection.

{% hint style="warning" %}
**Closed beta, free during December 2026.** Voice calls with audio are enabled per phone. To use the feature, contact **<info@maytapi.com>** and tell us the phone ID you want to enable. On phones where the feature is not enabled, these endpoints (except `call/status`) return an error. The endpoints may change during the beta.
{% endhint %}

For ring-only calls (`call/start`), rejecting calls, call links, call history and call webhooks, see [Calls & Call Links](https://support.maytapi.com/account-and-channels/calls.md).

***

## How It Works

```
Your server ──HTTPS──▶ api.maytapi.com ──▶ your WhatsApp phone
     │                                          │
     └── WebRTC audio ◀── turn.maytapi.com ──▶──┘
```

1. A call arrives and you get the `call/ringing` webhook (or you start one with `call/dial`).
2. Your server gets the WebRTC settings (`webrtc-config`).
3. Your WebRTC client creates an offer with those settings.
4. You answer the call (`accept`) and send the offer (`/webrtc`). The response is the answer.
5. Audio flows over the WebRTC connection through `turn.maytapi.com`. No HTTP requests are needed for audio.
6. The call ends (`end`, the other party hangs up, or a time limit) and you get the `call/end` webhook.

***

## Requirements

|                   |                                                                                                                                                  |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **WebRTC client** | Any WebRTC implementation: a browser, or a server library such as `aiortc` (Python), `werift` (Node.js), `pion` (Go)                             |
| **Network**       | Outbound **TCP 443** to `turn.maytapi.com`. No other ports are needed                                                                            |
| **Audio**         | Audio only. Video is not supported                                                                                                               |
| **Calls**         | One-to-one calls and outgoing group calls (`call/dial` with the group ID). Incoming group calls cannot be answered. One call at a time per phone |

{% hint style="danger" %}
**Never put your API token in a browser.** Call the Maytapi endpoints from your server. Send only `iceServers` and the SDP to the browser.
{% endhint %}

`turn.maytapi.com` is not a web page. Give the `iceServers` you receive to `RTCPeerConnection` exactly as they are.

***

## Endpoints

| Method | Endpoint                           | Purpose                                 |
| ------ | ---------------------------------- | --------------------------------------- |
| `GET`  | `/{phone_id}/call/webrtc-config`   | WebRTC (TURN) settings for the call     |
| `POST` | `/{phone_id}/call/{callId}/accept` | Answer an incoming call                 |
| `POST` | `/{phone_id}/call/dial`            | Start an outgoing call                  |
| `POST` | `/{phone_id}/call/{callId}/webrtc` | Connect the audio (offer → answer)      |
| `POST` | `/{phone_id}/call/{callId}/end`    | End the call                            |
| `GET`  | `/{phone_id}/call/status`          | The call that is ringing or in progress |

***

## 1. Get the WebRTC Settings

```
GET /{phone_id}/call/webrtc-config
```

```json
{
  "success": true,
  "data": {
    "iceServers": [
      {
        "urls": ["turns:turn.maytapi.com:443?transport=tcp"],
        "username": "1700000000:12345:c",
        "credential": "Zm9vYmFyZXhhbXBsZWNyZWRlbnRpYWw="
      }
    ],
    "expiresAt": "2026-01-01T12:00:00.000Z",
    "iceTransportPolicy": "relay"
  }
}
```

* The credentials are short-lived (`expiresAt`). An open call keeps working after they expire. **Call this endpoint again before every new connection or reconnect.**
* Limited to 10 requests per minute per phone.

***

## 2. Answer an Incoming Call

The `call/ringing` webhook gives you the `callId`:

```json
{
  "type": "message",
  "phone_id": 12345,
  "message": {
    "id": "00A1B2C3D4E5F60718293A4B5C6D7E8F",
    "type": "info",
    "subtype": "call/ringing",
    "callId": "00A1B2C3D4E5F60718293A4B5C6D7E8F",
    "isVideo": false,
    "fromMe": false
  },
  "user": { "id": "905301234568@c.us", "name": "John Doe", "phone": "905301234568" }
}
```

Answer it:

```
POST /{phone_id}/call/{callId}/accept
```

```json
{ "success": true, "data": true }
```

{% hint style="info" %}
Connect the audio (step 4) **within 20 seconds** after answering, otherwise the call is ended.
{% endhint %}

***

## 3. Start an Outgoing Call

```
POST /{phone_id}/call/dial
```

```json
{ "to_number": "905301234567", "duration": 45 }
```

| Field       | Required | Description                                                                                                                               |
| ----------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `to_number` | ✅        | Number with country code, no `+` or spaces. For a group call, the full group ID including `@g.us` (for example `120363000000000000@g.us`) |
| `duration`  | ❌        | How long to ring before giving up, in seconds. Default `45`, min `5`, max `60`                                                            |

```json
{ "success": true, "data": { "callId": "00F1E2D3C4B5A69788796A5B4C3D2E1F", "chatId": "905301234567@c.us" } }
```

Unlike `call/start`, the call stays open when it is answered. Poll `call/status` and **connect the audio after `status` becomes `connected`**. If you connect earlier, the start of the conversation can be lost.

**Group calls:** pass the group ID as `to_number`, including the `@g.us` suffix. Without the suffix the value is treated as a phone number and the call is not placed. All group members are called; connect the audio after `status` becomes `connected` (when the first member joins). You hear all members on the same audio track. Incoming group calls cannot be answered.

***

## 4. Connect the Audio

Create an `RTCPeerConnection` with the settings from step 1, add your audio track, create an offer and wait until ICE gathering is complete (no trickle ICE). Then send the offer:

```
POST /{phone_id}/call/{callId}/webrtc
```

```json
{ "sdp": "v=0\r\no=- 1111111111111111111 2 IN IP4 127.0.0.1\r\n..." }
```

```json
{ "success": true, "data": { "sdp": "v=0\r\no=- 2222222222222222222 2 IN IP4 127.0.0.1\r\n..." } }
```

Set the returned `sdp` as the remote description. The caller's voice arrives as a remote audio track (`ontrack`); the audio you add to the connection is heard by the caller.

* The offer must be **audio only** and at most 100 KB.
* One connection per call. A second offer without `reconnect` is refused.

### Browser example

Your server forwards the three requests to Maytapi with your token; the browser only talks to your server.

```javascript
// cfg = response of webrtc-config (from your server)
const pc = new RTCPeerConnection({ iceServers: cfg.iceServers, iceTransportPolicy: 'relay' });

const mic = await navigator.mediaDevices.getUserMedia({ audio: true });
mic.getTracks().forEach((t) => pc.addTrack(t, mic));

const audio = new Audio();
audio.autoplay = true;
pc.ontrack = (e) => { audio.srcObject = e.streams[0]; };

await pc.setLocalDescription(await pc.createOffer());
await new Promise((resolve) => {
  if (pc.iceGatheringState === 'complete') return resolve();
  pc.onicegatheringstatechange = () => pc.iceGatheringState === 'complete' && resolve();
});

// your server calls POST /{phone_id}/call/{callId}/webrtc with { sdp }
const answer = await yourServer.connectCall(callId, pc.localDescription.sdp);
await pc.setRemoteDescription({ type: 'answer', sdp: answer.sdp });
```

### Reconnect

If the network changes during a call, you can reconnect: get new settings from `webrtc-config`, create a new connection and offer, and send it with `"reconnect": true`:

```json
{ "sdp": "v=0\r\n...", "reconnect": true }
```

***

## 5. Follow the Call

```
GET /{phone_id}/call/status
```

```json
{
  "success": true,
  "data": [
    {
      "timestamp": 1796000000,
      "uid": "905301234568@c.us",
      "fromMe": false,
      "conversation": "905301234568@c.us",
      "user": { "id": "905301234568@c.us", "name": "John Doe", "phone": "905301234568" },
      "message": {
        "id": "00A1B2C3D4E5F60718293A4B5C6D7E8F",
        "_serialized": "00A1B2C3D4E5F60718293A4B5C6D7E8F",
        "type": "info",
        "subtype": "call/ringing",
        "callId": "00A1B2C3D4E5F60718293A4B5C6D7E8F",
        "isVideo": false
      },
      "status": "connected",
      "connectedSec": 12
    }
  ]
}
```

* `status`: `calling` (outgoing, not ringing yet), `ringing`, `connected`. Short-lived values such as `ending` (the call is closing) or `active_elsewhere` (the call was answered on another device, for example the phone itself) can also appear.
* `connectedSec`: seconds since the call was answered, `null` before that.
* When there is no call, `data` is an empty list.

***

## 6. End the Call

```
POST /{phone_id}/call/{callId}/end
```

```json
{ "success": true, "data": true }
```

Only the call with this `callId` is ended. The WebRTC connection is closed. If the call was connected, a `call/end` webhook follows with `callDuration` (seconds); an outgoing call that was still ringing ends without `call/end`.

***

## Time Limits

| Situation                             | What happens                                                                                       |
| ------------------------------------- | -------------------------------------------------------------------------------------------------- |
| Call answered but audio not connected | Call ends after **20 seconds**                                                                     |
| WebRTC connection drops               | Waits **25 seconds** for the connection to recover (about 40 seconds in total), then ends the call |
| Maximum call length                   | **10 minutes** by default; can be changed per phone on request                                     |

If your connection goes to `failed` and you do not reconnect, treat the call as ended.

***

## Webhooks

The usual [call webhooks](https://support.maytapi.com/account-and-channels/calls.md#call-events-webhooks) are sent:

| Scenario                                 | Events                                                            |
| ---------------------------------------- | ----------------------------------------------------------------- |
| Incoming call answered with `accept`     | `call/ringing` → `call/accept` → `call/end` (with `callDuration`) |
| Outgoing call with `call/dial`, answered | `call/ringing` → `call/end` (with `callDuration`)                 |
| Not answered / declined                  | `call/ringing` → `call/miss` / `call/reject`                      |

***

## Related Pages

* [Calls & Call Links](https://support.maytapi.com/account-and-channels/calls.md)
* [Webhook Payload Reference](https://support.maytapi.com/receiving-messages/webhook-payload-reference.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.maytapi.com/account-and-channels/voice-calls-webrtc.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
