A small FastAPI microservice that resolves caller name information for a phone number using Twilio Lookup v2.
This service exposes a single endpoint to look up caller name metadata for a phone number in E.164 format.
- Python 3.9 or higher
- Twilio account with Lookup API access
TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKEN
The service will fail to start if either environment variable is missing.
- FastAPI
- Uvicorn
- Twilio Python SDK
- Pydantic
- Create a Python virtual environment:
python -m venv venv - Activate it:
source venv/bin/activate - Install dependencies:
pip install -r requirements.txt - Set your Twilio credentials:
export TWILIO_ACCOUNT_SID=your_sidexport TWILIO_AUTH_TOKEN=your_token - Start the server:
uvicorn server:app --reload
- GET
/lookup/caller-name?phone_number={phone_number}- Query parameter:
phone_numberin E.164 format, e.g.+18135551212 - Returns caller name metadata for the requested phone number.
- Query parameter:
{
"phone_number": "+18135551212",
"valid": true,
"national_format": "+1 813-555-1212",
"country_code": "US",
"caller_name": "SCAM ALERT",
"caller_type": "business",
"error": null
}- The current implementation uses
twilio.rest.Clientand Twilio Lookup v2. - Errors from Twilio are returned as HTTP errors with a JSON detail payload.