One-time passcodes by SMS
SMS OTP and 2FA codes for Australian apps
Send sign-in and verification codes from your app with one API call. 3¢ per SMS, no monthly fee, official SDKs for Node, Python, PHP and .NET.
Start free with 5 credits5 free credits. No credit card. No contract.
Texto delivers SMS one-time passcodes (OTP) and two-factor authentication (2FA) codes for Australian apps at 3¢ per message. Your app generates and checks the code, and Texto sends it through a single REST API call, with data kept on-shore in Australia and messages sent via licensed Australian carriers.
How sending an OTP works
1
Your app creates the code
When a user signs in or verifies a phone number, your app generates a short random code and stores it with an expiry time.
2
Texto delivers it by SMS
Your app sends one POST request to the Texto /send endpoint with the user's number and a message containing the code.
3
Your app checks the code
The user types the code into your app, and your app compares it with the stored value before it expires.
Send a code in your language
Put your code in the message, for example "Your Acme code is 482913. It expires in 10 minutes. Don't share it." Full details are in the SMS API reference and on the developers page.
Send an SMS with Node.js
No package required — Node 18+ ships with fetch
# Node 18 and above has fetch built in. # On older versions, add a fetch polyfill: npm install node-fetch
Send a message
// texto.js
const TEXTO_API_KEY = process.env.TEXTO_API_KEY;
export async function sendSms({ to, message, from, campaign }) {
const response = await fetch("https://api.texto.com.au/send", {
method: "POST",
headers: {
Authorization: `Bearer ${TEXTO_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ to, message, from, campaign }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(`Texto ${response.status}: ${data.error ?? "request failed"}`);
}
return data;
}
const result = await sendSms({
to: "+61412345678",
message: "Your order has shipped.",
campaign: "order-updates",
});
console.log(result.message_id, result.credits_remaining);Handle errors
try {
await sendSms({ to: "+61412345678", message: "Hello" });
} catch (err) {
// 401 invalid key · 402 out of credits · 422 invalid number · 429 rate limited
console.error(err.message);
}Send an SMS with PHP
Recommended: Guzzle via Composer
composer require guzzlehttp/guzzle
Send a message
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$client = new Client(['base_uri' => 'https://api.texto.com.au/']);
function sendSms(Client $client, string $to, string $message, ?string $campaign = null): array
{
$response = $client->post('send', [
'headers' => [
'Authorization' => 'Bearer ' . getenv('TEXTO_API_KEY'),
'Content-Type' => 'application/json',
],
'json' => array_filter([
'to' => $to,
'message' => $message,
'campaign' => $campaign,
]),
]);
return json_decode((string) $response->getBody(), true);
}
$result = sendSms($client, '+61412345678', 'Your order has shipped.', 'order-updates');
echo $result['message_id'], ' ', $result['credits_remaining'];Handle errors
try {
$result = sendSms($client, '+61412345678', 'Hello');
} catch (RequestException $e) {
// 401 invalid key · 402 out of credits · 422 invalid number · 429 rate limited
$status = $e->getResponse()?->getStatusCode();
$body = (string) $e->getResponse()?->getBody();
error_log("Texto {$status}: {$body}");
}Send an SMS with Python
Recommended: requests
pip install requests
Send a message
# texto.py
import os
import requests
BASE_URL = "https://api.texto.com.au"
API_KEY = os.environ["TEXTO_API_KEY"]
def send_sms(to: str, message: str, campaign: str | None = None) -> dict:
response = requests.post(
f"{BASE_URL}/send",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json={k: v for k, v in {
"to": to,
"message": message,
"campaign": campaign,
}.items() if v is not None},
timeout=15,
)
response.raise_for_status()
return response.json()
result = send_sms("+61412345678", "Your order has shipped.", "order-updates")
print(result["message_id"], result["credits_remaining"])Handle errors
from requests import HTTPError
try:
send_sms("+61412345678", "Hello")
except HTTPError as err:
# 401 invalid key · 402 out of credits · 422 invalid number · 429 rate limited
print(err.response.status_code, err.response.text)Send an SMS with .NET
No package required — HttpClient is built in
# System.Net.Http and System.Text.Json ship with .NET.
# Register a typed client in Program.cs:
builder.Services.AddHttpClient("texto", c =>
c.BaseAddress = new Uri("https://api.texto.com.au/"));Send a message
using System.Net.Http.Json;
using System.Net.Http.Headers;
public record SendSmsRequest(string To, string Message, string? Campaign = null);
public record SendSmsResponse(string message_id, int credits_used, int credits_remaining);
public class TextoClient(HttpClient http, string apiKey)
{
public async Task<SendSmsResponse> SendSmsAsync(SendSmsRequest request)
{
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", apiKey);
var response = await http.PostAsJsonAsync("send", new
{
to = request.To,
message = request.Message,
campaign = request.Campaign,
});
response.EnsureSuccessStatusCode();
return (await response.Content.ReadFromJsonAsync<SendSmsResponse>())!;
}
}
var result = await client.SendSmsAsync(
new SendSmsRequest("+61412345678", "Your order has shipped.", "order-updates"));
Console.WriteLine($"{result.message_id} {result.credits_remaining}");Handle errors
try
{
await client.SendSmsAsync(new SendSmsRequest("+61412345678", "Hello"));
}
catch (HttpRequestException ex)
{
// 401 invalid key · 402 out of credits · 422 invalid number · 429 rate limited
Console.Error.WriteLine($"Texto {(int?)ex.StatusCode}: {ex.Message}");
}Sender and throughput
Show your app name with an approved Sender ID, or send from a dedicated number.
Each API key gets 50 requests per second and 25 concurrent connections by default. Higher limits are available for high-volume senders and those with higher throughput needs.
OTP security tips
- Expire codes after 5 to 10 minutes and allow them to be used once.
- Limit how many codes a number can request, and how many wrong guesses it gets.
- Keep the message short: the code, your app name and a warning not to share it.
- Never put the code in a link, and never log it in plain text.
What SMS 2FA costs
Each OTP of up to 160 characters is 1 credit, or 3¢ to an Australian mobile. 10,000 codes a month is about $300. No setup fee, no monthly fee. See SMS pricing.
Looking to receive shared login codes for your team instead? See Team SMS 2FA.
SMS OTP and 2FA FAQs
Send your first OTP in minutes
3¢ per SMS, no monthly fee, and 5 free credits to test with.
Start free with 5 credits