OTP Verification

Send and verify one-time passwords on any channel — SMS, voice, email, or WhatsApp.

Overview

YourSend's OTP system generates a 6-digit code, delivers it via your chosen channel, and verifies it when the user submits it. Codes expire after 10 minutes by default and allow up to 5 verification attempts.

Send OTP

send-otp.ts
import { YourSend } from 'yoursend';

const ys = new YourSend({ apiKey: 'ys_live_...' });

// Send OTP via SMS — no body/template_id means YourSend generates the code
const otp = await ys.send({
  channel: 'sms',
  to: '+14155551234',
});

// Store the message_id to verify later
const messageId = otp.message_id;

Verify OTP

verify-otp.ts
// When user submits their code:
const result = await ys.check({
  message_id: messageId,
  code: '123456', // user-provided code
});

if (result.verified) {
  console.log('OTP verified successfully!');
} else {
  console.log('Invalid code —', result.remaining_attempts, 'attempts left');
}

Security note: Each OTP can only be verified once. After a successful verification, the code is invalidated. Codes expire after 10 minutes by default and allow a maximum of 5 attempts — after that, request a new code.

Supported Channels

ChannelDeliveryBest for
smsText messageMost common, fastest delivery
voicePhone call (TTS)Accessibility, no SMS reception
emailEmailLow-friction verification
whatsappWhatsApp messageInternational users
autoAI picks bestMaximum delivery rate