> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cawme.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# Stream de Chamada

> GET /v1/calls/:callId/stream — WebSocket para streaming de áudio em tempo real

`GET /v1/calls/:callId/stream`

Faz o upgrade de uma conexão HTTP para WebSocket para streaming de áudio bidirecional em tempo real. Este endpoint é utilizado com chamadas do tipo `DYNAMIC_STREAM`.

<Warning>
  O streaming via WebSocket está atualmente **em preview** e ainda não está disponível em produção. O endpoint retorna `501 Not Implemented` até o lançamento.
</Warning>

## Como funciona

1. Crie uma chamada `DYNAMIC_STREAM` via `POST /v1/calls`
2. Conecte-se a este endpoint WebSocket usando o `callId` retornado
3. Envie frames de áudio; receba transcrições e eventos da chamada

```
Cliente → Servidor: Frames de áudio PCM ou MP3
Servidor → Cliente: Transcrições em tempo real e eventos da chamada
```

## Upgrade do WebSocket

```http theme={null}
GET /v1/calls/call_xyz789/stream HTTP/1.1
Host: cawme.com
Authorization: Bearer <token>
Upgrade: websocket
Connection: Upgrade
```

O upgrade bem-sucedido retorna `101 Switching Protocols`.

## Formato das mensagens

### Enviando áudio (cliente → servidor)

Envie frames binários PCM ou MP3 brutos pela conexão WebSocket.

### Recebendo eventos (servidor → cliente)

```json theme={null}
{
  "type": "transcript",
  "text": "Olá, estou ligando sobre sua consulta recente.",
  "timestamp": "2026-03-01T10:01:20Z"
}
```

```json theme={null}
{
  "type": "call_event",
  "event": "answered",
  "timestamp": "2026-03-01T10:01:15Z"
}
```

## Requisição

### Cabeçalhos

| Cabeçalho       | Valor            |
| --------------- | ---------------- |
| `Authorization` | `Bearer <token>` |
| `Upgrade`       | `websocket`      |

### Parâmetros de caminho

| Parâmetro | Tipo     | Descrição                                    |
| --------- | -------- | -------------------------------------------- |
| `callId`  | `string` | O ID de uma chamada do tipo `DYNAMIC_STREAM` |

## Erros

| Código | Descrição                 |
| ------ | ------------------------- |
| `401`  | Token ausente ou inválido |
| `501`  | Ainda não implementado    |

## Exemplo (JavaScript)

```javascript theme={null}
const ws = new WebSocket(
  "wss://cawme.com/api/v1/calls/call_xyz789/stream",
  [],
  {
    headers: {
      Authorization: "Bearer <token>",
    },
  }
);

ws.onopen = () => {
  // Enviar frames de áudio PCM
  ws.send(audioBuffer);
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log(data.type, data.text ?? data.event);
};
```
