---
title: "Fail over to a second text provider · Agent Wranglers"
url: https://agentwranglers.se/playbook/notifications/text-messages/sms-provider-failover
id: NTF-44
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1052
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Fail over to a second text provider

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Text messages](https://agentwranglers.se/playbook/notifications/text-messages.md).

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

- ID: NTF-44
- Level: Recommended
- Chapter: [Text messages](https://agentwranglers.se/playbook/notifications/text-messages.md)
- Rule: For sign-in codes and other critical texts, keep a second provider with its own registered senders. Switch to it when the first provider's error rate or delivery time passes a set limit.
- Check: A test makes the first provider's adapter return errors. The next code text goes out through the second provider, once. A monthly drill sends one live code through the second provider to a team phone and it arrives.
- How: A text provider outage, or one carrier route going bad, stops every sign-in that needs a code. Register your senders with both providers ahead of time, as [Register every sender before you send](https://agentwranglers.se/playbook/notifications/text-messages/sms-sender-registration.md) says, because a new registration can take weeks. Send through one interface with an adapter per provider. Count failed API calls and the time from send to the delivered callback per provider and country, as [Track what happened to each text](https://agentwranglers.se/playbook/notifications/text-messages/sms-delivery-status.md) records. Switch when, for example, 5 percent of calls fail over 5 minutes, or the median delivery time passes 60 seconds. Keep one idempotency key per message, so a retry on the second provider never sends two codes. Push has no second route, since APNs and FCM are the only services for their devices, so offer another channel instead.

## 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
const FAILOVER_ERROR_RATE = 0.05;

export async function sendCritical(message) {
  const [primary, backup] = providers;
  const healthy = (await health.errorRate(primary.name, 300)) < FAILOVER_ERROR_RATE;
  const first = healthy ? primary : backup;
  try {
    return await first.send(message, { idempotencyKey: message.id });
  } catch {
    return (first === primary ? backup : primary).send(message, { idempotencyKey: message.id });
  }
}
```

### Python example

```python
FAILOVER_ERROR_RATE = 0.05

def send_critical(message):
    primary, backup = providers
    first = primary if health.error_rate(primary.name, 300) < FAILOVER_ERROR_RATE else backup
    try:
        return first.send(message, idempotency_key=message.id)
    except ProviderError:
        other = backup if first is primary else primary
        return other.send(message, idempotency_key=message.id)
```

## Sources

- [Twilio, Track the message status of outbound messages](https://www.twilio.com/docs/messaging/guides/track-outbound-message-status)

## Related rules

- NTF-22 [Register every sender before you send](https://agentwranglers.se/playbook/notifications/text-messages/sms-sender-registration.md) in Notifications
- NTF-29 [Track what happened to each text](https://agentwranglers.se/playbook/notifications/text-messages/sms-delivery-status.md) 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/notifications/text-messages/sms-provider-failover">Agent Wranglers notifications playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Link only to your own domain in texts](https://agentwranglers.se/playbook/notifications/text-messages/sms-own-domain-links.md)
- Next: [Treat WhatsApp and RCS as channels with their own opt-in](https://agentwranglers.se/playbook/notifications/text-messages/chat-app-channels.md)
- [Text messages](https://agentwranglers.se/playbook/notifications/text-messages.md)
