SMS API

Exchange text and picture messages in the programming language you use.

Sign up and start building

Enter your phone number and receive an SMS

  • What's Happening
  • Technical Version

When you click "Send SMS", a request is sent to Twilio to deliver an SMS to the provided phone number. The server logic determines the weather forecast for San Francisco and sends a related message and graphic to the phone number.

When you click "Send SMS", an AJAX request is made that, in turn, triggers a server-side HTTP request to Twilio, which provides a number to SMS, as well as a URL of the photo to be delivered. Image media is automatically transcoded as needed to adapt to carriers and handsets.

Note that picture messages outside of US and Canada will be delivered as a hyperlink.

  • PHP
  • Node
  • Python
  • Ruby
  • Java
  • .NET (C#)
<?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 = "AC5ef872f6da5a21de157d80997a64bd33";
$token = "your_auth_token";
$client = new Client($sid, $token);

$client->messages->create(
  "+16518675309",
  array(
    'from' => "+14158141829",
    'body' => "Tomorrow's forecast in Financial District, San Francisco is Clear.",
    'mediaUrl' => "https://climacons.herokuapp.com/clear.png",
  )
);
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using System.Collections.Generic;

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

    var mediaUrl = new List() {
      new Uri( "https://climacons.herokuapp.com/clear.png" )
    };
    var to = new PhoneNumber("+16518675309");
    var message = MessageResource.Create(
      to,
      from: new PhoneNumber("+14158141829"),
      body: "Tomorrow's forecast in Financial District, San Francisco is Clear",
      mediaUrl: mediaUrl);
    Console.WriteLine(message.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

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

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

    Message message = Message
      .creator(new PhoneNumber("+16518675309"), new PhoneNumber("+14158141829"),
        "Tomorrow's forecast in Financial District, San Francisco is Clear")
      .setMediaUrl("https://climacons.herokuapp.com/clear.png")
      .create();

    System.out.println(message.getSid());
  }
}
// Twilio Credentials
const accountSid = 'AC5ef872f6da5a21de157d80997a64bd33';
const authToken = 'your_auth_token';

// require the Twilio module and create a REST client
const client = require('twilio')(accountSid, authToken);

client.messages
  .create({
    to: '+16518675309',
    from: '+14158141829',
    body: "Tomorrow's forecast in Financial District, San Francisco is Clear",
    mediaUrl: 'https://climacons.herokuapp.com/clear.png',
  })
  .then((message) => console.log(message.sid));
from twilio.rest import Client

# put your own credentials here
account_sid = "AC5ef872f6da5a21de157d80997a64bd33"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

client.messages.create(
  to="+16518675309",
  from_="+14158141829",
  body="Tomorrow's forecast in Financial District, San Francisco is Clear",
  media_url="https://climacons.herokuapp.com/clear.png")
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'

# put your own credentials here
account_sid = 'AC5ef872f6da5a21de157d80997a64bd33'
auth_token = '[AuthToken]'

# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token

@client.account.messages.create({
  :from => '+14158141829',
  :to => '+16518675309',
  :body => 'Tomorrow\'s forecast in Financial District, San Francisco is Clear.',
  :media_url => 'https://climacons.herokuapp.com/clear.png'
})

Powerful API Primitives

  • <Message> using custom app logic

    Webhooks allow your app to define custom logic for every response. Build nearly any workflow you can imagine.

    View Docs
    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
      <Message>ahoy!</Message>
    </Response>
  • Send pictures with <Media>

    Send and receive pictures on all U.S. and Canadian phone numbers.

    View Docs
    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
      <Message>
        <Body>You need to see this to believe it...</Body>
        <Media>https://demo.twilio.com/owl.png</Media>
      </Message>
    </Response>
  • Real-time status webhooks

    See every step your message takes as it traverses the global telecom network.

    View Docs
    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
      <Message statusCallback="/SMSHandler.php">ahoy!</Message>
    </Response>

Browse examples of SMS use cases.

The Twilio advantage

Communicate reliably

Experience a 99.95% uptime SLA made possible with automated failover and zero maintenance windows.

Operate at scale

Extend the same app you write once to new markets with configurable features for localization and compliance.

Many channels

Use the same platform you know for voice, SMS, video, chat, two-factor authentication, and more.

No shenanigans

Get to market faster with pay-as-you-go pricing, free support, and the freedom to scale up or down without contracts.