# How to Call Twilio SMS API from Client-Side JavaScript Securely

> Calling Twilio directly from client-side JS exposes your Account SID and Auth Token, enabling malicious actors to drain your SMS credits with spam campaigns. RealComposer proxies Twilio calls at the edge, attaching Basic Auth headers server-side.

- Canonical page: https://realcomposer.com/recipes/twilio-sms-frontend-proxy
- Client platform: JavaScript / HTML
- Upstream services: Twilio
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/twilio-sms-frontend-proxy.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=twilio-sms-frontend-proxy&via=agent

## Problem: Toll Fraud and Twilio Credit Depletion

Bots crawl web forms for Twilio credentials to send premium-rate SMS messages, creating massive bills.

- Thousands of dollars in SMS toll fraud bills
- Immediate Twilio suspension
- Customer spamming

## Solution steps

1. **Store Twilio Auth in Vault**: Store TWILIO_AUTH_TOKEN in RealComposer.

2. **Expose Verification Endpoint**: Trigger SMS dispatch without client-side credentials.

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Twilio SMS Gateway",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "steps": [
    {
      "stepKey": "twilio",
      "upstreamUrlTemplate": "https://api.twilio.com/2010-04-01/Accounts/{{secrets.TWILIO_ACCOUNT_SID}}/Messages.json",
      "httpMethod": "POST",
      "headersTemplate": {
        "Authorization": "Basic {{secrets.TWILIO_BASIC_AUTH}}"
      },
      "timeoutMs": 4000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "sid",
        "sourceStep": "twilio",
        "sourcePath": "sid"
      },
      {
        "targetPath": "status",
        "sourceStep": "twilio",
        "sourcePath": "status"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/acme/send-sms"
```

## Payload before and after

Raw upstream response:

```json
{
  "sid": "SM123",
  "status": "queued",
  "to": "+14155552671"
}
```

Slimmed RealComposer response:

```json
{
  "sid": "SM123",
  "status": "queued"
}
```

## FAQ

### Does RealComposer prevent SMS pumping?

Yes, per-IP rate limiting and origin checks block automated pumping bots.
