2FA SMS API Ownership: How to Compare Direct Send and OTP in 3 Steps
For 2FA login, an SMS API must distinguish direct send from an OTP endpoint before template permissions can make sense. A receipt must describe a settled payment. A login challenge must prove something about an authentication attempt. Letting both messages pass through one editable template gives the template owner responsibilities that belong in authentication code.
Short answer: give the commerce team ownership of receipt content, and keep challenge creation and verification behind an authentication boundary. Use direct send for receipt notifications. For login SMS, choose between an application-owned challenge service that uses direct send and an OTP endpoint that owns the challenge lifecycle. Compare who controls the message and who verifies the answer before comparing transport costs.
Keep those responsibilities visible. The same distinction matters for public sector appointment alerts: an appointment reminder is a notification; signing in to change that appointment is an authentication operation. This note works through an e-commerce receipt because payment settlement gives the content owner a concrete boundary to enforce.
Before: payment events and login events both become a freely editable SMS body.
After, in words: settlement event → receipt policy → versioned commerce template → notification transport. Login attempt → challenge policy → challenge delivery → verification decision. Logs join the stages through identifiers, without copying message bodies or codes.
Step 1: Make template ownership executable
Start with a small contract. In this example, commerce owns the receipt template and identity owns the login challenge template. These are proposed application roles, not claims about a particular service. A template version records what the application selected; it doesn't establish that a message reached a person.
The following TypeScript snippets run independently in a TypeScript-capable runtime. They use local fixtures and no network calls. First, reject a receipt request unless the input explicitly represents a settled payment:
type Payment = { orderId: string; state: "pending" | "settled"; }; function receiptPlan(payment: Payment) { if (payment.state !== "settled") { throw new Error("Receipt requires payment settlement"); } return { orderId: payment.orderId, templateId: "order-receipt", templateVersion: 3, templateOwner: "commerce", purpose: "receipt", }; } const plan = receiptPlan({ orderId: "order-234", state: "settled" }); console.assert(plan.templateOwner === "commerce"); console.log(plan); let rejected = false; try { receiptPlan({ orderId: "order-235", state: "pending" }); } catch { rejected = true; } if (!rejected) throw new Error("Pending payment passed the receipt policy"); That rejection is useful. A perfectly rendered receipt can still be the wrong message if an earlier checkout event triggered it. The example checks the input contract; in a deployed system, validate the event's origin and settlement semantics at ingestion. A caller-supplied string alone cannot establish payment truth.
Version 3 is an illustrative template revision. Pin a revision when creating the send intent so a retry doesn't silently pick up tomorrow's wording. The trade-off is deliberate: reproducible sends require a release process for template changes. Give the template owner a preview and review workflow, including the data fields they may render.
Step 2: Separate direct delivery from challenge ownership
A direct-send interface accepts a destination and message content. An OTP interface is useful here only if its documented contract includes the challenge operations your application needs. Don't infer verification, expiration, attempt limits, or replay handling from the presence of an SMS send operation. Establish those responsibilities explicitly during integration review.
Use a policy decision before an adapter gets called. This second snippet demonstrates that decision without implementing an authentication system:
type Intent = | { purpose: "receipt"; templateOwner: "commerce" } | { purpose: "login"; challengeOwner: "application" | "endpoint" }; function route(intent: Intent) { if (intent.purpose === "receipt") { return { operation: "direct-send", verifier: "none" }; } return intent.challengeOwner === "application" ? { operation: "application-challenge", verifier: "application" } : { operation: "otp-challenge", verifier: "endpoint" }; } const receipt = route({ purpose: "receipt", templateOwner: "commerce" }); const localLogin = route({ purpose: "login", challengeOwner: "application" }); const endpointLogin = route({ purpose: "login", challengeOwner: "endpoint" }); if (receipt.operation !== "direct-send") throw new Error("Wrong receipt route"); if (localLogin.verifier !== "application") throw new Error("Missing verifier"); if (endpointLogin.verifier !== "endpoint") throw new Error("Wrong verifier"); console.log({ receipt, localLogin, endpointLogin }); The application-challenge branch would create a challenge under your authentication policy, then call direct send through its delivery adapter. It is intentionally a different operation from rendering a receipt. Choosing this branch means accepting responsibility for secure generation, storage, expiry, attempt limits, and consumption of challenges. The snippet only chooses the owner; it supplies none of those security controls.
An endpoint-owned branch moves those responsibilities behind another contract. Check its actual template controls, verification behavior, and observable events before adopting that boundary. Restricting edits to authentication wording may be an acceptable trade-off when the identity owner wants a smaller customization surface. Commerce can still control receipt copy independently.
An authenticator app introduces another authentication path to evaluate, including enrollment and recovery. Keep that evaluation separate from receipt delivery. A notification transport decision cannot settle the application's entire authentication design.
Step 3: Record evidence that answers the right question
Now make the boundary observable. Record the template owner and revision with the send intent. Record transport acceptance separately from a verification result. A useful review question is: could this dashboard mistake a sent receipt for a completed login?
Acceptance isn't verification.
This final fixture checks an evidence record before logging it. Its allowlist keeps message content out of this particular record by construction:
type ReceiptEvidence = { event: "receipt.send_requested"; orderId: string; sendIntentId: string; templateOwner: "commerce"; templateVersion: number; }; function logReceipt(input: ReceiptEvidence) { const record = { event: input.event, orderId: input.orderId, sendIntentId: input.sendIntentId, templateOwner: input.templateOwner, templateVersion: input.templateVersion, }; const serialized = JSON.stringify(record); if (serialized.includes("receipt.verified")) { throw new Error("Receipt evidence cannot assert verification"); } console.log(serialized); return record; } const evidence = logReceipt({ event: "receipt.send_requested", orderId: "order-234", sendIntentId: "receipt-order-234", templateOwner: "commerce", templateVersion: 3, }); if (evidence.event !== "receipt.send_requested") { throw new Error("Unexpected evidence event"); } The fixture records a request, so it makes no delivery claim. In production, persist the send intent and enforce its uniqueness in durable storage before retrying dispatch. Reusing an identifier in a log does not deduplicate anything. Decide how to reconcile an uncertain transport response before adding automatic retries; the acceptance contract determines what evidence is available.
For a deployment check, replay the pending-payment fixture, the settled-payment fixture, and both login ownership branches. Preview the pinned receipt revision with representative order data. Then check the emitted events. A template-only release should pass the receipt checks and preserve the authentication contract.
For monitoring, count receipt requests, transport acceptances, and verification outcomes as separate measures. Use stable labels such as purpose and owner for aggregate metrics; keep order and send-intent identifiers in access-controlled diagnostic records. Define alert thresholds from the team's expected traffic and response objectives. There is no measured baseline in this example from which to claim a universal threshold.
How should a 2FA login SMS API separate direct send from an OTP endpoint?
Yes, if its permissions and contracts preserve the distinction. Shared rendering infrastructure can offer separate namespaces, reviewers, and allowed variables. The risky shortcut is allowing a receipt editor to change an authentication message's meaning or remove a field the login flow depends on. Test that boundary during review, especially when a shared layout changes.
Browser-assisted code entry is a separate concern. MDN describes WebOTP as a way for a website to obtain a one-time password from a specially formatted SMS after user consent, with origin binding and browser support considerations. If that capability is part of your login design, treat the required SMS formatting as an authentication contract. Don't let a general marketing or receipt template edit casually rewrite it. Code retrieval still needs a verification decision in your application flow.
The other likely objection is operational overhead: why maintain distinct policies for messages sent to the same customer? Because the evidence must answer different questions. For the receipt, ask which settled order selected which approved template. For login, ask which challenge was verified under which authentication policy. Shared adapters can reduce duplicated integration work while those policies remain explicit. Evaluate cost alongside review effort, incident diagnosis, and the team's capacity to operate its chosen challenge owner; no unit-price comparison answers those ownership questions.
For email receipts, SPF addresses another boundary. RFC 7208 specifies how a domain authorizes hosts to use its domain in SMTP identities. It does not establish that an order settled or that receipt wording was approved. Keep sender authorization, commerce policy, and authentication decisions separately testable.
Choose template permissions first. Then connect delivery and verification to the owners who can explain their evidence. The receipt path should end with an auditable notification outcome; the login path needs an explicit verification outcome before access is granted.
Sources
References:
- RFC 7208, Sender Policy Framework (SPF): https://datatracker.ietf.org/doc/html/rfc7208
- MDN, WebOTP API: https://developer.mozilla.org/en-US/docs/Web/API/WebOTP_API