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 5 minutes by default.

Send OTP

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

const ys = new YourSend('ys_live_...');

// Send OTP via SMS
const { data } = await ys.send({
  channel: 'sms',
  to: '+14155551234',
  otp: true,
});

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

Verify OTP

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

if (result.valid) {
  console.log('OTP verified successfully!');
} else {
  console.log('Invalid or expired code');
}

Security note: Each OTP can only be verified once. After a successful verification, the code is invalidated. Codes expire after 5 minutes (300 seconds).

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