Prerequisites
- A Telnyx account (free to create)
1. Get two phone numbers
Purchase two Telnyx numbers so you can test messaging between them without registration requirements.Go to Numbers
Navigate to Numbers > Search & Buy in the portal.
Search for numbers
Enter your preferred area code or region, check SMS under features, and click Search.
Having two numbers lets you test on-net (Telnyx-to-Telnyx) messaging immediately, and also test receiving inbound messages.
2. Create a Messaging Profile
Go to Messaging
Navigate to Messaging in the portal.
Assign both numbers
Go to My Numbers, and for each number, click the Messaging Profile dropdown, select your profile, and save.
3. Get your API key
Go to API Keys and copy your API key (or create one if needed).4. Send a message
- SMS
- MMS
YOUR_API_KEY: Your API key from step 3from: Your first Telnyx number (the sender)to: Your second Telnyx number (the recipient)
E.164 format is required. Always include the
+ prefix, country code, and full number with no spaces or punctuation.International number format examples
International number format examples
| Country | Format | Example |
|---|---|---|
| US/Canada | +1 + 10 digits | +15551234567 |
| UK | +44 + 10-11 digits (drop leading 0) | +447911123456 |
| Germany | +49 + 10-11 digits (drop leading 0) | +4915123456789 |
| Australia | +61 + 9 digits (drop leading 0) | +61412345678 |
| Brazil | +55 + 10-11 digits | +5511987654321 |
| India | +91 + 10 digits | +919876543210 |
- ❌
15551234567(missing+) - ❌
+1 (555) 123-4567(contains spaces and punctuation) - ❌
+1-555-123-4567(contains dashes) - ✅
+15551234567
Sending to non-Telnyx numbers? Off-net messaging to external carriers typically requires sender registration (10DLC, toll-free verification, etc.). See Next steps for registration guides.
Response
A successful response looks like this:status: "queued" means your message is on its way. Save the id to track delivery status.
Error handling
API errors return structured JSON responses with an error code, title, and detail message. Handle these in your application to provide clear feedback and enable automatic recovery.Error response format
SDK error handling examples
HTTP error codes
| HTTP Status | Meaning | Retryable | Action |
|---|---|---|---|
400 | Bad Request | No | Fix the request body — malformed JSON or missing required fields |
401 | Unauthorized | No | Check your API key is correct and active |
402 | Payment Required | No | Add funds to your account balance |
403 | Forbidden | No | Number not assigned to a messaging profile, or sender registration required |
404 | Not Found | No | The resource (message ID, profile ID) does not exist |
422 | Unprocessable Entity | No | Validation failed — see error detail for the specific field |
429 | Too Many Requests | Yes | Rate limited — wait for the retry-after header value, then retry |
500 | Internal Server Error | Yes | Telnyx server error — retry with exponential backoff |
503 | Service Unavailable | Yes | Temporary outage — retry with exponential backoff |
Messaging-specific error codes
These codes appear in theerrors[].code field and provide more specific detail than HTTP status codes alone:
| Code | Description | Resolution |
|---|---|---|
40001 | Phone number not in E.164 format | Format as +[country code][number] with no spaces or punctuation |
40002 | Missing required field | Include all required fields: from, to, and text (or media_urls) |
40300 | Number not assigned to messaging profile | Go to My Numbers and assign a messaging profile |
40301 | Sender registration required | Register for 10DLC, toll-free verification, or another sender type |
40302 | Messaging profile disabled | Re-enable the profile in the portal |
42200 | Invalid from number | Verify the number belongs to your account and supports messaging |
42201 | Invalid to number | Verify the destination is a valid, active phone number |
42202 | Message body too long | SMS max: 1,600 characters (concatenated). Reduce content or split into multiple messages |
42203 | Invalid media URL | Ensure media_urls are publicly accessible HTTPS URLs |
42204 | Too many media attachments | MMS supports up to 10 media URLs per message |
42205 | Media file too large | Individual media files must be under 1 MB; total under 2 MB |
For a complete error code reference including delivery failure codes, see the Messaging Error Codes guide.
Rate limiting
The Telnyx Messaging API enforces rate limits to ensure platform stability. When you exceed the limit, the API returns429 Too Many Requests with a retry-after header.
Rate limit headers:
| Header | Description |
|---|---|
x-ratelimit-limit | Maximum requests allowed in the current window |
x-ratelimit-remaining | Requests remaining in the current window |
x-ratelimit-reset | Unix timestamp when the window resets |
retry-after | Seconds to wait before retrying (only on 429 responses) |
- Implement exponential backoff: wait
2^attemptseconds between retries (1s, 2s, 4s, 8s…) - Add jitter to prevent thundering herd:
wait = base_wait * (0.5 + random()) - Set a maximum retry count (3–5 attempts) to avoid infinite loops
- Use a message queue (Redis, RabbitMQ, SQS) to buffer outbound messages and control throughput
- Monitor
x-ratelimit-remainingand slow down before hitting the limit
Troubleshooting checklist
If your message fails to send, work through this checklist:Verify API key
Confirm your API key is active at API Keys. Revoked or expired keys return
401.Check number assignment
Verify your
from number is assigned to a messaging profile at My Numbers. Unassigned numbers return 403.Confirm E.164 format
Both
from and to must be in E.164 format: +15551234567. No spaces, dashes, or parentheses.Check sender registration
Sending to US carriers off-net requires registration. Check your registration status:
- 10DLC: 10DLC Registration
- Toll-free: Toll-Free Verification
- Short code: Short Codes
Verify account balance
Insufficient balance returns
402. Check and top up at Billing.Check message content
- SMS body must not exceed 1,600 characters
- MMS media URLs must be publicly accessible HTTPS URLs
- Content must comply with carrier guidelines (no SHAFT content without proper registration)
Review webhook events
If the API returns
200 but the message doesn’t arrive, check message.finalized webhook events for delivery failure details. See Webhooks and delivery tracking.Still stuck? Check the Telnyx Status Page for platform issues, or contact support with your message ID from the API response.
Webhooks and delivery tracking
After sending a message, Telnyx delivers real-time status updates via webhooks. Configure a webhook URL on your Messaging Profile to receive these events automatically.Message lifecycle events
Messages progress through these statuses:| Event | Status | Description |
|---|---|---|
message.sent | sent | Message accepted and sent to the carrier |
message.finalized | delivered | Carrier confirmed delivery to the handset |
message.finalized | delivery_failed | Carrier could not deliver the message |
message.finalized | delivery_unconfirmed | No delivery confirmation received from the carrier |
Not all carriers return delivery receipts. Some messages may remain in
sent status without a finalized event. US carriers generally support delivery receipts for SMS; international coverage varies.Webhook payload example
Processing webhooks
Set up an endpoint to receive webhookPOST requests and return a 200 response. Telnyx retries failed deliveries with exponential backoff.
Retrieve message status via API
You can also check a message’s current status by its ID:Delivery failure error codes
When a message fails delivery, theerrors array in the webhook payload contains error codes:
| Code | Description | Action |
|---|---|---|
30003 | Unreachable destination | Verify the number is active and can receive SMS |
30004 | Message blocked by carrier | Check content compliance and sender registration |
30005 | Unknown destination | Number may be disconnected or invalid |
30006 | Landline or unreachable | Number cannot receive SMS (landline, VoIP) |
30007 | Carrier violation | Message rejected due to content filtering |
30008 | Destination capacity exceeded | Retry after a delay |
For a complete error code reference, see the Messaging Error Codes guide.
Webhook security
Validate incoming webhooks to ensure they’re from Telnyx:- IP allowlisting — Telnyx sends webhooks from
192.76.120.192/27 - HTTPS endpoints — Always use HTTPS for your webhook URL
- Respond quickly — Return
200within 5 seconds to prevent retries
If your endpoint consistently fails to respond, Telnyx will retry with exponential backoff and eventually disable the webhook. Monitor your endpoint health to avoid missing delivery events.