{"id":17784,"date":"2026-11-18T23:38:08","date_gmt":"2026-11-18T18:08:08","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/"},"modified":"2026-11-19T00:43:41","modified_gmt":"2026-11-18T19:13:41","slug":"android-otp-sms-api","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/","title":{"rendered":"OTP verification in an Android app (Kotlin) with Fast2SMS: the safe way"},"content":{"rendered":"<p>To add OTP login to an Android app with Fast2SMS, your app talks to your own server, and only your server calls the Fast2SMS API. This guide shows the full setup in Kotlin: a small backend with send, verify and resend endpoints, the Android code that calls it with OkHttp and coroutines, OTP autofill, sending DLT SMS alerts, delivery reports and error handling. The same pattern works for Java Android apps.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Add OTP login to your Android app<\/strong><p>Create a Smart OTP template, keep the API key on your server and verify users by SMS or WhatsApp.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Why the API key must not be in the app<\/h2>\n<p>Anything inside an APK or AAB can be read by decompiling it, including keys in <code>BuildConfig<\/code>, <code>strings.xml<\/code> or native code. Anyone who gets your Fast2SMS key can send messages from your wallet. So the flow is:<\/p>\n<ol>\n<li>The app sends the mobile number to <strong>your server<\/strong>.<\/li>\n<li>Your server calls Fast2SMS <code>\/dev\/otp\/send<\/code> with the key and your OTP ID.<\/li>\n<li>The user types (or autofills) the code. The app sends it to your server.<\/li>\n<li>Your server calls <code>\/dev\/otp\/verify<\/code> and, if it passes, creates the user&#8217;s session or token.<\/li>\n<\/ol>\n<p>Your server also decides who may ask for an OTP, which protects you from bots that request thousands of OTPs.<\/p>\n<h2>Before you start<\/h2>\n<ul>\n<li><strong>A backend<\/strong> you control (any language). The example below uses Kotlin with Spring Boot.<\/li>\n<li><strong>API key<\/strong> from <strong>API Key<\/strong> under UTILITY, with <strong>API Access<\/strong> on.<\/li>\n<li><strong>Smart OTP template<\/strong> and its <strong>OTP ID<\/strong>. For autofill, the DLT template behind it should include your app hash (see below).<\/li>\n<li><strong>Wallet balance.<\/strong> Every OTP send and resend is charged.<\/li>\n<li><strong>Android:<\/strong> minSdk 21 or later, Kotlin coroutines and OkHttp.<\/li>\n<\/ul>\n<h2>Set up in the Fast2SMS panel<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>Copy the OTP ID<\/h3>\n<p>Open <a href=\"\/help\/smart-otp-setup-guide-fast2sms\/\">Smart OTP<\/a>, <strong>OTP Template List<\/strong>. Copy the <strong>OTP ID<\/strong> of your login template. If you have none, click <strong>Add OTP Template<\/strong>, choose SMS or WhatsApp and link your approved template.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Smart OTP Template List with WhatsApp and SMS OTP cards, each showing an OTP ID with a copy icon\"><figcaption>The OTP ID goes in your server config, not in the app.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Set the resend wait and verify attempts<\/h3>\n<p>Open <strong>OTP Settings<\/strong>. <strong>Max Verify OTP Limit<\/strong> is how many wrong codes are allowed. <strong>SMS Resend \/ Time Limit<\/strong> is the wait, in seconds, before the same number can get another OTP. Use the same wait for the countdown on your Resend button.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-settings-hd-1-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"OTP Settings page with Max Verify OTP Limit set to 5 and SMS Resend \/ Time Limit set to 30 seconds\"><figcaption>Match your app&#8217;s resend timer to this value.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy the API key to your server<\/h3>\n<p>In <strong>Account Setting<\/strong>, <strong>API Key<\/strong>, click <strong>View<\/strong>, enter the OTP sent to your account mobile and copy the key into your server&#8217;s environment, for example <code>FAST2SMS_API_KEY<\/code>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with masked Authorization Key, View and Reset buttons and API Access switched on\"><figcaption>Only your backend reads this key.<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<h2>Backend: three endpoints for the app<\/h2>\n<p>Here is a small Spring Boot controller in Kotlin. It calls Fast2SMS and returns simple JSON to the app. If your backend is in PHP, Python, Node.js or C#, see the language guides linked at the end; the calls are the same.<\/p>\n<pre><code class=\"language-kotlin\">import com.fasterxml.jackson.databind.ObjectMapper\nimport org.springframework.http.ResponseEntity\nimport org.springframework.web.bind.annotation.*\nimport java.net.URI\nimport java.net.http.HttpClient\nimport java.net.http.HttpRequest\nimport java.net.http.HttpResponse\nimport java.time.Duration\n\ndata class SendReq(val mobile: String)\ndata class VerifyReq(val mobile: String, val otp: String)\n\n@RestController\n@RequestMapping(\"\/api\/otp\")\nclass OtpController {\n    private val http = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build()\n    private val json = ObjectMapper()\n    private val apiKey = System.getenv(\"FAST2SMS_API_KEY\")\n    private val otpId = System.getenv(\"FAST2SMS_OTP_ID\")\n\n    private fun fast2sms(path: String, body: Map&lt;String, Any&gt;): Pair&lt;Boolean, String&gt; {\n        val req = HttpRequest.newBuilder(URI.create(\"https:\/\/www.fast2sms.com$path\"))\n            .timeout(Duration.ofSeconds(15))\n            .header(\"authorization\", apiKey)              \/\/ bare key, no \"Bearer \"\n            .header(\"Content-Type\", \"application\/json\")\n            .POST(HttpRequest.BodyPublishers.ofString(json.writeValueAsString(body)))\n            .build()\n        val res = http.send(req, HttpResponse.BodyHandlers.ofString())\n        val node = json.readTree(res.body())\n        val ok = res.statusCode() in 200..299 &amp;&amp; node.path(\"return\").asBoolean(false)\n        return ok to node.path(\"message\").asText(\"\")\n    }\n\n    private fun clean(m: String) = m.filter { it.isDigit() }.takeLast(10)\n\n    @PostMapping(\"\/send\")\n    fun send(@RequestBody r: SendReq): ResponseEntity&lt;Map&lt;String, Any&gt;&gt; {\n        val mobile = clean(r.mobile)\n        if (&#33;Regex(\"^[6-9]\\\\d{9}$\").matches(mobile)) return ResponseEntity.badRequest().body(mapOf(\"error\" to \"Enter a valid mobile number\"))\n        \/\/ Add your own limits here: per IP, per device and per mobile per hour\n        val (ok, msg) = fast2sms(\"\/dev\/otp\/send\", mapOf(\"mobile\" to mobile, \"otp_id\" to otpId, \"otp_expiry\" to 5))\n        return if (ok) ResponseEntity.ok(mapOf(\"sent\" to true)) else ResponseEntity.status(400).body(mapOf(\"error\" to msg))\n    }\n\n    @PostMapping(\"\/verify\")\n    fun verify(@RequestBody r: VerifyReq): ResponseEntity&lt;Map&lt;String, Any&gt;&gt; {\n        val (ok, msg) = fast2sms(\"\/dev\/otp\/verify\", mapOf(\"mobile\" to clean(r.mobile), \"otp\" to r.otp.trim()))\n        if (&#33;ok) return ResponseEntity.status(400).body(mapOf(\"error\" to msg))\n        val token = \"...\" \/\/ create your session or JWT for this mobile here\n        return ResponseEntity.ok(mapOf(\"verified\" to true, \"token\" to token))\n    }\n\n    @PostMapping(\"\/resend\")\n    fun resend(@RequestBody r: SendReq): ResponseEntity&lt;Map&lt;String, Any&gt;&gt; {\n        val (ok, msg) = fast2sms(\"\/dev\/otp\/resend\", mapOf(\"mobile\" to clean(r.mobile)))\n        return if (ok) ResponseEntity.ok(mapOf(\"sent\" to true)) else ResponseEntity.status(400).body(mapOf(\"error\" to msg))\n    }\n}<\/code><\/pre>\n<p>Facts your backend should know:<\/p>\n<ul>\n<li>Verify needs only the mobile and the code. It checks the latest unverified OTP for that number, and a new send cancels older ones.<\/li>\n<li>Resend sends the same code again and is charged. It works within 10 minutes of the first send and up to 5 sends in total, counting the first.<\/li>\n<li>A send inside the wait time returns &#8220;Please wait N seconds before requesting a new OTP&#8221;. Pass the message to the app.<\/li>\n<li>The default expiry is 15 minutes; the example sets 5 with <code>otp_expiry<\/code>.<\/li>\n<\/ul>\n<h2>Android: call your backend from Kotlin<\/h2>\n<p>Add OkHttp and coroutines to <code>app\/build.gradle.kts<\/code>:<\/p>\n<pre><code class=\"language-kotlin\">dependencies {\n    implementation(\"com.squareup.okhttp3:okhttp:4.12.0\")\n    implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1\")\n    implementation(\"androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4\")\n}<\/code><\/pre>\n<p>And the internet permission in <code>AndroidManifest.xml<\/code>: <code>&lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;<\/code>. The app only knows your server&#8217;s URL, never the Fast2SMS key.<\/p>\n<pre><code class=\"language-kotlin\">import kotlinx.coroutines.Dispatchers\nimport kotlinx.coroutines.withContext\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.RequestBody.Companion.toRequestBody\nimport org.json.JSONObject\nimport java.util.concurrent.TimeUnit\n\nclass OtpApi(private val baseUrl: String = \"https:\/\/api.yourapp.com\") {\n    private val client = OkHttpClient.Builder()\n        .connectTimeout(5, TimeUnit.SECONDS)\n        .readTimeout(20, TimeUnit.SECONDS)\n        .build()\n\n    sealed class Result {\n        data class Ok(val body: JSONObject) : Result()\n        data class Error(val message: String) : Result()\n    }\n\n    private suspend fun post(path: String, body: JSONObject): Result = withContext(Dispatchers.IO) {\n        try {\n            val req = Request.Builder()\n                .url(baseUrl + path)\n                .post(body.toString().toRequestBody(\"application\/json\".toMediaType()))\n                .build()\n            client.newCall(req).execute().use { res -&gt;\n                val json = JSONObject(res.body?.string().orEmpty().ifBlank { \"{}\" })\n                if (res.isSuccessful) Result.Ok(json)\n                else Result.Error(json.optString(\"error\", \"Something went wrong. Try again.\"))\n            }\n        } catch (e: java.io.IOException) {\n            Result.Error(\"No internet connection. Try again.\")\n        }\n    }\n\n    suspend fun sendOtp(mobile: String) = post(\"\/api\/otp\/send\", JSONObject().put(\"mobile\", mobile))\n    suspend fun resendOtp(mobile: String) = post(\"\/api\/otp\/resend\", JSONObject().put(\"mobile\", mobile))\n    suspend fun verifyOtp(mobile: String, otp: String) =\n        post(\"\/api\/otp\/verify\", JSONObject().put(\"mobile\", mobile).put(\"otp\", otp))\n}<\/code><\/pre>\n<h2>OTP autofill on Android<\/h2>\n<p>Two Google APIs can read the OTP for the user:<\/p>\n<ul>\n<li><strong>SMS Retriever API:<\/strong> no permission prompt. The SMS must contain your app&#8217;s 11-character hash. In India the SMS text must match your DLT template, so the hash has to be part of the approved template as fixed text.<\/li>\n<li><strong>SMS User Consent API:<\/strong> no hash needed. Android shows the SMS and the user taps Allow. Fast2SMS messages come from a sender ID header, so start it without a sender filter.<\/li>\n<\/ul>\n<p>Start the listener just before you call your send endpoint, then pass the code you read to the verify endpoint. Never mark the user as verified inside the app. The full setup is in the OTP autofill guide linked below.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Faster OTP for your app users<\/strong><p>Use Smart OTP with an autofill-ready template and an automatic WhatsApp fallback when SMS fails.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Full copy-paste example: a login ViewModel<\/h2>\n<pre><code class=\"language-kotlin\">import androidx.lifecycle.ViewModel\nimport androidx.lifecycle.viewModelScope\nimport kotlinx.coroutines.delay\nimport kotlinx.coroutines.flow.MutableStateFlow\nimport kotlinx.coroutines.flow.StateFlow\nimport kotlinx.coroutines.launch\n\ndata class OtpUiState(\n    val mobile: String = \"\",\n    val codeSent: Boolean = false,\n    val loading: Boolean = false,\n    val resendIn: Int = 0,          \/\/ seconds left before Resend is enabled\n    val error: String? = null,\n    val token: String? = null,      \/\/ set when verified\n)\n\nclass LoginViewModel(\n    private val api: OtpApi = OtpApi(),\n    private val resendWaitSeconds: Int = 30,   \/\/ same as SMS Resend \/ Time Limit in OTP Settings\n) : ViewModel() {\n\n    private val _state = MutableStateFlow(OtpUiState())\n    val state: StateFlow&lt;OtpUiState&gt; = _state\n\n    fun sendOtp(mobile: String) = viewModelScope.launch {\n        val digits = mobile.filter { it.isDigit() }.takeLast(10)\n        if (&#33;Regex(\"^[6-9]\\\\d{9}$\").matches(digits)) {\n            _state.value = _state.value.copy(error = \"Enter a valid 10-digit mobile number\")\n            return@launch\n        }\n        _state.value = _state.value.copy(mobile = digits, loading = true, error = null)\n        when (val r = api.sendOtp(digits)) {\n            is OtpApi.Result.Ok -&gt; { _state.value = _state.value.copy(loading = false, codeSent = true); startTimer() }\n            is OtpApi.Result.Error -&gt; _state.value = _state.value.copy(loading = false, error = r.message)\n        }\n    }\n\n    fun resendOtp() = viewModelScope.launch {\n        if (_state.value.resendIn &gt; 0) return@launch\n        _state.value = _state.value.copy(loading = true, error = null)\n        when (val r = api.resendOtp(_state.value.mobile)) {\n            is OtpApi.Result.Ok -&gt; { _state.value = _state.value.copy(loading = false); startTimer() }\n            is OtpApi.Result.Error -&gt; _state.value = _state.value.copy(loading = false, error = r.message)\n        }\n    }\n\n    fun verifyOtp(code: String) = viewModelScope.launch {\n        if (code.length &lt; 4) return@launch\n        _state.value = _state.value.copy(loading = true, error = null)\n        when (val r = api.verifyOtp(_state.value.mobile, code.trim())) {\n            is OtpApi.Result.Ok -&gt; _state.value = _state.value.copy(loading = false, token = r.body.optString(\"token\"))\n            is OtpApi.Result.Error -&gt; _state.value = _state.value.copy(loading = false, error = r.message)\n        }\n    }\n\n    private fun startTimer() = viewModelScope.launch {\n        for (s in resendWaitSeconds downTo 0) {\n            _state.value = _state.value.copy(resendIn = s)\n            delay(1000)\n        }\n    }\n}<\/code><\/pre>\n<p>Bind <code>state<\/code> to your Compose screen or Activity: show the mobile field, then the code field after <code>codeSent<\/code>, disable Resend while <code>resendIn &gt; 0<\/code>, and store <code>token<\/code> securely (for example with EncryptedSharedPreferences or DataStore) once verified.<\/p>\n<h2>Sending DLT SMS alerts from an Android app<\/h2>\n<p>For order updates, booking alerts or payment receipts, the rule is the same: the app tells your server what happened, and your server calls <code>\/dev\/bulkV2<\/code> with <code>route=dlt<\/code>, your sender ID, the template&#8217;s <strong>Message ID<\/strong> and the variable values. Usually it is better to send these from the server when the order or booking changes, not from the app at all.<\/p>\n<pre><code class=\"language-bash\">curl -X POST \"https:\/\/www.fast2sms.com\/dev\/bulkV2\" \\\n  -H \"authorization: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\"route\":\"dlt\",\"sender_id\":\"DEMOTR\",\"message\":\"10001\",\"variables_values\":\"Rahul|DT10458|1240|21 Nov\",\"numbers\":\"9999999999\"}'<\/code><\/pre>\n<h2>Delivery reports<\/h2>\n<p>The app does not need to talk to Fast2SMS for delivery status either. Set up an OTP or SMS <a href=\"\/help\/fast2sms-webhooks-setup-delivery-reports\/\">webhook<\/a> under <strong>Webhook<\/strong> in the panel so Fast2SMS posts <code>delivered<\/code> or <code>failed<\/code> to your server, or call <code>GET \/dev\/dlr\/{request_id}<\/code> from the server for SMS. If the app needs to show &#8220;SMS not delivered, try WhatsApp&#8221;, have it ask your server. Smart OTP can also re-send a failed SMS OTP on WhatsApp automatically when the template has a fallback.<\/p>\n<h2>Error handling<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Message from Fast2SMS<\/th>\n<th>What the app should show<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Please wait N seconds before requesting a new OTP<\/td>\n<td>The countdown. Keep Resend disabled.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP<\/td>\n<td>&#8220;Wrong code, please check and try again.&#8221;<\/td>\n<\/tr>\n<tr>\n<td>OTP expired<\/td>\n<td>&#8220;Code expired. Tap Resend to get a new one.&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Maximum verification attempts reached. OTP is no longer valid.<\/td>\n<td>&#8220;Too many wrong tries. Request a new code.&#8221;<\/td>\n<\/tr>\n<tr>\n<td>OTP not found or already verified<\/td>\n<td>&#8220;Please request a new code.&#8221;<\/td>\n<\/tr>\n<tr>\n<td>OTP resend window (10 minutes) has expired \/ Maximum resend limit (5 times) reached<\/td>\n<td>Restart the flow with a fresh send, or ask the user to try later.<\/td>\n<\/tr>\n<tr>\n<td>Invalid authorization key, Invalid OTP ID, 413, 414, insufficient balance<\/td>\n<td>A general &#8220;Something went wrong&#8221; to the user. These are setup problems for you to fix on the server.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>On the server, do not retry a send after a timeout: it can send and charge twice. Verify can be retried once.<\/p>\n<h2>Common problems and fixes<\/h2>\n<ul>\n<li><strong>NetworkOnMainThreadException:<\/strong> run network calls in <code>Dispatchers.IO<\/code>, as in <code>OtpApi<\/code>.<\/li>\n<li><strong>CLEARTEXT communication not permitted:<\/strong> use HTTPS for your backend URL.<\/li>\n<li><strong>Autofill does not work:<\/strong> the hash in the SMS does not match the app signing key, or the SMS text is not exactly your DLT template.<\/li>\n<li><strong>Users get many OTPs:<\/strong> the app calls send again on screen rotation. Keep state in the ViewModel and send only on button tap.<\/li>\n<li><strong>Bots draining the wallet:<\/strong> add per-IP and per-mobile limits on your send endpoint, and consider Play Integrity or a captcha on the send screen.<\/li>\n<\/ul>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Can I call the Fast2SMS API directly from Android?<\/h3>\n<p>Technically yes, but you should not. The key can be pulled out of the app and used to send messages from your wallet. Always go through your server.<\/p>\n<h3>Is there a Fast2SMS Android SDK?<\/h3>\n<p>No SDK is needed. The app calls your backend, and your backend calls the Fast2SMS HTTP API.<\/p>\n<h3>Can I send the OTP on WhatsApp instead of SMS?<\/h3>\n<p>Yes. Create a WhatsApp Smart OTP template and use its OTP ID on the server. Your Android code does not change.<\/p>\n<h3>How long should the OTP be valid?<\/h3>\n<p>Set <code>otp_expiry<\/code> in minutes on your server, from 1 to 10080. For app login, 5 to 10 minutes is common.<\/p>\n<h3>Does resend send a new code?<\/h3>\n<p>No. Resend sends the same code again. To get a new code, call send again, which cancels the old one.<\/p>\n<h3>Is verify charged?<\/h3>\n<p>No. Only sends and resends are charged.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Ship OTP login in your Android app<\/strong><p>Sign up, create your Smart OTP template and connect it through your backend in an afternoon.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"\/help\/otp-autofill-android-ios-sms-retriever\/\">OTP autofill on Android, iPhone and websites<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-send-otp-api\/\">Fast2SMS Send OTP API: parameters and code examples<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-settings-cooldown-attempts\/\">Smart OTP settings: resend wait time and verify attempts<\/a><\/li>\n<li><a href=\"\/help\/java-sms-api\/\">Send SMS and OTP in Java with Fast2SMS API<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-best-practices\/\">OTP security best practices with Fast2SMS<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/otp-sms\">Fast2SMS OTP SMS<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To add OTP login to an Android app with Fast2SMS, your app talks to your own server, and only your server calls the Fast2SMS API. This guide shows the full setup in Kotlin: a small backend with send, verify and resend endpoints, the Android code that calls it with OkHttp and coroutines, OTP autofill, sending [&hellip;]<\/p>\n","protected":false},"featured_media":17778,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-17784","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android OTP Verification in Kotlin | Fast2SMS<\/title>\n<meta name=\"description\" content=\"Add OTP login to an Android app in Kotlin with Fast2SMS Smart OTP. Keep the API key on your server, call it with OkHttp, autofill the code, handle errors.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android OTP Verification in Kotlin | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"Add OTP login to an Android app in Kotlin with Fast2SMS Smart OTP. Keep the API key on your server, call it with OkHttp, autofill the code, handle errors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Fast2SMS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Fast2SMS\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T18:08:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T19:13:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fast2sms\" \/>\n<meta name=\"twitter:site\" content=\"@fast2sms\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"OTP verification in an Android app (Kotlin) with Fast2SMS: the safe way\",\"datePublished\":\"2026-11-18T18:08:08+00:00\",\"dateModified\":\"2026-11-18T19:13:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/\"},\"wordCount\":1416,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-1-scaled.webp\",\"articleSection\":[\"API\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/\",\"name\":\"Android OTP Verification in Kotlin | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-1-scaled.webp\",\"datePublished\":\"2026-11-18T18:08:08+00:00\",\"dateModified\":\"2026-11-18T19:13:41+00:00\",\"description\":\"Add OTP login to an Android app in Kotlin with Fast2SMS Smart OTP. Keep the API key on your server, call it with OkHttp, autofill the code, handle errors.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-1-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-1-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"Smart OTP Template List with WhatsApp and SMS OTP cards, each showing an OTP ID with a copy icon\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/android-otp-sms-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/api\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"OTP verification in an Android app (Kotlin) with Fast2SMS: the safe way\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\",\"name\":\"Fast2SMS\",\"description\":\"Help\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"inLanguage\":\"en-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\",\"name\":\"Fast2SMS\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"caption\":\"Fast2SMS\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\"},\"email\":\"support@fast2sms.com\",\"telephone\":\"+91-6262778822\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Fast2SMS\",\"https:\\\/\\\/www.instagram.com\\\/fast2sms\",\"https:\\\/\\\/x.com\\\/fast2sms\",\"https:\\\/\\\/www.youtube.com\\\/Fast2SMSofficial\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/fast2sms\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android OTP Verification in Kotlin | Fast2SMS","description":"Add OTP login to an Android app in Kotlin with Fast2SMS Smart OTP. Keep the API key on your server, call it with OkHttp, autofill the code, handle errors.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/","og_locale":"en_US","og_type":"article","og_title":"Android OTP Verification in Kotlin | Fast2SMS","og_description":"Add OTP login to an Android app in Kotlin with Fast2SMS Smart OTP. Keep the API key on your server, call it with OkHttp, autofill the code, handle errors.","og_url":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T18:08:08+00:00","article_modified_time":"2026-11-18T19:13:41+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_creator":"@fast2sms","twitter_site":"@fast2sms","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"OTP verification in an Android app (Kotlin) with Fast2SMS: the safe way","datePublished":"2026-11-18T18:08:08+00:00","dateModified":"2026-11-18T19:13:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/"},"wordCount":1416,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp","articleSection":["API","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/","url":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/","name":"Android OTP Verification in Kotlin | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp","datePublished":"2026-11-18T18:08:08+00:00","dateModified":"2026-11-18T19:13:41+00:00","description":"Add OTP login to an Android app in Kotlin with Fast2SMS Smart OTP. Keep the API key on your server, call it with OkHttp, autofill the code, handle errors.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-1-scaled.webp","width":2560,"height":1600,"caption":"Smart OTP Template List with WhatsApp and SMS OTP cards, each showing an OTP ID with a copy icon"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/android-otp-sms-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fast2sms.com\/help\/"},{"@type":"ListItem","position":2,"name":"API","item":"https:\/\/www.fast2sms.com\/help\/api\/"},{"@type":"ListItem","position":3,"name":"OTP verification in an Android app (Kotlin) with Fast2SMS: the safe way"}]},{"@type":"WebSite","@id":"https:\/\/www.fast2sms.com\/help\/#website","url":"https:\/\/www.fast2sms.com\/help\/","name":"Fast2SMS","description":"Help","publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"inLanguage":"en-IN"},{"@type":"Organization","@id":"https:\/\/www.fast2sms.com\/#organization","name":"Fast2SMS","url":"https:\/\/www.fast2sms.com\/","logo":{"@type":"ImageObject","@id":"https:\/\/www.fast2sms.com\/#logo","url":"https:\/\/www.fast2sms.com\/Fast2SMS.png","contentUrl":"https:\/\/www.fast2sms.com\/Fast2SMS.png","caption":"Fast2SMS"},"image":{"@id":"https:\/\/www.fast2sms.com\/#logo"},"email":"support@fast2sms.com","telephone":"+91-6262778822","sameAs":["https:\/\/www.facebook.com\/Fast2SMS","https:\/\/www.instagram.com\/fast2sms","https:\/\/x.com\/fast2sms","https:\/\/www.youtube.com\/Fast2SMSofficial","https:\/\/www.linkedin.com\/company\/fast2sms"]}]}},"_links":{"self":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/17784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/comments?post=17784"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/17784\/revisions"}],"predecessor-version":[{"id":19221,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/17784\/revisions\/19221"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/17778"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=17784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=17784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=17784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}