Contents

OTP2 endpoints

Send and verify one-time passwords.

Base URLhttps://sms21.in

Send an OTP

post/v1/otp/send

Scopeotp:send

Generates a one-time password and queues its delivery by SMS (default) or WhatsApp. The code is never returned and never stored in plain text.

  • A new OTP to the same number and purpose supersedes the previous one, and is subject to a resend cooldown (resendAfter) and per-number, per-IP and per-project limits.
  • channel: "whatsapp" uses the project WhatsApp authentication template; add fallbackChannel: "sms" to send by SMS when WhatsApp definitely fails.
  • Live OTPs to India need a DLT-approved SMS template with an {{otp}} variable (templateId, or the project default OTP template).
  • Test keys: nothing is sent and the code is always 123456.

Parameters1

  • Idempotency-Keyheaderstring

    Makes the request safe to retry: repeating it with the same key and body returns the original result (with Idempotent-Replayed: true) instead of sending again. Use one key per logical message, e.g. derived from your order or login-attempt ID. Reusing a key with a different body is 409 IDEMPOTENCY_KEY_REUSED.

Body8

  • mobilestringrequired

    Recipient in international format with country code: "919876543210" or "+919876543210".

  • purposestringrequired

    Why the OTP is requested; used in reports and abuse limits.

    loginregistrationpassword_resettransactionmobile_verification

  • channelstring

    Delivery channel of the first attempt.

    smswhatsapp

  • fallbackChannelstring

    channel: "whatsapp" only. If WhatsApp definitely fails (for example the number is not on WhatsApp), the code is sent by SMS. Nothing is resent while the WhatsApp outcome is uncertain.

    sms

  • templateIdstring

    SMS template with an {{otp}} variable. Defaults to the project OTP template. Live OTPs to DLT countries (India) need one of the two.

  • variablesobject

    Other template variables. otp and minutes are filled in by SMS21 and must not be sent.

  • expiresIninteger

    Validity in seconds. Default 300; values above the platform maximum (900 unless configured otherwise) are refused.

  • ipany (ipv4) | any (ipv6)

    The END USER's IP address, when known, for per-IP abuse limits. Never send your server's address.

Responses

  • 202

    Accepted: the code was generated and its delivery queued.

  • 400

    Invalid request.

    Example
    Response 400
    {
      "success": false,
      "error": {
        "code": "VALIDATION_FAILED",
        "message": "Request validation failed",
        "details": [
          {
            "field": "purpose",
            "message": "purpose must be one of the following values: login, registration, password_reset, transaction, mobile_verification"
          }
        ]
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 401

    The API key is missing, malformed, unknown, revoked or expired.

    Example
    Response 401
    {
      "success": false,
      "error": {
        "code": "AUTHENTICATION_REQUIRED",
        "message": "An API key is required; send it in the X-API-Key header or as \"Authorization: Bearer <key>\""
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 402

    Live keys only: the wallet cannot cover the message. Add funds; retrying will not help.

    Example
    Response 402
    {
      "success": false,
      "error": {
        "code": "INSUFFICIENT_BALANCE",
        "message": "Insufficient wallet balance"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 403

    The key may not do this: missing scope, IP not on the allow-list, company, project or key suspended by SMS21, project archived, wallet suspended or destination blocked.

    Example
    Response 403
    {
      "success": false,
      "error": {
        "code": "INSUFFICIENT_SCOPE",
        "message": "This API key does not have the required scope",
        "details": [
          {
            "message": "requires scope sms:send"
          }
        ]
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 404

    The template does not exist in this company.

    Example
    Response 404
    {
      "success": false,
      "error": {
        "code": "NOT_FOUND",
        "message": "Template not found",
        "details": [
          {
            "field": "templateId",
            "message": "no such template"
          }
        ]
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 409

    Conflicting state.

    Example
    Response 409
    {
      "success": false,
      "error": {
        "code": "IDEMPOTENCY_KEY_REUSED",
        "message": "This Idempotency-Key was already used with a different request"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 429

    Too many OTPs or requests. Honour Retry-After; do not loop.

    Example
    Response 429
    {
      "success": false,
      "error": {
        "code": "OTP_RESEND_COOLDOWN",
        "message": "Please wait 24 seconds before requesting another OTP"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 503

    Temporarily unavailable, or live sending paused by SMS21. Retry later with the same Idempotency-Key.

    Example
    Response 503
    {
      "success": false,
      "error": {
        "code": "SERVICE_UNAVAILABLE",
        "message": "Service temporarily unavailable"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
curl -X POST "https://sms21.in/v1/otp/send" \
  -H "X-API-Key: $SMS21_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"919876543210","purpose":"login"}'
Response 202
{
  "success": true,
  "requestId": "otp_01k55q8y4m3d9v7x2c6b0n1r8t",
  "status": "pending",
  "channel": "sms",
  "purpose": "login",
  "expiresIn": 300,
  "expiresAt": "2026-09-15T10:35:00.000Z",
  "resendAfter": 30,
  "messageId": "msg_01k55q8y4m3d9v7x2c6b0n1r8t"
}

Verify an OTP

post/v1/otp/verify

Scopeotp:verify

Checks the code a user entered. Succeeds exactly once per OTP request.

  • The request is locked after too many wrong codes (5 by default), expires after expiresIn, and is superseded by a newer OTP to the same number and purpose.
  • Pass mobile to bind verification to the number you expect; a mismatch counts as a wrong code.
  • Do not retry this call automatically after a timeout: a second call after a success returns 409 OTP_ALREADY_VERIFIED, and each wrong attempt counts. Ask the user to request a new code instead.
  • OTPs sent with a test key can only be verified with a test key.

Body3

  • requestIdstringrequired

    requestId returned by POST /otp/send.

  • otpstringrequired

    The code the user entered.

  • mobilestring

    Optional binding: verification only succeeds if the OTP was sent to this number (a mismatch counts as a wrong code).

Responses

  • 200

    Verified.

  • 400

    Wrong code, or invalid request.

    Example
    Response 400
    {
      "success": false,
      "error": {
        "code": "OTP_INVALID",
        "message": "The OTP is incorrect",
        "details": [
          {
            "field": "otp",
            "message": "4 attempts remaining"
          }
        ]
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 401

    The API key is missing, malformed, unknown, revoked or expired.

    Example
    Response 401
    {
      "success": false,
      "error": {
        "code": "AUTHENTICATION_REQUIRED",
        "message": "An API key is required; send it in the X-API-Key header or as \"Authorization: Bearer <key>\""
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 403

    The key may not do this: missing scope, IP not on the allow-list, company, project or key suspended by SMS21, project archived, wallet suspended or destination blocked.

    Example
    Response 403
    {
      "success": false,
      "error": {
        "code": "INSUFFICIENT_SCOPE",
        "message": "This API key does not have the required scope",
        "details": [
          {
            "message": "requires scope sms:send"
          }
        ]
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 404

    No such OTP request for this project and environment.

    Example
    Response 404
    {
      "success": false,
      "error": {
        "code": "NOT_FOUND",
        "message": "OTP request not found"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 409

    Already verified.

    Example
    Response 409
    {
      "success": false,
      "error": {
        "code": "OTP_ALREADY_VERIFIED",
        "message": "This OTP has already been verified"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 410

    Expired, or superseded by a newer OTP.

    Example
    Response 410
    {
      "success": false,
      "error": {
        "code": "OTP_EXPIRED",
        "message": "The OTP has expired"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 429

    Locked after too many wrong codes (final), or rate limited.

    Example
    Response 429
    {
      "success": false,
      "error": {
        "code": "OTP_ATTEMPTS_EXCEEDED",
        "message": "Too many incorrect attempts"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
  • 503

    Temporarily unavailable, or live sending paused by SMS21. Retry later with the same Idempotency-Key.

    Example
    Response 503
    {
      "success": false,
      "error": {
        "code": "SERVICE_UNAVAILABLE",
        "message": "Service temporarily unavailable"
      },
      "requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
    }
curl -X POST "https://sms21.in/v1/otp/verify" \
  -H "X-API-Key: $SMS21_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"requestId":"otp_01k55q8y4m3d9v7x2c6b0n1r8t","otp":"123456","mobile":"919876543210"}'
Response 200
{
  "success": true,
  "requestId": "otp_01k55q8y4m3d9v7x2c6b0n1r8t",
  "verified": true,
  "mobile": "919876543210",
  "purpose": "login",
  "verifiedAt": "2026-09-15T10:30:00.000Z"
}