> 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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Synthflow APIs
  version: 1.0.0
paths:
  /calls/outbound-test-ws-media:
    post:
      operationId: start-ws-media-call
      summary: Start a WebSocket media call
      description: >-
        Starts an outbound test call and returns a short-lived WebSocket URL for
        streaming call audio.
      tags:
        - ''
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: WebSocket media call created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/start-ws-media-call_Response_200'
        '400':
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Start-ws-media-callRequestBadRequestError'
        '401':
          description: Missing or invalid API credentials.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Start-ws-media-callRequestUnauthorizedError
        '502':
          description: Room join failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Start-ws-media-callRequestBadGatewayError'
        '503':
          description: WebSocket media is not enabled in this environment.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Start-ws-media-callRequestServiceUnavailableError
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                modelId:
                  type: string
                  format: uuid
                  description: Agent model UUID.
                fromPhoneNumber:
                  type: string
                  description: Caller ID for the test call.
                toPhoneNumber:
                  type: string
                  description: Destination phone number.
                leadName:
                  type: string
                  description: Lead display name.
                agentVersion:
                  type: string
                  description: >-
                    Agent version to use. Set to `draft` to test the draft
                    version, pass a version UUID, or omit for the live version.
                wsMediaCodec:
                  $ref: >-
                    #/components/schemas/CallsOutboundTestWsMediaPostRequestBodyContentApplicationJsonSchemaWsMediaCodec
                  default: opus
                  description: Codec to use for the WebSocket media stream.
              required:
                - modelId
                - fromPhoneNumber
                - toPhoneNumber
servers:
  - url: https://api.synthflow.ai/v2
    description: Global
  - url: https://api.us.synthflow.ai/v2
    description: United States
  - url: https://api.eu.synthflow.ai/v2
    description: European Union
components:
  schemas:
    CallsOutboundTestWsMediaPostRequestBodyContentApplicationJsonSchemaWsMediaCodec:
      type: string
      enum:
        - opus
        - pcma
        - pcmu
      default: opus
      description: Codec to use for the WebSocket media stream.
      title: >-
        CallsOutboundTestWsMediaPostRequestBodyContentApplicationJsonSchemaWsMediaCodec
    start-ws-media-call_Response_200:
      type: object
      properties:
        callId:
          type: string
          description: Call ID for looking up the call later.
        wsMediaUrl:
          type: string
          format: uri
          description: Short-lived WebSocket URL for streaming call audio.
      required:
        - callId
        - wsMediaUrl
      title: start-ws-media-call_Response_200
    Start-ws-media-callRequestBadRequestError:
      type: object
      properties: {}
      title: Start-ws-media-callRequestBadRequestError
    Start-ws-media-callRequestUnauthorizedError:
      type: object
      properties: {}
      title: Start-ws-media-callRequestUnauthorizedError
    Start-ws-media-callRequestBadGatewayError:
      type: object
      properties:
        callId:
          type: string
          description: Call ID, if a call was created before the room join failed.
        error:
          type: string
      title: Start-ws-media-callRequestBadGatewayError
    Start-ws-media-callRequestServiceUnavailableError:
      type: object
      properties: {}
      title: Start-ws-media-callRequestServiceUnavailableError
  securitySchemes:
    sec0:
      type: http
      scheme: bearer

```

## 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"
}
```

**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()
```