---
title: "Use Twilio to send text messages · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/product-services/twilio-sms
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use Twilio to send text messages

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Product services](https://agentwranglers.se/playbook/stack/product-services)
- Rule: Send text messages through a Twilio Messaging Service with the official SDK, and keep phone numbers in E.164 form.
- Cost: Paid. Twilio charges per message and per phone number. No open source service can deliver text messages, because that needs contracts with phone carriers in each country.
- How: Twilio's Python SDK dates from November 2009, and its npm package reached 1.0.0 in March 2013. The npm SDK 6.2.0 and the Python SDK 9.12.0 shipped on 12 October 2026. They had about 3.7 and 5.2 million weekly downloads, both MIT-licensed. Messages still go to the `2010-04-01` API path, so the interface has stayed stable for 16 years. Numbers and opt-outs are your own data, and sender registrations can move to another carrier. Follow [Register every sender before you send](https://agentwranglers.se/playbook/notifications/text-messages/sms-sender-registration) and [Guard text sending against SMS pumping](https://agentwranglers.se/playbook/notifications/text-messages/sms-pumping). Choose something else when your app already runs on one cloud and sends only codes. AWS End User Messaging or Vonage then save a second vendor.
- Check: Every send names a Messaging Service, not a single sender number. Every stored phone number matches `^\+[1-9]\d{1,14}$`.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
import twilio from 'twilio';

const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);

export const sendText = (to, body) => client.messages.create({
  to, body, messagingServiceSid: process.env.TWILIO_MESSAGING_SERVICE_SID,
});
```

### Python example

```python
import os
from twilio.rest import Client

client = Client(os.environ["TWILIO_ACCOUNT_SID"], os.environ["TWILIO_AUTH_TOKEN"])

def send_text(to: str, body: str):
    return client.messages.create(to=to, body=body, messaging_service_sid=os.environ["TWILIO_MESSAGING_SERVICE_SID"])
```

## Sources

- [Twilio Message resource](https://www.twilio.com/docs/messaging/api/message-resource)

## Related rules

- [Register every sender before you send](https://agentwranglers.se/playbook/notifications/text-messages/sms-sender-registration) in Notifications
- [Guard text sending against SMS pumping](https://agentwranglers.se/playbook/notifications/text-messages/sms-pumping) in Notifications

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/product-services/twilio-sms">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use Firebase Cloud Messaging for Android and Apple app push](https://agentwranglers.se/playbook/stack/product-services/fcm-push)
- Next: [Use Plausible for analytics without cookies](https://agentwranglers.se/playbook/stack/product-services/plausible-analytics)
- [Product services](https://agentwranglers.se/playbook/stack/product-services)
