REST API: Network Traversal Service Tokens

Network Traversal Service Tokens are ephemeral credentials that let you access TURN resources from WebRTC and VoIP clients. They are a secure way to create communication sessions with web browsers or mobile apps without exposing credentials in a client-side environment. All tokens have a limited lifetime to protect you from abuse. The lifetime is configurable up to 24 hours (which is also the default value) but you should make it as short as possible for your application.

Token List Resource

Resource URI

/2010-04-01/Accounts/{AccountSid}/Tokens

Resource Properties

A Token instance resource has the following properties

Property Description
Username The temporary username that uniquely identifies a Token.
Password The temporary password that the username will use when authenticating with Twilio.
Ttl The duration in seconds for which the username and password are valid, the default value is 86,400 (24 hours)
AccountSid The unique id of the Account that created this Token.
IceServers An array representing the ephemeral credentials and the STUN and TURN server URIs.
DateCreated The date that this resource was created, given in RFC 2822 format.
DateUpdated The date that this resource was last updated, given in RFC 2822 format.

HTTP GET

Not Supported

HTTP POST

You can create a new Token resource by POSTing to the Tokens list resource. Since the purpose of tokens is to provide short-lived credentials, usernames and passwords are always auto-generated and not intended to be stored long term.

Optional Parameters

You may POST the following parameters:

Parameter Description
Ttl The duration in seconds for which the generated credentials are valid, the default value is 86400 (24 hours).
Examples
Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
  .create()
  .then((token) => process.stdout.write(token.username));
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken();
    
    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create();
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create
puts token.username
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create();

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create();

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.tokens.create
puts token.username
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({}, function(err, token) {
    process.stdout.write(token.username);
});
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import java.util.ArrayList;
import org.apache.http.NameValuePair;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(new ArrayList<NameValuePair>());
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().create();

    System.out.println(token.getUsername());
  }
}
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
        }
    ],
    "password": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
    "registrars": null,
    "ttl": "86400",
    "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
    <Password>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>86400</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
        <Credential>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>
Create a Token Resource
Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
	.create({'ttl': 3600})
	.then((token) => process.stdout.write(token.username));
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;

class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken(3600);

    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create(3600);
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create(:ttl => 3600)
puts token.username
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create(ttl: 3600);

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create(
    array("ttl" => 3600)
);

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.tokens.create(:ttl => 3600)
puts token.username
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({
	"ttl": 3600
}, function(err, token) {
    process.stdout.write(token.username);
});
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import com.twilio.sdk.resource.list.TokenList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

	List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Ttl", "3600"));

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(params);
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().setTtl(3600).create();

    System.out.println(token.getUsername());
  }
}
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
        }
    ],
    "password": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
    "registrars": null,
    "ttl": "3600",
    "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
    <Password>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>3600</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
        <Credential>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>
Create Token Resource during 1 hour

HTTP PUT

Not Supported.

HTTP DELETE

Not Supported.

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
  .create()
  .then((token) => process.stdout.write(token.username));
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken();
    
    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create();
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create
puts token.username
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create();

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create();

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.tokens.create
puts token.username
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({}, function(err, token) {
    process.stdout.write(token.username);
});
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import java.util.ArrayList;
import org.apache.http.NameValuePair;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(new ArrayList<NameValuePair>());
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().create();

    System.out.println(token.getUsername());
  }
}
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
        }
    ],
    "password": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
    "registrars": null,
    "ttl": "86400",
    "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
    <Password>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>86400</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
        <Credential>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
	.create({'ttl': 3600})
	.then((token) => process.stdout.write(token.username));
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;

class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken(3600);

    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create(3600);
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create(:ttl => 3600)
puts token.username
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create(ttl: 3600);

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create(
    array("ttl" => 3600)
);

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.tokens.create(:ttl => 3600)
puts token.username
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({
	"ttl": 3600
}, function(err, token) {
    process.stdout.write(token.username);
});
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import com.twilio.sdk.resource.list.TokenList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

	List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Ttl", "3600"));

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(params);
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().setTtl(3600).create();

    System.out.println(token.getUsername());
  }
}
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
        }
    ],
    "password": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
    "registrars": null,
    "ttl": "3600",
    "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
    <Password>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>3600</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
        <Credential>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>