Skip to contentSkip to navigationSkip to topbar
On this page

Proxy Quickstart


(error)

Proxy Public Beta is not available to new customers

Proxy Public Beta is currently closed for new customers. Please consider using Twilio Conversations and Programmable Voice directly if you are building your masking application.

Note that this does not have any impact on Twilio Flex customers.

(warning)

Public Beta for customers already using Proxy

Twilio's Proxy API is currently available as a Public Beta product. Some features are not yet implemented and others may be changed before the product is declared as Generally Available.

Public Beta products are not covered by a Twilio SLA(link takes you to an external page).

With just a few lines of code, you can have a text and/or voice conversations between two cloaked participants.

In this Quickstart, you will learn how to:

  1. Purchase a Twilio phone number
  2. Gather your account information
  3. Set up your development environment
  4. Create a Proxy service
  5. Add a phone number to your service
  6. Create a session
  7. Create participants
  8. Send a text message
  9. Make a voice call

To test this quickstart, make sure you have two phone numbers you wish to connect ready to go (perhaps two cell phones?).


Purchase a Twilio phone number

purchase-a-twilio-phone-number page anchor

The first thing you need in order to set up a proxied session is a Twilio-powered phone number. You can grab one to use in the console here.

Make sure that it has SMS and/or Voice enabled for the purposes of this quickstart. Note that in many countries, numbers will only have either Voice or SMS capability; to test both features you will need both types in your number pool. US and Canadian numbers will have both capabilities.

A screenshot of the 'Buy a number' page in Twilio's Phone Numbers console. In the top right, we can see Voice and SMS capabilities are both selected.

You'll want at least two phone numbers in your Proxy pool.

Once you buy your preferred numbers, make a note of the Twilio string identifier (SID) of the number. You'll need it for this quickstart.


Gather your account information

gather-your-account-information page anchor

You can find these in the Twilio Console(link takes you to an external page).

  • Account SID - Used to authenticate REST API requests
  • Auth Token - Used to authenticate REST API requests
Find your Account SID and Auth Token in the Twilio Console: in the middle of this screenshot, a red box highlights 'Account Info', which lists Account SID and Auth Token (both obscured in this image). Each field has an icon for copying these values to the clipboard.

For all of our code snippets and curl examples, you will need to authenticate with the Account SID and Auth Token.


Set up your development environment

set-up-your-development-environment page anchor

The next steps will involve writing some code. We've provided examples in multiple languages, but you will need a working development environment in at least one of them. Here are some guides we've written to help you get your Twilio development environment up and running:

We also provide examples for the curl command(link takes you to an external page) line which should work from a Linux or macOS terminal.


Note: You can also create Services via the console for Proxy.(link takes you to an external page)
Let's create a service that will contain our sessions:

Create a ServiceLink to code sample: Create a Service
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 createService() {
11
const service = await client.proxy.v1.services.create({
12
uniqueName: "unique_name",
13
});
14
15
console.log(service.sid);
16
}
17
18
createService();

Output

1
{
2
"sid": "KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"chat_instance_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"unique_name": "unique_name",
6
"default_ttl": 3600,
7
"callback_url": "http://www.example.com",
8
"geo_match_level": "country",
9
"number_selection_behavior": "prefer-sticky",
10
"intercept_callback_url": "http://www.example.com",
11
"out_of_session_callback_url": "http://www.example.com",
12
"date_created": "2015-07-30T20:00:00Z",
13
"date_updated": "2015-07-30T20:00:00Z",
14
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"links": {
16
"sessions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions",
17
"phone_numbers": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers",
18
"short_codes": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes"
19
}
20
}

Take a note of the service SID (KSxxxx) that you get as a response.


Add a phone number to your service

add-a-phone-number-to-your-service page anchor

We need to associate the number(s) we bought with our newly created service. The phone numbers you add will be added to the anonymous number pool for your proxied communications.

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 createPhoneNumber() {
11
const phoneNumber = await client.proxy.v1
12
.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.phoneNumbers.create({ sid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" });
14
15
console.log(phoneNumber.sid);
16
}
17
18
createPhoneNumber();

Output

1
{
2
"sid": "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"date_created": "2015-07-30T20:00:00Z",
6
"date_updated": "2015-07-30T20:00:00Z",
7
"phone_number": "+1987654321",
8
"friendly_name": "Friendly Name",
9
"iso_country": "US",
10
"capabilities": {
11
"sms_outbound": true,
12
"voice_inbound": false
13
},
14
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"is_reserved": false,
16
"in_use": 0
17
}

This adds a single number to the Proxy pool. Repeat for each of your Twilio phone numbers


A session is a conversation between two people. This code will create a new session in your Proxy service.

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 createSession() {
11
const session = await client.proxy.v1
12
.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.sessions.create({ uniqueName: "MyFirstSession" });
14
15
console.log(session.sid);
16
}
17
18
createSession();

Output

1
{
2
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"status": "open",
4
"unique_name": "MyFirstSession",
5
"date_started": "2015-07-30T20:00:00Z",
6
"date_ended": "2015-07-30T20:00:00Z",
7
"date_last_interaction": "2015-07-30T20:00:00Z",
8
"date_expiry": "2015-07-30T20:00:00Z",
9
"ttl": 3600,
10
"mode": "voice-and-message",
11
"closed_reason": "",
12
"sid": "KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"date_updated": "2015-07-30T20:00:00Z",
14
"date_created": "2015-07-30T20:00:00Z",
15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"links": {
18
"interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Interactions",
19
"participants": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants"
20
}
21
}

Note the session SID (KCxxxx) from the response you get.


You can't have a good conversation without participants, so let's add some.

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 createParticipant() {
11
const participant = await client.proxy.v1
12
.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.sessions("KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.participants.create({
15
friendlyName: "Alice",
16
identifier: "+15558675310",
17
});
18
19
console.log(participant.proxyIdentifier);
20
}
21
22
createParticipant();

Output

1
{
2
"sid": "KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"session_sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
4
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"identifier": "+15558675310",
7
"proxy_identifier": "+14155559999",
8
"proxy_identifier_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"friendly_name": "Alice",
10
"date_deleted": "2015-07-30T20:00:00Z",
11
"date_updated": "2015-07-30T20:00:00Z",
12
"date_created": "2015-07-30T20:00:00Z",
13
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"links": {
15
"message_interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/MessageInteractions"
16
}
17
}

Run it again with a second participant (a different phone number for another proxied user, and a different 'Friendly Name').

For each participant, you'll receive a response with the participant's assigned Proxy number, which will come from the pool of numbers you've added. Depending on the capabilities of the phone number, next either send a text message in the conversation or make a voice call.


If your number has text messaging capabilities, you're ready to roll! If you're looking at a voice proxy, skip to the next section.

Let's send a message from one of the assigned Proxy numbers to one of the participants. Execute the following for one of the participants (the participant you'd like to receive this initial message):

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 createMessageInteraction() {
11
const messageInteraction = await client.proxy.v1
12
.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.sessions("KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.participants("KPXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
15
.messageInteractions.create({ body: "Reply to this message to chat!" });
16
17
console.log(messageInteraction.sid);
18
}
19
20
createMessageInteraction();

Output

1
{
2
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"data": "{\"body\":\"some message\"}",
4
"date_created": "2015-07-30T20:00:00Z",
5
"date_updated": "2015-07-30T20:00:00Z",
6
"participant_sid": "KPXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
7
"inbound_participant_sid": null,
8
"inbound_resource_sid": null,
9
"inbound_resource_status": null,
10
"inbound_resource_type": null,
11
"inbound_resource_url": null,
12
"outbound_participant_sid": "KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"outbound_resource_sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"outbound_resource_status": "sent",
15
"outbound_resource_type": "Message",
16
"outbound_resource_url": null,
17
"sid": "KIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"type": "message",
19
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/MessageInteractions/KIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
20
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"session_sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
22
}

And with that, the Proxy text conversation can continue!


If your Twilio Phone Numbers are voice capable, you're now ready for a proxied voice conversation. Following the names from the previous steps, get Alice to make a call to her Proxy Identifier number. Twilio's Proxy service will then make a call from Bob's Proxy Number to his real number and connect the two calls.

Now you're talking anonymously!

(warning)

Warning

If voicemail is enabled for your real number, your outgoing voicemail message may reveal your real number to people who call your proxied number.

Review your outgoing voicemail message to ensure that it does not include your real number. Remember that many default voicemail messages begin by stating the number that the person has reached.

You now know how to create text and/or voice conversations between two masked participants. To learn more about how Proxy works check out the guide to Phone Number Management or dive into the REST API reference.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.