In this tutorial, you’ll learn how to deliver a 2FA token to any mobile number and verify that token using the Telnyx v2 API. Examples are provided in curl, Node.js, Python, Ruby, Go, Java, .NET, and PHP.Documentation Index
Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Create a Telnyx account
Sign up at telnyx.com if you don’t have an account yet.
Get your API key
Follow the API Keys guide to generate an API key. Set it as an environment variable:
Methods of verification
There are currently three verification methods available:sms- the verification code is sent in a custom or default templated message.call- the code is spoken aloud in a custom or default templated message when the user answers the call.flashcall- the verification code is embedded in the caller ID of a brief “flash” call (the call rings once and hangs up). The user’s app extracts the code automatically.
Create a verify profile
A Verify Profile contains several important configurations that you’ll use when sending 2-factor authentication messages and receiving responses. Before you send any 2FA messages, you need a profile to go with them. Each profile can have one of each verification method configured. It is recommended that if you wish to configure multiple applications, you use a different profile for each one. In the below example we will set up a verification profile that can use SMS using a selected message template and speech to text calling.Select a message template
Example response
If not selected then the default template is “Your verification code is
{code}.”Want to use your own branded verification messages? You can now create custom templates that match your brand voice and compliance requirements.
Create a verify profile
Example response
Don’t forget to set your
TELNYX_API_KEY environment variable or replace YOUR_API_KEY in the curl examples.id that’s returned to you, you’ll need it to send 2FA verifications. At any time, you can access all of your created Verify Profiles by API as well.
You are now ready to send 2-factor authentication messages!
Trigger a verification request
To send a verification attempt, you need the Verify Profile ID, the phone number that will receive the message, and the verification type. Choose the method that best fits your use case:- SMS
- Call
SMS verification sends a code via text message. This is the most common method with the widest global coverage.User experience: The user receives a text message with a numeric code (e.g., “Your verification code is: 17686”). They enter this code in your application.
Example response (all methods)
Choosing the right verification method
| Feature | SMS | Call | Flashcall |
|---|---|---|---|
| Delivery speed | 1–5 seconds | 10–20 seconds (ring + answer) | 2–5 seconds |
| User interaction | Read code, type it in | Listen to code, type it in | Automatic (app reads caller ID) |
| Works on web | ✅ Yes | ✅ Yes | ❌ No (mobile only) |
| Works on landlines | ❌ No | ✅ Yes | ❌ No |
| Cost | Per-message rate | Per-minute rate | Per-call rate (very short) |
| Global coverage | Widest | Wide | Limited |
| Accessibility | Good | Best (audio) | App-dependent |
| Best for | General purpose | Landlines, accessibility | Mobile apps with auto-read |
Fallback strategy: Configure multiple methods in your verify profile. Start with SMS (fastest and widest coverage), fall back to call if SMS fails. For mobile apps, consider flashcall as a zero-friction primary method with SMS as fallback.
Verify a 2FA code
The user provides the code they received (via SMS or call). Submit it to Telnyx to verify it matches:Example response
response_code of "accepted" confirms the code matches. Other possible values:
| Response Code | Meaning |
|---|---|
accepted | Code is correct - verification successful |
rejected | Code is incorrect |
expired | Verification timed out (exceeded timeout_secs) |
max_attempts_exceeded | Too many incorrect attempts |
Telnyx Verify supports webhooks to receive instant notifications when users complete verification, eliminating the need for polling. This enables event-driven workflows for faster user experiences.Learn more: Receiving Webhooks for Telnyx Verify
Next steps
Now that you’ve completed a basic verification flow, explore these guides to build a production-ready implementation:Custom Templates
Create branded verification messages that match your app’s voice and compliance requirements.
Security Best Practices
Protect against SMS pumping, brute force attacks, and other verification fraud.
Webhooks
Receive real-time notifications when verifications complete or expire.
Integration Examples
Complete login, registration, and payment verification flow implementations.