Skip to content

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.

IntegrationUse it when
LibraryThe application runs on Node.js or Bun and calls SMSBridge.send().
Self-hostingThe 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.

  1. The caller sends POST /v1/sms/send with a profile API key, or calls SMSBridge.send().
  2. The message is stored with status pending. When a queue is in use, the status becomes queued.
  3. Queued delivery runs in a worker. Direct delivery runs in the caller.
  4. Routing selects a provider. See Routing.
  5. The provider gateway performs the vendor request. On a library send, metadata is passed to that gateway. sms-bridge does not interpret metadata.
  6. A successful send sets the status to sent and records a success for that provider. A failed send records a failure and selects the next candidate. When every candidate fails, the status is failed. 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.

  1. When the request sets isMasked to true, candidates without a masked sender ID are removed.
  2. When routingHint names a remaining candidate by id, name, or type, that candidate is selected.
  3. Otherwise the strategy in the following table is applied.
StrategySelection
rule_basedThe first rule whose prefix matches the start of the recipient. When none match, the rule that sets default.
weighted_distributionA random candidate, using the configured weights.
fixedThe first remaining candidate.
priority_failoverThe candidate with the highest optimisticBalance * healthScore.
health_awareThe 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.