Get Started

Install the Twilio Ruby Helper Library

The twilio-ruby helper library lets you write Ruby code to make HTTP requests to the Twilio API.

The easiest way to install twilio-ruby is from RubyGems. In the command line, run gem install twilio-ruby:

# Be sure to type "twilio-ruby", not just "twilio"
gem install twilio-ruby

Or, you can clone the source code for twilio-ruby, and install the library from there.

"Permission Denied"

If the command line gives you a big long error message that says Permission Denied in the middle of it, try running the above commands with sudo, ex. sudo gem install twilio.

Testing your installation

Try sending yourself an SMS message, like this:

require 'rubygems'
require 'twilio-ruby'

# Get your Account Sid and Auth Token from
account_sid = 'AC32a3c49700934481addd5ce1659f04d2'
auth_token = ''
@client = account_sid, auth_token

message = @client.account.sms.messages.create(:body => "Jenny please?! I love you <3",
    :to => "+14159352345",     # Replace with your phone number
    :from => "+14158141829")   # Replace with your Twilio number
puts message.sid

More Documentation

The Rest API Documentation has examples written in Ruby for every kind of action you could take with the Twilio API. You should start there if you know what you want to do with the Ruby library. If you'd like to learn more about how Twilio works, or for inspiration about what to build, try the Ruby quickstarts.


If the Twilio API returns a 400 or a 500 level HTTP response, the twilio-ruby library will throw a Twilio::REST::RequestError. 400-level errors are normal during API operation ("Invalid number", "Cannot deliver SMS to that number", for example) and should be handled appropriately.

require 'twilio-ruby'

    client = account_sid, auth_token
      from => from_number,
      to =>   to_number,
      body => "Hello World"
rescue Twilio::REST::RequestError => e
    puts e.message