Send a text to yourself from FastAPI
Yes. Homing Pigeon (homingpigeon.dev) lets your FastAPI app text your phone from any route, like when a new order comes in. The text goes out in a background task after the response is sent, so no request waits on it or fails because of it, and your coding agent can add it to the app you already have.
What to tell your agent
Use Homing Pigeon to text me from this FastAPI app when a new order comes in.
Your agent asks for your number, you read back the six-digit code, and it does the rest.
How it works in code
After pip install homingpigeondev, add this helper as notify.py, next to main.py:
import logging
import homingpigeondev
logger = logging.getLogger(__name__)
def text_me(message, key=None):
try:
homingpigeondev.send(message, idempotency_key=key, timeout=5)
except homingpigeondev.HomingPigeonError as err:
logger.warning("Text alert failed: %s", err)
Then have a route hand it to BackgroundTasks. This one, in main.py, texts you when a new order is saved. Replace save_order with your own code and use your own fields:
from fastapi import BackgroundTasks, FastAPI
from pydantic import BaseModel
from notify import text_me
app = FastAPI()
class Order(BaseModel):
item: str
total: float
@app.post("/orders", status_code=201)
def create_order(order: Order, background_tasks: BackgroundTasks):
order_id = save_order(order)
background_tasks.add_task(
text_me, f"New order {order_id} for ${order.total:.2f}.", f"order-{order_id}"
)
return {"id": order_id}
Good to know
- FastAPI runs the task only after the response has been sent, so the caller never waits on the text. If a send fails or takes longer than 5 seconds, the reason goes to your log as a warning and the request is not affected.
- The text reads like "New order 41 for $129.50." A plain
deftask liketext_meruns in FastAPI's thread pool, so a slow send never holds up other requests, even if your route isasync def. - The task is added only after
save_orderreturns, so an order that raises an error stays quiet. A request whose body does not matchOrdergets FastAPI's 422 response before your code runs, so it stays quiet too. - The order ID in the idempotency key means a retry never texts you twice for the same order.
- If your app is a package, import the helper with
from .notify import text_meinstead. - Background tasks run inside your app's process, which suits a short call like this one. For work that must survive a restart, use a job queue instead.
- FastAPI's
TestClientruns background tasks before it returns, so your tests would text you. Wrap them inunittest.mock.patch("main.text_me")to keep your phone quiet. - On your server, set
HOMINGPIGEON_API_KEYin the app's environment. After you verify your phone,npx -y homingpigeondev keyprints the key. On your own machine, runpython -m homingpigeondev verify +15551234567, then again with the six-digit code it texts you, and the key is saved for you. - Messages are limited to 480 characters and go only to the US mobile number you verified. Keep them plain, with no links. Delivery is not guaranteed, so treat each text as a heads-up.
Get started
Add Homing Pigeon to Claude Code, then ask for what you want:
claude mcp add homingpigeondev -- npx -y homingpigeondev mcp
You get 50 free texts every month, on US mobile numbers. See more use cases.