How to send a 4-digit or 6-digit OTP with Fast2SMS (OTP length)

To change the OTP length in Fast2SMS, send the otp_length parameter with the Send OTP API: 4 gives a 4-digit OTP, 6 gives a 6-digit OTP, and you can go up to 10 digits. If you leave it out, Smart OTP creates a 6-digit code. This page explains the rules and how to send your own code instead.

OTP length rules

What you send What happens
No otp_length 6-digit OTP
otp_length 4 to 10 OTP with that many digits
otp_length below 4 (for example 3) Quietly changed to 6 digits
otp_length above 10 Validation error, no OTP is sent
Your own otp value That exact value is sent (up to 10 characters) and otp_length is not needed

How to send a 4-digit OTP

  1. Copy your OTP ID

    Open Smart OTP and go to OTP Template List. Every card shows an OTP ID with a copy button. You need it in the API call.

    Smart OTP Template list with WhatsApp and SMS OTP template cards, each showing its OTP ID with a copy icon
    The OTP ID is on every template card.
  2. Add otp_length to the Send OTP call

    Set otp_length to 4. Fast2SMS creates a random 4-digit code and puts it in the OTP variable of your template.

    curl -X POST "https://www.fast2sms.com/dev/otp/send" \
      -H "authorization: YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"mobile":"9999999999","otp_id":"YOUR_OTP_ID","otp_length":4}'

    A good reply looks like {"return":true,"status_code":200,"request_id":"O...","message":"OTP sent successfully"}.

  3. Verify the code the user types

    Call /dev/otp/verify with mobile and otp. The length does not change how verify works.

Sending your own OTP value

If your app already creates the code, pass it in the otp field, for example "otp":"4821". Fast2SMS sends that value and the Verify API still checks it. The value can be at most 10 characters. Send it as a string.

If you do not need your own code, let Smart OTP create it. Then the code never has to be stored in your own database.

4 digits are quick to type, but 6 digits are much harder to guess. For login, payment and password reset, 6 digits is the safer choice. Keep the verify attempt limit low in OTP Settings either way.

Frequently asked questions

What is the default OTP length in Fast2SMS?

6 digits, when you do not send otp_length.

Can I send an 8-digit OTP?

Yes. Any length from 4 to 10 works with otp_length.

Why did I get a 6-digit OTP when I asked for 3?

Values below 4 are changed to 6. The shortest OTP Smart OTP creates is 4 digits.

Can the OTP contain letters?

Codes that Smart OTP creates are numbers only. If you pass your own value in otp, it is sent as you give it, so keep it to digits if your DLT template expects a number.

Does a longer OTP cost more?

The charge depends on the SMS parts of the full message. A few extra digits rarely change the part count, but a very long template can.