Filtering Zip Codes By Radius Using API Filters + OpenAI's ChatGPT
Lead Prosper has always made it easy to filter leads based on any data points you collect, including filtering leads based on zip code lists. In the past you had to simply upload a list of all zip codes and choose whether to allow or block leads based on that zip list. But what about if you wanted to filter leads based on a radius around a specific zip code? To do this in the past you would need to take the time to generate a list of the zip codes within the given radius using online tools, and then update your zip filter using that newly generated list.
With the rise of AI platforms like ChatGPT, and the introduction of API Filters in Lead Prosper, determining if a zip code is within a certain radius of an area can be completely dynamic and automated. Let's show you an example of how you could accomplish zip radius filtering using OpenAI's API and API Filters.
Setting Up an OpenAI API Filter
To get started, you'll need an OpenAI account and an API key.
If you don't already have an API key, follow this guide from OpenAI to generate one. Once you have your API key, make sure to copy it—you’ll need it during the setup process.
Adding the OpenAI API Filter to Your Campaign
Navigate to your Campaign.
Decide where you'd like to apply the filter:
- Globally, across your entire campaign
- Or to a specific Supplier or Buyer
- Click New Filter > API Filter to start setting up the filter.
Configuring the API Filter
A pop-up window will appear with configuration options. These settings are tailored specifically for use with the OpenAI API. If you're using a different API provider, the setup may look quite different.
- Run filter on: Choose Pre-Ping, Ping, and / or Post.
- Post URL: https://api.openai.com/v1/chat/completions
- Request Method: POST
- Payload Type: JSON
- HTTP Timeout: 30 (default)
- Body:
{ "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that determines if a U.S. ZIP code is within a 50-mile radius of Asheville, North Carolina. Only respond with Yes or No." }, { "role": "user", "content": "Is ZIP code 28806 within 50 miles of Asheville, NC?" } ] }
- Custom Headers:
Key: Content-Type
Value: application/json
Key: Authorization
Value: Bearer {{OpenAI_API_Key}}
- Response Type:
- Action: Allow
- Condition: key equal with
- Key: choices/0/message/content
- Value: Yes
- Customer Error Message (optional): Zip code not within given range.
Understanding the OpenAI ChatGPT Prompt
Lets break down the Body so you can understand what can be modified to produce different results:
{ "role": "system", "content": "You are a helpful assistant that determines if a U.S. ZIP code is within a 50-mile radius of Asheville, North Carolina. Only respond with Yes or No." }
This part of the setup provides context to OpenAI about what you're asking it to do. Here's what the prompt is communicating:
- You are assigning the role of an assistant (or character).
- The assistant’s task is to check whether a given ZIP code falls within a 50-mile radius.
- The reference point for that radius is Asheville, North Carolina.
- If the ZIP code is within the 50-mile radius, the assistant should respond with “Yes.”
- If the ZIP code is not, the response should be “No.”
Here’s an example of how your prompt might look using placeholders for dynamic data:
{ "role": "system", "content": "You are a helpful assistant that determines if a U.S. ZIP code is within a {{number_of_miles}}-mile radius of {{city}}, {{state}}. Only respond with Yes or No." }
{{number_of_miles}} - replace with the number of miles you want to search for the radius
{{city}}, {{state}} - replace with the city, state combination you want to base the zip code radius around, or you can replace this with a single zip code.
{ "role": "user", "content": "Is ZIP code 28806 within 50 miles of Asheville, NC?" }
This section is where you will replace the ZIP code value '28806' with your zip_code campaign field shortcode - default is {{zip_code}}. And then you can replace the "50 miles of Asheville, NC" with the updates you made in the section above. Here is an example of how this might look with placeholders:
{ "role": "user", "content": "Is ZIP code {{zip_code}} within {{number_of_miles}}-miles of {{city}}, {{state}}?" }
{{zip_code}} - the input zip code
{{number_of_miles}} - replace with the number of miles you want to search for the radius
{{city}}, {{state}} - replace with the city, state combination you want to base the zip code radius around, or you can replace this with a single zip code.
For example, if we wanted to check if a zip_code was within a 25 mile radius of Fort Lauderdale, FL we would update the payload to the following:
{ "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that determines if a U.S. ZIP code is within a 25-mile radius of Fort Lauderdale, FL. Only respond with Yes or No." }, { "role": "user", "content": "Is ZIP code {{zip_code}} within 25-miles of Fort Lauderdale, FL?" } ] }
Here is how this API filter would look in the end:
By combining the flexibility of Lead Prosper's API Filters with the power of OpenAI, you can now dynamically filter leads based on geographic radius—without the need for manually uploading and maintaining ZIP code lists. This approach not only saves time but also allows for more intelligent, real-time decision-making within your lead flow. As AI continues to evolve, so do the tools at your disposal. We’re excited to see how you’ll use these capabilities to fine-tune your lead quality and boost campaign performance.