Build an AI Property Research Agent with Live Listings
An AI real estate research tool needs two things: live listing and valuation data from more than one source, and a model that explains the numbers without inventing any. This tutorial builds one in Python. Given a Redfin property ID, it pulls the listing and valuation from Redfin and the matching Zillow listing nearby, reconciles list price, Zestimate, last sale and tax assessment, and has Claude explain the gaps. A question costs 3 credits, capped at 4.
What does the agent do, step by step?
It turns one property into a short, sourced explanation of what it's worth on paper. The plan is fixed, which keeps the cost predictable: code makes three calls, builds a facts object, and hands it to the model with instructions to use only those numbers. The model never decides which endpoints to call.
- Fetch the home from the Redfin Property endpoint: address, beds, baths, square feet, year built and coordinates.
- Fetch its valuation from the Redfin Valuation endpoint: list price, last sale price and date, and whether a Redfin Estimate is available.
- Search Zillow within a quarter mile of the coordinates with the Zillow API, and keep the listing whose street address and ZIP match.
- Build the facts: every number with its source, and
nullfor anything missing. - Ask Claude to compare the list price with each estimate that exists and to name what's missing.
You need Python 3.10 or later, a Perceptlayer API key and an Anthropic API key. Get a free API key; verified accounts get 100 free credits once, enough for 33 questions. Install pip install anthropic requests and export PERCEPTLAYER_API_KEY and ANTHROPIC_API_KEY.
Why compare Redfin and Zillow at all?
Because automated valuations disagree, and each is only as good as the data behind it. Both companies publish their own accuracy: Zillow reports a nationwide median error of about 2% for homes on the market and about 7% for off-market homes (Zillow, 2026), and Redfin reports similar figures for the Redfin Estimate (Redfin, 2026). A median error means half of estimates miss the sale price by more than that.
Both report much smaller errors for homes on the market, where a current listing's details are available, so an estimate close to the list price on a listed home is less independent than it looks. The useful signals are elsewhere: a large gap between list price and an estimate, a last sale far below today's price, or a tax assessment out of line with both. A second source also covers the case where one has no estimate at all, which, as the recordings below show, happens.
How do you fetch the Redfin side?
Call the property and valuation endpoints with the same property_id, and the listing_id when you have one. Both are in a Redfin search result, and the property_id is the number at the end of a Redfin home URL, such as /home/124182. These are the exact requests behind the recordings used here:
curl "https://api.perceptlayer.com/v1/redfin/property?property_id=124182&listing_id=224635828" \
-H "X-API-Key: $API_KEY"
curl "https://api.perceptlayer.com/v1/redfin/valuation?property_id=124182&listing_id=224635828" \
-H "X-API-Key: $API_KEY"
The property response gives the address and coordinates the next step needs. Here's an excerpt, trimmed with …:
{
"data": {
"property_id": 124182,
"address": "2517 25th Ave W",
"city": "Seattle",
"state": "WA",
"zip": "98199",
"price": 2750000,
"beds": 3,
"baths": 4,
"sqft": 3570,
"year_built": 2005,
"latitude": 47.6416879,
"longitude": -122.3893426,
…
}
}
The valuation response carries the price history fields. Note the last line of this excerpt:
{
"data": {
"listingPrice": 2750000,
"lastSoldPrice": 1050000,
"lastSoldDate": 1285830000000,
"priceInfo": {
"amount": 2750000,
"label": "Listed at Price",
…
},
…
"sectionPreviewText": "Estimate Not Available",
"propertyId": 124182
}
}
lastSoldDate is milliseconds since the epoch, 30 September 2010. And this home has no Redfin Estimate: sectionPreviewText says so. We don't have a recording of a valuation that includes an estimate, so the agent reports this status text rather than reading an estimate field it can't name. The Redfin API guide covers search, region codes and valuation in more depth.
How do you find the same home on Zillow?
Search Zillow around the Redfin coordinates and match the address. GET /v1/zillow/search takes latitude, longitude and radius_mi, plus listing_category (category1 in the recorded request, which returned homes for sale) and page_size. A quarter-mile radius keeps the result set small; the agent then compares each listing's street address and ZIP with Redfin's.
curl "https://api.perceptlayer.com/v1/zillow/search?latitude=47.6416879&longitude=-122.3893426&radius_mi=0.25&listing_category=category1&page_size=50" \
-H "X-API-Key: $API_KEY"
We haven't run that request. The recorded Zillow search, a 5-mile radius around downtown Seattle, shows what a match would contribute. Here's an excerpt of its two listings, trimmed with …:
{
"data": {
"listings": [
{
"zpid": 2068074790,
"address": { "streetAddress": "1124 Sunset Avenue SW", "zipcode": "98116", "city": "Seattle", "state": "WA" },
"price": { "value": 14000000, "pricePerSquareFoot": 1779 },
"estimates": { "zestimate": 13068300 },
…
},
{
"zpid": 49046647,
"address": { "streetAddress": "1627 33rd Avenue", "zipcode": "98122", "city": "Seattle", "state": "WA" },
"listing": { "listingStatus": "forSale", "marketingStatus": "comingSoon", … },
"price": { "value": 1050000, "pricePerSquareFoot": 500 },
"taxAssessment": { "taxAssessedValue": 949000, "taxAssessmentYear": "2025" },
…
}
],
"count": 20,
"total_matching_count": 2058,
…
}
}
The first listing has a Zestimate 6.7% below its asking price (13,068,300 against 14,000,000). The second has no Zestimate at all, but a 2025 tax assessment of 949,000, 90% of its asking price. Neither is the Redfin home above, so in a test on these recordings the agent correctly reports no Zillow match. Zillow writes "Avenue" where Redfin writes "Ave", which is why the matcher normalises suffixes and directions before comparing.
What does the complete agent look like?
Here's the whole script. get counts credits from each response's X-Credits-Used header and refuses to call once the cap is reached. research makes the three calls and builds the facts. explain sends them to Claude with a system prompt that forbids new numbers. Set CLAUDE_MODEL to use another model.
"""Research one US home from Redfin and Zillow data, then have Claude explain the numbers."""
import datetime
import json
import os
import re
import sys
import anthropic
import requests
API = "https://api.perceptlayer.com/v1"
HEADERS = {"X-API-Key": os.environ["PERCEPTLAYER_API_KEY"]}
MODEL = os.environ.get("CLAUDE_MODEL", "claude-opus-5-5")
CREDIT_CAP = 4 # a question needs 3 calls; one spare
spent = 0
def get(path, **params):
"""One API call, counted against the cap. Failed calls cost nothing."""
global spent
if spent >= CREDIT_CAP:
raise RuntimeError(f"credit cap of {CREDIT_CAP} reached")
r = requests.get(f"{API}/{path}", headers=HEADERS, params=params, timeout=60)
spent += int(r.headers.get("X-Credits-Used", "0"))
r.raise_for_status()
return r.json()["data"]
ABBREV = {"avenue": "ave", "street": "st", "drive": "dr", "road": "rd", "boulevard": "blvd",
"place": "pl", "court": "ct", "lane": "ln", "southwest": "sw", "southeast": "se",
"northwest": "nw", "northeast": "ne", "north": "n", "south": "s", "east": "e", "west": "w"}
def street_key(address, zip_code):
words = re.sub(r"[^a-z0-9 ]", " ", address.lower()).split()
return " ".join(ABBREV.get(w, w) for w in words) + f" {zip_code}"
def ms_to_date(ms):
return datetime.datetime.fromtimestamp(ms / 1000, datetime.timezone.utc).date().isoformat() if ms else None
def research(property_id, listing_id=None):
ids = {"property_id": property_id, **({"listing_id": listing_id} if listing_id else {})}
home = get("redfin/property", **ids)
value = get("redfin/valuation", **ids)
nearby = get("zillow/search", latitude=home["latitude"], longitude=home["longitude"],
radius_mi=0.25, listing_category="category1", page_size=50)
key = street_key(home["address"], home["zip"])
match = next((z for z in nearby.get("listings", [])
if street_key(z["address"]["streetAddress"], z["address"]["zipcode"]) == key), None)
facts = {
"address": f'{home["address"]}, {home["city"]}, {home["state"]} {home["zip"]}',
"beds": home.get("beds"), "baths": home.get("baths"), "sqft": home.get("sqft"),
"year_built": home.get("year_built"),
"redfin": {
"list_price": value.get("listingPrice"),
"price_label": value.get("priceInfo", {}).get("label"),
"last_sold_price": value.get("lastSoldPrice"),
"last_sold_date": ms_to_date(value.get("lastSoldDate")),
"estimate_status": value.get("sectionPreviewText"),
},
"zillow": None,
"credits_used": spent,
}
if match:
tax = match.get("taxAssessment", {})
facts["zillow"] = {
"zpid": match["zpid"],
"list_price": match.get("price", {}).get("value"),
"zestimate": match.get("estimates", {}).get("zestimate"),
"tax_assessed_value": tax.get("taxAssessedValue"),
"tax_assessment_year": tax.get("taxAssessmentYear"),
"status": match.get("listing", {}).get("marketingStatus"),
}
facts["credits_used"] = spent
return facts
SYSTEM = """You explain US home valuation data to a buyer.
Use only the numbers in the JSON you are given. Never estimate a missing value.
Say which values are missing and why that matters. Compare the list price with
each estimate that exists, as a percentage. Mention the last sale and its date.
Keep it under 200 words and end with what to check next."""
def explain(facts):
client = anthropic.Anthropic()
response = client.messages.create(
model=MODEL,
max_tokens=16000,
system=SYSTEM,
messages=[{"role": "user", "content": json.dumps(facts, indent=2)}],
)
if response.stop_reason == "refusal":
return "The model declined to answer."
return "".join(b.text for b in response.content if b.type == "text")
if __name__ == "__main__":
pid = int(sys.argv[1])
lid = int(sys.argv[2]) if len(sys.argv) > 2 else None
facts = research(pid, lid)
print(json.dumps(facts, indent=2))
print(explain(facts))
print(f"\nCredits used: {spent}")
Run it with a Redfin property ID and, optionally, a listing ID: python property_agent.py 124182 224635828.
What does the agent return?
The facts object is the part we could test. With requests.get mocked to return the recorded Redfin property, Redfin valuation and Zillow search responses, research(124182, 224635828) made the three calls and returned this:
{
"address": "2517 25th Ave W, Seattle, WA 98199",
"beds": 3,
"baths": 4,
"sqft": 3570,
"year_built": 2005,
"redfin": {
"list_price": 2750000,
"price_label": "Listed at Price",
"last_sold_price": 1050000,
"last_sold_date": "2010-09-30",
"estimate_status": "Estimate Not Available"
},
"zillow": null,
"credits_used": 3
}
That's an honest, if thin, result: a list price of 2,750,000 against a 2010 sale at 1,050,000, no Redfin Estimate and no Zillow match in the recorded search. The model's job is to say exactly that, plus what to check next, such as the Zillow Property endpoint for a direct lookup by zpid. We haven't run the explanation step against a model for this article, so we don't show its output.
The fields map to the questions a buyer asks. List price against estimates answers "is it priced like the market thinks?". The last sale answers "what did the owners pay?". The tax assessment is a third, slower-moving reference. For which listing fields matter in valuation models, see real estate listing data for valuation.
What does a question cost?
Three successful calls at 1 credit each, so 3 credits a question, with the cap at 4 so a retry fits but a loop doesn't. Failed calls cost nothing and return X-Credits-Used: 0, which is why get reads the header instead of counting calls. The credits docs explain billing, and the model's tokens are billed separately by Anthropic.
| Questions a month | Credits |
|---|---|
| 100 | 300 |
| 1,000 | 3,000 |
| 10,000 | 30,000 |
The 100 free credits cover the first 33 questions once; after that you need a pack. Worked example: an internal tool answering 1,000 property questions a month spends 1,000 × 3 = 3,000 credits; 10,000 questions, 30,000 credits, fit in a Build pack of 50,000 credits. Purchased credits last 12 months; see pricing for what credits cost. The free tier runs at 1 request a second, so a question's three calls take about three seconds; the rate limits docs list the paid rates.
How do you make it more robust?
Four changes cover most failures. Each is small, and each keeps the fixed-plan design.
- Widen the Zillow search on no match. Retry once at 0.5 miles before giving up; the cap of 4 allows one extra call.
- Fall back to a direct Zillow lookup. If you already know the
zpid, the Zillow Property endpoint takeszpid[]and skips the address match. - Handle units. Apartments need the unit in the key; Redfin writes it into
address("Unit D4" in the recorded search), so keep it rather than stripping it. - Retry the right errors. Retry
rate_limitedandtemporarily_unavailableafterRetry-After; never retryinvalid_parameters. Handling web data API errors in Python has the pattern, and the errors docs list the codes.
To let a model choose calls itself instead, put the same endpoints behind the MCP server, as in the AI agents docs, and keep a per-question cap. To start, get a free API key and run the valuation call in the playground on the Redfin API page. Data is collected from publicly available sources and returned as found at the time of the call.
APIs in this post
Frequently asked questions
Which data does the property research agent use?
Redfin property details and valuation (list price, last sale price and date, estimate status) and a Zillow search around the home's coordinates (list price, Zestimate, tax assessment), all as JSON. The agent matches the Zillow listing to the Redfin home by normalised street address and ZIP code, since the two sites share no IDs.
How much does each question cost?
3 credits: one call each to redfin/property, redfin/valuation and zillow/search, at 1 credit per successful call. The script caps a question at 4 credits. Failed calls cost nothing. Every account gets 100 free credits once, after verifying an email address, enough for 33 questions. See pricing.
Why do some homes have no estimate?
Neither site estimates every home. The recorded Redfin valuation for a listed Seattle home returns "Estimate Not Available", and one of two recorded Zillow listings has a tax assessment but no Zestimate. The agent passes the missing values to the model as null, and the system prompt tells it to say so, not to guess.
Can the model make up a valuation?
The design makes that harder: code fetches the data, and the system prompt tells the model to use only the numbers in the facts object and never to estimate a missing value. Check its output against the facts before you show it to a user, especially percentages, which the model calculates itself.
Is this real estate advice?
No. The agent restates published list prices, automated estimates, past sales and tax assessments, as found at the time of the call. Automated estimates have known error rates, published by Zillow and Redfin themselves. Use the output as a starting point for an appraisal or an agent's comparable sales, not as a valuation.