sms-bridge
sms-bridge accepts an SMS message, selects a provider, delivers the message, and records the result. The built-in providers are BulkSMSBd, GreenWeb, and a sandbox provider that does not call a vendor.
Integrations
There are two integrations. An application uses one of them.
| Integration | Use it when |
|---|---|
| Library | The application runs on Node.js or Bun and calls SMSBridge.send(). |
| Self-hosting | The application is not a Node.js or Bun process. Run the HTTP server and call the HTTP API. |
Self-hosting is the HTTP API. The library does not send requests to that API. A provider class written in an application is visible only to the library process that constructed it. The server image loads the built-in providers. See Custom providers.
Better Auth sends its phone-number and two-factor codes through either integration. Better Auth creates the code and checks it. sms-bridge delivers the SMS.
A coding agent implementing either integration follows Agents.
Message processing
The following sequence applies to both integrations.
- The caller sends
POST /v1/sms/sendwith a profile API key, or callsSMSBridge.send(). - The message is stored with status
pending. When a queue is in use, the status becomesqueued. - Queued delivery runs in a worker. Direct delivery runs in the caller.
- Routing selects a provider. See Routing.
- The provider gateway performs the vendor request. On a library send,
metadatais passed to that gateway. sms-bridge does not interpretmetadata. - A successful send sets the status to
sentand records a success for that provider. A failed send records a failure and selects the next candidate. When every candidate fails, the status isfailed. A queued job is then thrown so that BullMQ can retry it.
A profile is a tenant. It has an API key, a routing strategy, and the set of providers it may use.
Routing
The routing engine filters the candidates, then applies the profile strategy.
- When the request sets
isMaskedtotrue, candidates without a masked sender ID are removed. - When
routingHintnames a remaining candidate by id, name, or type, that candidate is selected. - Otherwise the strategy in the following table is applied.
| Strategy | Selection |
|---|---|
rule_based | The first rule whose prefix matches the start of the recipient. When none match, the rule that sets default. |
weighted_distribution | A random candidate, using the configured weights. |
fixed | The first remaining candidate. |
priority_failover | The candidate with the highest optimisticBalance * healthScore. |
health_aware | The same ordering as priority_failover. |
Health is the ratio of successful attempts to total attempts over the last 50 attempts. A failed send removes that candidate and runs selection again.
The health_aware configuration may include window_size and fail_threshold. The health tracker does not read those fields. The window is 50 attempts.