Skip to content

Zillow property data as Vercel AI SDK tools

Two ways to give a Vercel AI SDK app live U.S. property data: the ZillAPI MCP server, or your own tools on top of the REST API.

The AI SDK can load tools from a remote MCP server with createMCPClient. Connect it to the ZillAPI MCP server and your model can look up a home by address or zpid, read its Zestimate and rent Zestimate, and search listings inside a map area. Or define two small tools with tool() that call the REST API directly. Both use the same API key.

Install

Terminal window
npm i ai @ai-sdk/mcp @ai-sdk/openai zod

The code on this page was checked against ai 7.0.179, @ai-sdk/mcp 2.0.103 and @ai-sdk/openai 4.0.122. OpenAI is only the example model; any AI SDK provider works.

Add your keys

  1. Sign up and create a key on the API keys page. Keys start with zk_.
  2. Set it, and your model provider key, in the environment:
Terminal window
export ZILLAPI_KEY="zk_your_key_here"
export OPENAI_API_KEY="sk-..."

Keep the ZillAPI key on the server: in a Next.js app, use it in a route handler or server action, never in client code. See Authentication for how keys work.

Option 1: the ZillAPI MCP server

import { createMCPClient } from "@ai-sdk/mcp";
import { openai } from "@ai-sdk/openai";
import { generateText, isStepCount } from "ai";
const zillapi = await createMCPClient({
transport: {
type: "http",
url: "https://api.zillapi.com/mcp",
headers: { Authorization: `Bearer ${process.env.ZILLAPI_KEY}` },
},
});
try {
const { text } = await generateText({
model: openai("gpt-5-mini"),
tools: await zillapi.tools(),
stopWhen: isStepCount(5),
prompt: "What is the Zestimate for 350 5th Ave, New York, NY 10118?",
});
console.log(text);
} finally {
await zillapi.close();
}

zillapi.tools() loads the four ZillAPI tools and their input schemas from the server:

Tool What it does Required input
lookup_property_by_address Full property record for a U.S. street address address (street, city, state and ZIP)
lookup_property_by_zpid Full property record for a Zillow property id zpid
get_zestimate Zestimate and rent Zestimate for a zpid zpid
search_listings For sale, for rent or sold listings inside a bounding box bbox (west,south,east,north), status

stopWhen: isStepCount(5) lets the model call a tool, read the result and answer in the same request. With streamText, close the client in the onEnd callback instead of finally, so it stays open while the response streams.

Option 2: your own tools on the REST API

import { openai } from "@ai-sdk/openai";
import { generateText, isStepCount, tool } from "ai";
import { z } from "zod";
const API = "https://api.zillapi.com/v1";
const headers = { Authorization: `Bearer ${process.env.ZILLAPI_KEY}` };
const lookupByAddress = tool({
description: "Look up a U.S. property by full street address, city, state and ZIP.",
inputSchema: z.object({ address: z.string() }),
execute: async ({ address }) => {
const url = `${API}/properties/by-address?address=${encodeURIComponent(address)}`;
const res = await fetch(url, { headers });
return res.json();
},
});
const getZestimate = tool({
description: "Get the Zestimate and rent Zestimate for a Zillow property id (zpid).",
inputSchema: z.object({ zpid: z.string().regex(/^\d+$/) }),
execute: async ({ zpid }) => {
const res = await fetch(`${API}/properties/${zpid}/zestimate`, { headers });
return res.json();
},
});
const { text } = await generateText({
model: openai("gpt-5-mini"),
tools: { lookupByAddress, getZestimate },
stopWhen: isStepCount(5),
prompt: "What is the Zestimate for 350 5th Ave, New York, NY 10118?",
});
console.log(text);

Add fields= to the address lookup to return only the fields the model needs, for example &fields=zpid,price,zestimate. See Field projection. For more endpoints (listing search, comparable homes, price history), see the API reference and the zillapi-vercel-ai-sdk-example repository, which has ready-made tools, streaming and tests.

Costs per endpoint and plans are on the pricing page.

Troubleshooting

  • Tool results with an error about the API key. Check that ZILLAPI_KEY is set where the code runs (if it is not, the header becomes Bearer undefined). If it is set, the key was rejected: copy the whole key, starting with zk_, or create a new one on the API keys page.
  • The model answers without calling a tool. Add stopWhen so the model gets a second step after the tool result, and name the tool in the prompt if needed.
  • Search finds nothing. search_listings needs a bounding box, west,south,east,north in decimal degrees, not a place name.

Full error codes are listed on Errors.

FAQ

How do I use ZillAPI with the Vercel AI SDK?
Create an MCP client with createMCPClient from @ai-sdk/mcp, using an http transport to https://api.zillapi.com/mcp and the header Authorization: Bearer with your ZillAPI key. Pass await client.tools() to generateText or streamText, and close the client when the response is finished.
Should I use the ZillAPI MCP server or REST tools in the AI SDK?
The MCP client is the fastest start: the tools and their schemas come from the server. REST tools take a few more lines, but you choose the endpoints, the input schema and how much of each response the model sees.
Which AI SDK version does this page use?
The code was checked against ai 7.0.179, @ai-sdk/mcp 2.0.103 and @ai-sdk/openai 4.0.122. Any AI SDK model provider works; OpenAI is only the example.

ZillAPI is an independent service, not affiliated with, endorsed by, or sponsored by Zillow Group, Inc. “Zillow” and “Zestimate” are trademarks of Zillow Group, Inc., used here descriptively. See Trademark & Affiliation.