> For a complete page index, fetch https://docs.synthflow.ai/llms.txt. For full documentation content, fetch https://docs.synthflow.ai/llms-full.txt.

# Start a WebSocket media call

POST https://api.synthflow.ai/v2/calls/outbound-test-ws-media
Content-Type: application/json

Starts an outbound test call and returns a short-lived WebSocket URL for streaming call audio.

Reference: https://docs.synthflow.ai/api-reference/platform-api/calls/start-ws-media-call

## Authentication

- `Authorization` header (bearer token, required)

## Servers

- `https://api.synthflow.ai/v2` (Global, default)
- `https://api.us.synthflow.ai/v2` (United States)
- `https://api.eu.synthflow.ai/v2` (European Union)

## Request

### Body (application/json)

- `modelId` (string, required) — Agent model UUID.
- `fromPhoneNumber` (string, required) — Caller ID for the test call.
- `toPhoneNumber` (string, required) — Destination phone number.
- `leadName` (string, optional) — Lead display name.
- `agentVersion` (string, optional) — Agent version to use. Set to `draft` to test the draft version, pass a version UUID, or omit for the live version.
- `wsMediaCodec` (enum, optional, default: opus) — Codec to use for the WebSocket media stream. `l16` is raw big-endian 16-bit PCM at 16 kHz.
  - Allowed values: `opus`, `pcma`, `pcmu`, `l16`
- `wsMediaFraming` (enum, optional, default: rtp) — Wire format for the WebSocket media stream. `rtp` (default) sends full RTP packets; `payload` sends raw codec payloads (RTP header stripped), which is simpler for external AI/STT/TTS clients. Use `payload` with `pcma`/`pcmu` — avoid `payload` with `opus` (see the integration guide for why).
  - Allowed values: `rtp`, `payload`
- `wsMediaServerName` (string, optional, default: ) — Media node the client reached, taken from the `server-name` in the `server_info` message. Provide it to start the call on that exact node and receive a `sid` to bind over the open WebSocket (connect-then-bind). Omit it only for the legacy single-node flow that returns a ready-to-use `wsMediaUrl`.

## Response

### 200

WebSocket media call created.

- `callId` (string, required) — Call ID for looking up the call later.
- `wsMediaUrl` (string, required) — Short-lived WebSocket URL with the session id attached. Used directly by the legacy single-node flow; connect-then-bind clients ignore it and bind `sid` over the base URL connection instead.
- `sid` (string, optional) — Session id for connect-then-bind. Returned when `wsMediaServerName` is set; send it as `{ "type": "bind", "sid": "..." }` over the WebSocket you already opened to attach your connection to the call. Empty for the legacy single-node flow.

## Examples

**Request**

```json
{
  "modelId": "8edd032a-5fef-4847-abe2-55fb16057ece",
  "fromPhoneNumber": "+15559876543",
  "toPhoneNumber": "+15551234567",
  "leadName": "Test Lead",
  "agentVersion": "draft",
  "wsMediaCodec": "opus"
}
```

**Response**

```json
{
  "callId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "wsMediaUrl": "wss://webrtc-us.synthflow.ai/ws-audio?sid=7f3c9e2a1b0d4f8e",
  "sid": "7f3c9e2a1b0d4f8e"
}
```

**SDK Code**

```python
import requests

url = "https://api.synthflow.ai/v2/calls/outbound-test-ws-media"

payload = {
    "modelId": "8edd032a-5fef-4847-abe2-55fb16057ece",
    "fromPhoneNumber": "+15559876543",
    "toPhoneNumber": "+15551234567",
    "leadName": "Test Lead",
    "agentVersion": "draft",
    "wsMediaCodec": "opus"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.synthflow.ai/v2/calls/outbound-test-ws-media"

	payload := strings.NewReader("{\n  \"modelId\": \"8edd032a-5fef-4847-abe2-55fb16057ece\",\n  \"fromPhoneNumber\": \"+15559876543\",\n  \"toPhoneNumber\": \"+15551234567\",\n  \"leadName\": \"Test Lead\",\n  \"agentVersion\": \"draft\",\n  \"wsMediaCodec\": \"opus\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.synthflow.ai/v2/calls/outbound-test-ws-media")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"modelId\": \"8edd032a-5fef-4847-abe2-55fb16057ece\",\n  \"fromPhoneNumber\": \"+15559876543\",\n  \"toPhoneNumber\": \"+15551234567\",\n  \"leadName\": \"Test Lead\",\n  \"agentVersion\": \"draft\",\n  \"wsMediaCodec\": \"opus\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.synthflow.ai/v2/calls/outbound-test-ws-media")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"modelId\": \"8edd032a-5fef-4847-abe2-55fb16057ece\",\n  \"fromPhoneNumber\": \"+15559876543\",\n  \"toPhoneNumber\": \"+15551234567\",\n  \"leadName\": \"Test Lead\",\n  \"agentVersion\": \"draft\",\n  \"wsMediaCodec\": \"opus\"\n}")
  .asString();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.synthflow.ai/v2/calls/outbound-test-ws-media");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"modelId\": \"8edd032a-5fef-4847-abe2-55fb16057ece\",\n  \"fromPhoneNumber\": \"+15559876543\",\n  \"toPhoneNumber\": \"+15551234567\",\n  \"leadName\": \"Test Lead\",\n  \"agentVersion\": \"draft\",\n  \"wsMediaCodec\": \"opus\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "modelId": "8edd032a-5fef-4847-abe2-55fb16057ece",
  "fromPhoneNumber": "+15559876543",
  "toPhoneNumber": "+15551234567",
  "leadName": "Test Lead",
  "agentVersion": "draft",
  "wsMediaCodec": "opus"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.synthflow.ai/v2/calls/outbound-test-ws-media")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```