> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# stream

> Stream call audio to a WebSocket endpoint.

[streamaction]: /docs/server-sdks/reference/python/relay/actions

[calling-call-stream]: /docs/server-sdks/reference/python/relay/call#events

[call-events]: /docs/server-sdks/reference/python/relay/call#events

Start streaming call audio to a WebSocket endpoint. Returns a
[`StreamAction`][streamaction] that you can use to
stop the stream or wait for it to finish.

> **Info**
>
> This method emits [`calling.call.stream`][calling-call-stream] events. See [Call Events][call-events] for payload details.

## **Parameters**

**`url`** `str` — required

WebSocket URL to stream audio to (e.g., `"wss://example.com/stream"`).

---

**`name`** `str | None` — default: None

A name for this stream, useful for identifying multiple concurrent streams.

---

**`codec`** `str | None` — default: None

Audio codec for the stream.

* `"PCMU"` -- G.711 mu-law (default for North America)
* `"PCMA"` -- G.711 A-law (default for international)
* `"OPUS"` -- Opus codec (higher quality, variable bitrate)

---

**`track`** `str | None` — default: None

Which audio track to stream.

* `"inbound"` -- audio received from the caller
* `"outbound"` -- audio sent to the caller
* `"both"` -- audio in both directions

---

**`status_url`** `str | None` — default: None

URL to receive stream status webhooks.

---

**`status_url_method`** `str | None` — default: None

HTTP method for status webhooks.

* `"GET"` -- send status updates via GET request
* `"POST"` -- send status updates via POST request

---

**`authorization_bearer_token`** `str | None` — default: None

Bearer token for authenticating with the WebSocket server.

---

**`custom_parameters`** `dict | None` — default: None

Custom key-value pairs sent with the stream start message.

---

**`control_id`** `str | None` — default: None

Custom control ID. Auto-generated if not provided.

---

**`on_completed`** `Callable[[RelayEvent], Any] | None` — default: None

Callback invoked when the stream ends.

---

## **Returns**

[`StreamAction`][streamaction] -- An action handle with
`stop()` and `wait()` methods.

## **Example**

```python {14}
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    contexts=["default"],
)

@client.on_call
async def handle_call(call):
    await call.answer()

    # Stream audio to an external service for real-time processing
    action = await call.stream(
        url="wss://example.com/audio-stream",
        track="inbound",
        codec="PCMU",
        custom_parameters={"session_id": "abc123"},
    )

    # The stream runs until stopped or the call ends
    await call.wait_for_ended()

client.run()
```