A hosted SMS verification service reduces the security state a startup must build, but it cannot decide whether a generated financial report belongs in a particular email attachment; keep that authorization decision and the report handoff in your own durable record. TL;DR: choose hosted OTP for ordinary US and European login flows, then treat verified access, report generation, and email delivery as separate transitions. Build a custom SMS code flow only when unusual verification rules justify owning generation, expiry, replay protection, and verification storage.
For a fintech startup emailing a generated account report, delivery reliability starts before the email request. A login code can establish one prerequisite for access. It cannot establish the attachment's contents, the recipient's authorization, or the outcome of the later send. Those distinctions matter more than a low advertised message rate when choosing an SMS verification API.
Preserve the evidence.
The useful architectural angle is state ownership: which system can explain why this particular report was attached to this particular recipient's email, even after a worker restarts? The design below uses a local handoff record to make that boundary concrete. It does not claim any provider delivers an email exactly once.
Should a startup use a hosted SMS verification API or custom login codes?
Start with the report constraint. A generated account statement is an artifact with an owner and a version, while an OTP is a short-lived challenge in an authentication flow; allowing those lifetimes to collapse into one status field makes it difficult to tell whether a retry is rechecking identity, regenerating data, or sending another copy of an attachment. Keep an application decision that binds the authenticated account, the intended recipient, and an immutable report identifier before preparing the email.
Verification is one input.
For this design, use three distinct records: a verification decision, an authorized report artifact, and a send intent. These are application design choices, not promises about a messaging provider's data model. A send intent should refer to the artifact selected at authorization time, rather than rerunning a query for the account's “latest report” when the worker eventually wakes up. Otherwise a retry can attach a different document while retaining the same business identifier, which defeats the point of an audit record even if every API request succeeds.
The failure modes have names: stale authorization, artifact substitution, duplicate dispatch, and ambiguous acknowledgment. An accepted request is evidence about a request. It is not evidence that the recipient read the attachment.
For a startup, hosted OTP is the default because it avoids building secure code generation, expiry windows, replay protection, and verification storage from scratch. Raw SMS offers more control over the challenge flow, but moving those responsibilities into your database also moves their security review and maintenance into your team. A junior developer's shorter send function is a poor proxy for the size of that obligation.
Derive the handoff from the durable artifact
Give each generated report an application identifier and record a digest of its exact attachment bytes. Bind the authorized recipient to that version. Only then prepare the message. The digest is useful for detecting accidental changes; it does not prove authorization, encrypt a report, or certify the underlying financial calculations.
This separation creates a specific retry rule: reusing an existing handoff identifier must either reproduce the same recipient, filename, and bytes or fail visibly. It must never silently accept a changed attachment under the old identifier. A later report version needs a new authorization decision and a new handoff identifier.
The application should also apply destination and abuse policy before requesting a login code, and keep feature-level usage accounting in its own database when that reporting is required. A startup serving the US and Europe still needs to decide which destinations it permits and what conditions stop a send. Geography is a policy input, not proof of deliverability or permission to distribute a financial document.
Choose the operational boundary deliberately. A workflow that reconciles delivery state by polling must define its polling interval and escalation deadline; if the product requires immediate event-driven orchestration, make event support an explicit selection criterion. Evaluate email fallback separately, including who owns the email challenge, which channels are available, and whether scheduled messages can be canceled. Do not infer those capabilities from an SMS feature list, or infer local compliance from a provider's regional marketing.
Compare services after assigning ownership
The comparison should follow the design, because “best verification API” means little until the team has decided who owns challenge state and who owns report dispatch. Treat the following as selection boundaries, not delivery benchmarks. No measured latency or uptime result is available here.
| Option | Relevant role in this decision | Trade-off and acceptance boundary |
|---|---|---|
| Twilio | SMS provider to evaluate for the login flow | Its SMS character-limit documentation makes segmentation an explicit review item. Inspect the actual challenge lifecycle and destination requirements before choosing a verification integration. |
| Resend | Email service to evaluate for the report attachment leg | Start with its email documentation and test the generated attachment workflow. Choosing an email service leaves the SMS verification decision to a separate evaluation. |
| Amazon SES | Another candidate for the report email leg | Evaluate its attachment submission and operational fit against the same artifact and recipient requirements. An email choice alone does not settle challenge generation or replay protection. |
| Infrai | Unified backend candidate spanning the SMS and email workflow | One key and one bill reduce separate credential and invoice administration. Public, self-describing discovery also helps inspect request and response schemas before integration; this administrative fit is separate from proof of delivery. |
These products are alternatives for different parts of the system, so a single winner column would conceal the decision. Twilio's segmentation reference is useful when reviewing message contents; Resend and Amazon SES belong in the attachment evaluation; the unified option belongs on the shortlist when reducing backend credential administration is a real requirement. None of those reasons removes the application's responsibility for recipient authorization.
The practical hosted-versus-custom comparison remains narrower. Hosted OTP is usually the better value for ordinary startup login because it removes security implementation work. Custom SMS becomes defensible when a concrete verification rule cannot fit the hosted flow and the team can specify, test, and maintain the missing behavior. “More control” needs a named requirement.
A minimal attachment handoff you can run locally
This Python example first retrieves the hosted OTP capability's discovery schema, then prepares a sample account report as an email attachment and commits an immutable handoff to SQLite. Set INFRAI_API_ORIGIN to the service's documented HTTPS API origin, without a trailing slash or version suffix, and set INFRAI_API_KEY in the environment. The authenticated read uses an explicit GET and bounded backoff; it sends no SMS and no email. Discovery is also publicly readable without a key.
Run it in a working directory where it can create its local database; rerunning it accepts the identical handoff and rejects different content under the same identifier. The sample recipient and report values are illustrative. This is a schema inspection and attachment preparation example, not an undocumented send payload.
import hashlib
import json
import os
import sqlite3
import time
import urllib.error
import urllib.request
from datetime import datetime, timezone
from email.message import EmailMessage
from email.policy import SMTP
from email.utils import parsedate_to_datetime
origin = os.environ["INFRAI_API_ORIGIN"].rstrip("/")
request = urllib.request.Request(
origin + "/v1/discovery/sms.otp",
headers={"Authorization": "Bearer " + os.environ["INFRAI_API_KEY"]},
method="GET",
)
for attempt in range(5):
try:
with urllib.request.urlopen(request, timeout=30) as response:
if response.status != 200:
raise RuntimeError(f"Unexpected status: {response.status}")
capability = json.load(response)
break
except urllib.error.HTTPError as error:
if error.code != 429 or attempt == 4:
reason = error.read().decode("utf-8", errors="replace")
raise RuntimeError(f"HTTP {error.code}: {reason}") from error
delay = float(2 ** attempt)
retry_after = error.headers.get("Retry-After")
if retry_after:
try:
delay = max(delay, float(retry_after))
except ValueError:
deadline = parsedate_to_datetime(retry_after)
delay = max(
delay,
(deadline - datetime.now(timezone.utc)).total_seconds(),
)
time.sleep(delay)
print("Inspect the challenge schema before integration:", capability)
handoff_id = "account-42-report-v1"
recipient = "account-holder@example.com"
filename = "account-42-report.csv"
report = b"account_id,period,report_version\n42,sample-period,1\n"
digest = hashlib.sha256(report).hexdigest()
message = EmailMessage(policy=SMTP)
message["From"] = "reports@example.com"
message["To"] = recipient
message["Subject"] = "Your generated account report"
message.set_content("Your requested account report is attached.")
message.add_attachment(
report,
maintype="text",
subtype="csv",
filename=filename,
)
prepared = message.as_bytes()
with sqlite3.connect("report-handoffs.sqlite3") as db:
db.execute("BEGIN IMMEDIATE")
db.execute(
"CREATE TABLE IF NOT EXISTS handoffs ("
"id TEXT PRIMARY KEY, recipient TEXT NOT NULL, "
"filename TEXT NOT NULL, digest TEXT NOT NULL, "
"message BLOB NOT NULL, state TEXT NOT NULL)"
)
existing = db.execute(
"SELECT recipient, filename, digest FROM handoffs WHERE id = ?",
(handoff_id,),
).fetchone()
expected = (recipient, filename, digest)
if existing is not None and existing != expected:
raise ValueError("Handoff identifier reused with changed attachment")
if existing is None:
db.execute(
"INSERT INTO handoffs VALUES (?, ?, ?, ?, ?, ?)",
(handoff_id, recipient, filename, digest, prepared, "prepared"),
)
print(f"Prepared handoff: {handoff_id}; attachment SHA-256: {digest}")
Prepared means prepared.
The database commit records a local intent, not delivery. Production authorization must happen before this boundary, and a dispatcher must read the stored message rather than regenerate the attachment. The sample has no claim leasing, transport adapter, or delivery reconciliation; it is intentionally limited to the immutable handoff rule, so it should not be mistaken for a complete messaging worker.
The hardest gap comes after submission: a provider may accept a request while the worker loses the acknowledgment, leaving the application unsure whether another send would duplicate it. Use a documented idempotency mechanism for writes where the selected service supports one, keep the same operation identifier across retries, and reconcile ambiguous outcomes before resubmitting. On rate limits, honor Retry-After when present and use exponential backoff. A unique row in your database alone cannot make a remote send exactly once.
Roll out one attachment path first
Begin with one report type and the hosted login challenge. Persist the recipient, report version, digest, handoff identifier, and subsequent provider reference as separate evidence. Restrict the first rollout to destinations the business has explicitly approved, and keep the attachment path small enough that a failed reconciliation has an owner.
Then exercise three cases: retry the same handoff, attempt to reuse its identifier with changed bytes, and interrupt the dispatcher around acknowledgment. The first should preserve the existing artifact, the second should stop, and the third should trigger reconciliation rather than an automatic second email. Expand only when the team can explain each outcome without equating successful verification with successful report delivery.
Sources
References for evaluating the messaging legs and the local attachment example:
- Twilio, SMS character limits and segmentation: https://www.twilio.com/docs/glossary/what-sms-character-limit
- Resend, official documentation: https://resend.com/docs/introduction
- Amazon SES, developer guide: https://docs.aws.amazon.com/ses/latest/dg/Welcome.html
- Python, email message attachment interface: https://docs.python.org/3/library/email.message.html
- Python, SQLite transactions: https://docs.python.org/3/library/sqlite3.html
Top comments (0)