# Let an AI Agent Read SMS Verification Codes

> How an n8n, browser or custom AI agent can read the SMS code sent to your iPhone at login, through a webhook, with only code texts sent on.

Last updated: 2026-10-25
Canonical HTML page: https://www.fwrdsms.com/blog/ai-agent-sms-verification-codes
Published: 2026-10-25

An AI agent can’t read your iPhone’s texts by itself, so you hand it the code: a Shortcuts Message automation passes each code text to Fwrd, which posts it from the iPhone to an endpoint your agent can reach, such as an n8n Webhook node or a small server. The agent then pulls the digits out with a regular expression and types them in. Use it only for accounts you own or are authorised to automate.

**What you need:** an iPhone on iOS 26 or later with the number that gets the codes, the Shortcuts app (it’s already on the phone), [Fwrd](https://apps.apple.com/app/apple-store/id6759069713?pt=128544281&ct=blog-ai-agent-codes&mt=8), and a public HTTPS address your agent can read, such as an n8n workflow, a Zapier or Make webhook, or your own server.

## How can an AI agent get the SMS code sent to my iPhone?

Through a webhook. The code arrives on the iPhone, Fwrd posts it as JSON to your endpoint, and your agent reads it from there.

iOS doesn’t let any app, or any agent, read the Messages inbox; [Is there an iPhone SMS API?](https://www.fwrdsms.com/blog/iphone-sms-api) explains why. What it does allow is a Message automation you set up yourself, which runs when a matching text arrives and hands it to the next action. Fwrd is that action. It sends the text straight from the iPhone to the address you give it, with no account and no Fwrd server in the middle.

Where the code lands depends on your agent:

- **An n8n AI Agent workflow.** A Webhook node receives the text and the workflow passes it on. [Forward iPhone SMS to n8n](https://www.fwrdsms.com/blog/forward-iphone-sms-to-n8n) has the node setup.
- **A browser agent or custom LLM agent.** A small server stores each text with the time it arrived, and the agent asks it for the newest code after it requests one.
- **A Zapier or Make scenario.** A catch hook or custom webhook starts the run. [Send iPhone texts to Zapier, Make or n8n](https://www.fwrdsms.com/iphone-sms-to-zapier-make-n8n) covers each tool.

For a chat assistant reading your texts in general, rather than a login code, see [connect ChatGPT to your iPhone texts](https://www.fwrdsms.com/blog/connect-chatgpt-to-iphone-texts).

## Should an agent handle your login codes?

Only for your own accounts, or ones you’re authorised to automate, and only where the service gives you nothing better.

- **Prefer the service’s own API tokens.** If the service offers API keys, OAuth or a service account, give the agent that. It never touches a login screen, and you can revoke it on its own.
- **Prefer passkeys or an authenticator app for your personal sign-in.** Keep SMS codes for the logins that offer nothing else.
- **Anyone who can read your endpoint can use the code.** Put a long secret in the address, delete each code once it’s used, and keep the endpoint’s logs private.
- **Check the service’s terms.** Some forbid automated sign-in, and some banks forbid sharing codes at all.

## How to send code texts to your agent

Add a Webhook destination that keeps only codes, then a Message automation that hands each code text to Fwrd. The [webhook guide](https://www.fwrdsms.com/guides/webhook) covers the endpoint side in full.

1. **Add a webhook in Fwrd.** Open Fwrd, tap +, and choose Webhook. Paste your endpoint’s whole HTTPS address into the Configuration field, tap Send Test Message so your endpoint sees the fields, then save with the tick.

2. **Keep only codes.** In the same destination, choose Only Some Texts under Which Texts and turn on Looks Like a Code, which keeps texts with a 4 to 8 digit code. That’s one condition, so it works on the free plan.

3. **Create a Message automation.** On iOS 27, open Shortcuts, tap Library, then Automation, then +. If you see Describe a shortcut, tap Edit. Tap Automation, then Message, change Sender to Message, and type a single space, so any text with a space in it reaches Fwrd’s filter. On iOS 26, open the Automation tab, tap +, choose Message, and type the space under Message Contains.

4. **Make it run without asking.** On iOS 27, tap the arrow beside the trigger and check that Confirm Before Run is off. Under ⓘ, then Privacy, check that Allow Running When Locked is on. On iOS 26, choose Run Immediately, then tap Next and Create New Shortcut.

5. **Add Fwrd’s action.** Search for Forward and add Forward Message to All Destinations. Set its Message to Shortcut Input (on iOS 26, Shortcut Input, then Message). Tap back to save (Done on iOS 26).

6. **That’s it.** New code texts now reach your endpoint on their own, with the iPhone unlocked or locked.

### What does the endpoint receive?

A POST with `Content-Type: application/json` and the text exactly as it arrived. The message is in `content`, and the same text is repeated in `text` for services that read that field. A `sender` field is added only when you turn on Include Who Sent It in Fwrd’s Settings and choose Sender on Fwrd’s action.

This curl command sends the same request Fwrd does, so you can build the agent’s side before a real code arrives:

```bash
curl -X POST "https://your-endpoint.example/sms/long-secret" \
  -H "Content-Type: application/json" \
  -d '{"content": "Your code is 123456", "text": "Your code is 123456"}'
```

To pull out the code, match the first run of 4 to 8 digits in `content`:

```python
import re

match = re.search(r"\b(\d{4,8})\b", body["content"])
code = match.group(1) if match else None
```

There’s no timestamp in the body, so record the time on your side and ignore codes older than your login attempt. Every attempt for the same text carries the same `Idempotency-Key` header, so you can drop repeats. Working examples for n8n and a small server are in the [fwrd-sms-webhook-examples repository](https://github.com/alanwtom/fwrd-sms-webhook-examples) on GitHub.

## Ways to get a code to an agent

| Approach | Who moves the code | Agent waits for you? |
|---|---|---|
| You read it and type it in | You | Yes, every login |
| The agent pauses and asks you in chat | You | Yes, every login |
| The service’s API token instead | Nobody, there’s no code | No |
| Fwrd posting it to your endpoint | The iPhone, on its own | No |

## What this setup can’t do

- **It can’t read codes that arrived earlier.** The automation only runs for new texts.
- **One number serves one login at a time.** Two agents asking for codes on the same number can read each other’s, so queue the sign-in step. For CI and QA pipelines, [SMS codes in CI](https://www.fwrdsms.com/blog/sms-otp-codes-ci-automation-iphone) covers that case.
- **The iPhone stays on and online.** After a restart, forwarding waits until you unlock it once, and an iPhone that isn’t unlocked for three days restarts itself.
- **Fwrd sends no login header.** Put the secret in the address; Fwrd keeps the whole address in the iPhone’s Keychain. It also rejects IP addresses and .local or .internal names.
- **It’s one way.** Fwrd can’t send a text from the iPhone for your agent.

## Questions about AI agents and SMS codes

### Can the agent read my other texts too?

Only the ones you let through. With Looks Like a Code on, Fwrd skips texts without a 4 to 8 digit code, and the endpoint never sees them.

### Do the codes go through Fwrd’s servers?

No. Fwrd has no account and no server of its own; each text goes from the iPhone straight to your HTTPS endpoint.

### Does it work with codes from short numbers?

Yes. The automation matches what the text says, not who sent it, so codes from short numbers that aren’t in your Contacts still reach Fwrd’s filter.

### What does it cost?

As of October 2026, Fwrd is free for 15 forwards a month, and a text counts once however many places it goes. Fwrd Pro removes the limit for $4.99 a month or $29.99 a year in the US.

## Keep reading

- [Is there an iPhone SMS API?](https://www.fwrdsms.com/blog/iphone-sms-api)
- [Connect ChatGPT to your iPhone texts](https://www.fwrdsms.com/blog/connect-chatgpt-to-iphone-texts)
