Skip to contentSkip to navigationSkip to topbar
On this page

Stream Resource


(information)

Support for Twilio Regions

Media Streams is now available in the Ireland (IE1) and Australia (AU1) Regions.

The Stream resource represents a live audio stream during a live call.

Creating a Stream resource creates a unidirectional Media Stream. You can stop a unidirectional Media Stream by updating the status of a Stream resource, regardless of whether the Stream was created via TwiML (with <Start><Stream>) or via REST API (with the Stream resource).


Stream Properties

stream-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<MZ>

Optional

Not PII

The SID of the Stream resource.

Pattern: ^MZ[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

Optional

The SID of the Account that created this Stream resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

call_sidSID<CA>

Optional

The SID of the Call the Stream resource is associated with.

Pattern: ^CA[0-9a-fA-F]{32}$Min length: 34Max length: 34

namestring

Optional

The user-specified name of this Stream, if one was given when the Stream was created. This can be used to stop the Stream.


statusenum<string>

Optional

The status of the Stream. Possible values are stopped and in-progress.

Possible values:
in-progressstopped

date_updatedstring<date-time-rfc-2822>

Optional


uristring

Optional

The URI of the resource, relative to https://api.twilio.com.


Create a Stream resource

create-a-stream-resource page anchor
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
AccountSidSID<AC>required

The SID of the Account that created this Stream resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

CallSidSID<CA>required

The SID of the Call the Stream resource is associated with.

Pattern: ^CA[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Urlstring<uri>required

Relative or absolute URL where WebSocket connection will be established.


Namestring

Optional

The user-specified name of this Stream, if one was given when the Stream was created. This can be used to stop the Stream.


Trackenum<string>

Optional

The tracks to be included in the Stream. Possible values are inbound_track, outbound_track, both_tracks. Default value is inbound_track.

Possible values:
inbound_trackoutbound_trackboth_tracks

StatusCallbackstring<uri>

Optional

Absolute URL to which Twilio sends status callback HTTP requests.


StatusCallbackMethodenum<http-method>

Optional

The HTTP method Twilio uses when sending status_callback requests. Possible values are GET and POST. Default is POST.

Possible values:
GETPOST

Parameter1.Namestring

Optional

Parameter name


Parameter1.Valuestring

Optional

Parameter value


Parameter2.Namestring

Optional

Parameter name


Parameter2.Valuestring

Optional

Parameter value


Parameter3.Namestring

Optional

Parameter name


Parameter3.Valuestring

Optional

Parameter value


Parameter4.Namestring

Optional

Parameter name


Parameter4.Valuestring

Optional

Parameter value


Parameter5.Namestring

Optional

Parameter name


Parameter5.Valuestring

Optional

Parameter value


Parameter6.Namestring

Optional

Parameter name


Parameter6.Valuestring

Optional

Parameter value


Parameter7.Namestring

Optional

Parameter name


Parameter7.Valuestring

Optional

Parameter value


Parameter8.Namestring

Optional

Parameter name


Parameter8.Valuestring

Optional

Parameter value


Parameter9.Namestring

Optional

Parameter name


Parameter9.Valuestring

Optional

Parameter value


Parameter10.Namestring

Optional

Parameter name


Parameter10.Valuestring

Optional

Parameter value


Parameter11.Namestring

Optional

Parameter name


Parameter11.Valuestring

Optional

Parameter value


Parameter12.Namestring

Optional

Parameter name


Parameter12.Valuestring

Optional

Parameter value


Parameter13.Namestring

Optional

Parameter name


Parameter13.Valuestring

Optional

Parameter value


Parameter14.Namestring

Optional

Parameter name


Parameter14.Valuestring

Optional

Parameter value


Parameter15.Namestring

Optional

Parameter name


Parameter15.Valuestring

Optional

Parameter value


Parameter16.Namestring

Optional

Parameter name


Parameter16.Valuestring

Optional

Parameter value


Parameter17.Namestring

Optional

Parameter name


Parameter17.Valuestring

Optional

Parameter value


Parameter18.Namestring

Optional

Parameter name


Parameter18.Valuestring

Optional

Parameter value


Parameter19.Namestring

Optional

Parameter name


Parameter19.Valuestring

Optional

Parameter value


Parameter20.Namestring

Optional

Parameter name


Parameter20.Valuestring

Optional

Parameter value


Parameter21.Namestring

Optional

Parameter name


Parameter21.Valuestring

Optional

Parameter value


Parameter22.Namestring

Optional

Parameter name


Parameter22.Valuestring

Optional

Parameter value


Parameter23.Namestring

Optional

Parameter name


Parameter23.Valuestring

Optional

Parameter value


Parameter24.Namestring

Optional

Parameter name


Parameter24.Valuestring

Optional

Parameter value


Parameter25.Namestring

Optional

Parameter name


Parameter25.Valuestring

Optional

Parameter value


Parameter26.Namestring

Optional

Parameter name


Parameter26.Valuestring

Optional

Parameter value


Parameter27.Namestring

Optional

Parameter name


Parameter27.Valuestring

Optional

Parameter value


Parameter28.Namestring

Optional

Parameter name


Parameter28.Valuestring

Optional

Parameter value


Parameter29.Namestring

Optional

Parameter name


Parameter29.Valuestring

Optional

Parameter value


Parameter30.Namestring

Optional

Parameter name


Parameter30.Valuestring

Optional

Parameter value


Parameter31.Namestring

Optional

Parameter name


Parameter31.Valuestring

Optional

Parameter value


Parameter32.Namestring

Optional

Parameter name


Parameter32.Valuestring

Optional

Parameter value


Parameter33.Namestring

Optional

Parameter name


Parameter33.Valuestring

Optional

Parameter value


Parameter34.Namestring

Optional

Parameter name


Parameter34.Valuestring

Optional

Parameter value


Parameter35.Namestring

Optional

Parameter name


Parameter35.Valuestring

Optional

Parameter value


Parameter36.Namestring

Optional

Parameter name


Parameter36.Valuestring

Optional

Parameter value


Parameter37.Namestring

Optional

Parameter name


Parameter37.Valuestring

Optional

Parameter value


Parameter38.Namestring

Optional

Parameter name


Parameter38.Valuestring

Optional

Parameter value


Parameter39.Namestring

Optional

Parameter name


Parameter39.Valuestring

Optional

Parameter value


Parameter40.Namestring

Optional

Parameter name


Parameter40.Valuestring

Optional

Parameter value


Parameter41.Namestring

Optional

Parameter name


Parameter41.Valuestring

Optional

Parameter value


Parameter42.Namestring

Optional

Parameter name


Parameter42.Valuestring

Optional

Parameter value


Parameter43.Namestring

Optional

Parameter name


Parameter43.Valuestring

Optional

Parameter value


Parameter44.Namestring

Optional

Parameter name


Parameter44.Valuestring

Optional

Parameter value


Parameter45.Namestring

Optional

Parameter name


Parameter45.Valuestring

Optional

Parameter value


Parameter46.Namestring

Optional

Parameter name


Parameter46.Valuestring

Optional

Parameter value


Parameter47.Namestring

Optional

Parameter name


Parameter47.Valuestring

Optional

Parameter value


Parameter48.Namestring

Optional

Parameter name


Parameter48.Valuestring

Optional

Parameter value


Parameter49.Namestring

Optional

Parameter name


Parameter49.Valuestring

Optional

Parameter value


Parameter50.Namestring

Optional

Parameter name


Parameter50.Valuestring

Optional

Parameter value


Parameter51.Namestring

Optional

Parameter name


Parameter51.Valuestring

Optional

Parameter value


Parameter52.Namestring

Optional

Parameter name


Parameter52.Valuestring

Optional

Parameter value


Parameter53.Namestring

Optional

Parameter name


Parameter53.Valuestring

Optional

Parameter value


Parameter54.Namestring

Optional

Parameter name


Parameter54.Valuestring

Optional

Parameter value


Parameter55.Namestring

Optional

Parameter name


Parameter55.Valuestring

Optional

Parameter value


Parameter56.Namestring

Optional

Parameter name


Parameter56.Valuestring

Optional

Parameter value


Parameter57.Namestring

Optional

Parameter name


Parameter57.Valuestring

Optional

Parameter value


Parameter58.Namestring

Optional

Parameter name


Parameter58.Valuestring

Optional

Parameter value


Parameter59.Namestring

Optional

Parameter name


Parameter59.Valuestring

Optional

Parameter value


Parameter60.Namestring

Optional

Parameter name


Parameter60.Valuestring

Optional

Parameter value


Parameter61.Namestring

Optional

Parameter name


Parameter61.Valuestring

Optional

Parameter value


Parameter62.Namestring

Optional

Parameter name


Parameter62.Valuestring

Optional

Parameter value


Parameter63.Namestring

Optional

Parameter name


Parameter63.Valuestring

Optional

Parameter value


Parameter64.Namestring

Optional

Parameter name


Parameter64.Valuestring

Optional

Parameter value


Parameter65.Namestring

Optional

Parameter name


Parameter65.Valuestring

Optional

Parameter value


Parameter66.Namestring

Optional

Parameter name


Parameter66.Valuestring

Optional

Parameter value


Parameter67.Namestring

Optional

Parameter name


Parameter67.Valuestring

Optional

Parameter value


Parameter68.Namestring

Optional

Parameter name


Parameter68.Valuestring

Optional

Parameter value


Parameter69.Namestring

Optional

Parameter name


Parameter69.Valuestring

Optional

Parameter value


Parameter70.Namestring

Optional

Parameter name


Parameter70.Valuestring

Optional

Parameter value


Parameter71.Namestring

Optional

Parameter name


Parameter71.Valuestring

Optional

Parameter value


Parameter72.Namestring

Optional

Parameter name


Parameter72.Valuestring

Optional

Parameter value


Parameter73.Namestring

Optional

Parameter name


Parameter73.Valuestring

Optional

Parameter value


Parameter74.Namestring

Optional

Parameter name


Parameter74.Valuestring

Optional

Parameter value


Parameter75.Namestring

Optional

Parameter name


Parameter75.Valuestring

Optional

Parameter value


Parameter76.Namestring

Optional

Parameter name


Parameter76.Valuestring

Optional

Parameter value


Parameter77.Namestring

Optional

Parameter name


Parameter77.Valuestring

Optional

Parameter value


Parameter78.Namestring

Optional

Parameter name


Parameter78.Valuestring

Optional

Parameter value


Parameter79.Namestring

Optional

Parameter name


Parameter79.Valuestring

Optional

Parameter value


Parameter80.Namestring

Optional

Parameter name


Parameter80.Valuestring

Optional

Parameter value


Parameter81.Namestring

Optional

Parameter name


Parameter81.Valuestring

Optional

Parameter value


Parameter82.Namestring

Optional

Parameter name


Parameter82.Valuestring

Optional

Parameter value


Parameter83.Namestring

Optional

Parameter name


Parameter83.Valuestring

Optional

Parameter value


Parameter84.Namestring

Optional

Parameter name


Parameter84.Valuestring

Optional

Parameter value


Parameter85.Namestring

Optional

Parameter name


Parameter85.Valuestring

Optional

Parameter value


Parameter86.Namestring

Optional

Parameter name


Parameter86.Valuestring

Optional

Parameter value


Parameter87.Namestring

Optional

Parameter name


Parameter87.Valuestring

Optional

Parameter value


Parameter88.Namestring

Optional

Parameter name


Parameter88.Valuestring

Optional

Parameter value


Parameter89.Namestring

Optional

Parameter name


Parameter89.Valuestring

Optional

Parameter value


Parameter90.Namestring

Optional

Parameter name


Parameter90.Valuestring

Optional

Parameter value


Parameter91.Namestring

Optional

Parameter name


Parameter91.Valuestring

Optional

Parameter value


Parameter92.Namestring

Optional

Parameter name


Parameter92.Valuestring

Optional

Parameter value


Parameter93.Namestring

Optional

Parameter name


Parameter93.Valuestring

Optional

Parameter value


Parameter94.Namestring

Optional

Parameter name


Parameter94.Valuestring

Optional

Parameter value


Parameter95.Namestring

Optional

Parameter name


Parameter95.Valuestring

Optional

Parameter value


Parameter96.Namestring

Optional

Parameter name


Parameter96.Valuestring

Optional

Parameter value


Parameter97.Namestring

Optional

Parameter name


Parameter97.Valuestring

Optional

Parameter value


Parameter98.Namestring

Optional

Parameter name


Parameter98.Valuestring

Optional

Parameter value


Parameter99.Namestring

Optional

Parameter name


Parameter99.Valuestring

Optional

Parameter value

Create a Stream resource during a live call in order to start a new unidirectional Media Stream. Twilio sends the call's forked audio stream to the url specified in this request.

A sample request is shown below.

Start a unidirectional Media Stream on a live callLink to code sample: Start a unidirectional Media Stream on a live call
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createStream() {
11
const stream = await client
12
.calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.streams.create({
14
name: "My Media Stream",
15
url: "wss://example.com/a-websocket-server",
16
});
17
18
console.log(stream.sid);
19
}
20
21
createStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"call_sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXX",
4
"sid": "MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"name": "My Media Stream",
6
"status": "in-progress",
7
"date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
8
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
9
}

You can also create a unidirectional Media Stream with custom parameters.

Twilio sends these custom parameters to your WebSocket server in the start WebSocket message. Learn more on the WebSocket Messages page.

Use the parameter[x].name and parameter[x].value parameters to specify key-value pairs. For example, parameter1.name is the key and parameter1.value is the value of a key-value pair. You can provide up to 99 key-value pairs (parameter99.name and parameter99.value).

An example request is shown below.

Start a unidirectional Media Stream with custom parametersLink to code sample: Start a unidirectional Media Stream with custom parameters
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createStream() {
11
const stream = await client
12
.calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.streams.create({
14
name: "My Media Stream",
15
"parameter1.name": "agent_name",
16
"parameter1.value": "Mary",
17
"parameter2.name": "Department",
18
"parameter2.value": "sales",
19
url: "wss://example.com/a-websocket-server",
20
});
21
22
console.log(stream.sid);
23
}
24
25
createStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"call_sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
4
"sid": "MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"name": "My Media Stream",
6
"status": "in-progress",
7
"date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
8
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
9
}

Update a Stream resource

update-a-stream-resource page anchor
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json

To stop a live unidirectional Media Stream, update the Stream resource's status to stopped.

Property nameTypeRequiredPIIDescription
AccountSidSID<AC>required

The SID of the Account that created this Stream resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

CallSidSID<CA>required

The SID of the Call the Stream resource is associated with.

Pattern: ^CA[0-9a-fA-F]{32}$Min length: 34Max length: 34

Sidstringrequired

The SID or the name of the Stream resource to be stopped

Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Statusenum<string>required

The status of the Stream you wish to stop. Only possible value is stopped.

Possible values:
stopped

An example request is shown below.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateStream() {
11
const stream = await client
12
.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.streams("Sid")
14
.update({ status: "stopped" });
15
16
console.log(stream.sid);
17
}
18
19
updateStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"sid": "Sid",
5
"name": null,
6
"status": "stopped",
7
"date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
8
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
9
}

You can also use the Stream name (if provided when creating the Stream) to stop the Stream. The example below shows how to stop a Stream with a name of myStream.

Stop a unidirectional Media Stream by nameLink to code sample: Stop a unidirectional Media Stream by name
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateStream() {
11
const stream = await client
12
.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.streams("myStream")
14
.update({ status: "stopped" });
15
16
console.log(stream.sid);
17
}
18
19
updateStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"sid": "myStream",
5
"name": "myStream",
6
"status": "stopped",
7
"date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
8
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
9
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.