ZIP Code Distance API - Straight-Line Distance Between ZIP & Postal Codes Worldwide
Getting the distance between two postal codes usually means geocoding both, running a Haversine calculation, and repeating that for every pair in your dataset. The ZIP Code Distance API collapses that into one POST request: send a base point and a list of ZIP or postal codes, and it returns the straight-line distance to each one. The base can be a ZIP code, a postal code, or a set of location coordinates, and results come back with a per-code distance value in your choice of measurement unit. It's built for developers shipping store locators, delivery pricing, lead routing, and logistics tools, worldwide, not just US ZIP codes. Start with 10,000 free credits, no credit card required.
What You Get in Every Response
ZIP or Postal Code as the Base Point
Set the code field to any ZIP or postal code, list the targets in the compare array, and name the country they share. The API resolves every code and returns the distance from the base to each target, one request, no geocoding step on your side. Use it as a postal code distance API for UK postcodes, Canadian postal codes, and other national formats, not only 5-digit US ZIPs.
Location Coordinates as the Base Point
Swap code for lat and longto measure from any point on the map such as a warehouse, a user's GPS fix, or a service hub, to a list of ZIP or postal codes in one call. The compare list still resolves per code, so you can rank fixed locations against a moving origin without maintaining your own coordinate table.
Up to 100 Codes per Request
Each response returns result_count and a results array with a distance value per code. A single request accepts up to 100 ZIP or postal codes, which makes it a practical distance between ZIP codes API for batch jobs, score an entire branch list against one origin instead of looping 100 single calls.
Pair Matching with a Distance Threshold
The /zipcode/distance/match endpoint takes a codes array plus a distance threshold and returns every pair within range as code_1, code_2, and the measured distance. With 100 codes it evaluates up to 4,950 pairs in one call, a ZIP code distance matrix API without building the matrix yourself. Use it to cluster orders near warehouses or flag territories that overlap.
Six Distance Units
The unit parameter accepts mi, km, m, ft, yd, and in, with km as the default. Distances are returned already converted, so a freight tool can read meters while a US-facing storefront reads miles, no post-processing on your side.
What developers build with this API
Nearest-branch and store locator ranking
Take the shopper's ZIP code as the base, send your full branch list in one request, and sort the response by distance to surface the closest locations. Pair it with the ZIP Codes Radius Search API when you'd rather pre-filter to codes inside a fixed service radius before ranking.Delivery pricing and service-area qualification at checkout
Measure from your dispatch point to the customer's postal code the moment it's entered, then price the delivery band or decline out-of-range orders before payment. Validate that the code exists first with the ZIP Code API and you've got the full checkout flow covered.Lead and territory routing
When a lead comes in with nothing but a ZIP code, measure it against every rep's home territory in a single call and assign the nearest one. The same pattern routes support tickets to field technicians.
Logistics pairing within a threshold
Feed a day's pickup and drop-off codes into the match endpoint with your maximum leg distance, and get back only the pairs worth consolidating, no N×N distance loop in your own code.
ZIP Code Distance API
API Endpoint
$ pip install requestsimport requests
import json
url = "https://api.apifreaks.com/v1.0/zipcode/distance"
payload = json.dumps({ "code": "V6H 3L4", "compare": ["P3A 5W8", "B3B 1K1", "H3E 1B5"], "country": "CA", "unit": "mi" })
headers = {
'Content-Type': 'application/json',
'X-apiKey': 'API-KEY'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
ZIP Code Distance Match API
API Endpoint
$ pip install requestsimport requests
import json
url = "https://api.apifreaks.com/v1.0/zipcode/distance/match"
payload = json.dumps({ "codes": ["71149", "56517", "54510", "51549", "10009"], "country": "US", "distance": 1000, "unit": "mi" })
headers = {
'Content-Type': 'application/json',
'X-apiKey': 'API-KEY'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
How-To-Guides
Calculate Distance from One ZIP Code to a List of ZIP Codes
A branch finder rarely needs one distance, it needs the customer's ZIP scored against every location you operate. This call takes one base code and up to 100 targets in compare, and returns a distance per target, sorted your way. All codes must be from the same country.
# Response { "result_count": 4, "results": [ { "code": "71149", "distance": 1230.047 }, { "code": "56517", "distance": 1207.996 }, { "code": "10001", "distance": 1.705 }, { "code": "51549", "distance": 1117.441 } ] }curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance?apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "code": "10009", "compare": ["71149", "56517", "10001", "51549"], "country": "US", "unit": "mi" }'
Calculate Distance from Location Coordinates to a List of ZIP Codes
When the origin is a live GPS fix or a warehouse that doesn't sit neatly on a postal code, start from coordinates instead. Pass lat and long as the base and the API measures to each code in compare, here, three UK postcodes from a point in London. If you only have a street address, resolve it to coordinates first with the Forward Geocoding API.
# Response { "result_count": 3, "results": [ { "code": "E1 0AZ", "distance": 11.977 }, { "code": "HD1 1AB", "distance": 259.566 }, { "code": "OX1 1PU", "distance": 76.004 } ] }curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance?apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "lat": 51.5132336, "long": -0.2273734, "compare": ["E1 0AZ", "HD1 1AB", "OX1 1PU"], "country": "GB" }'
Find All Pairs of ZIP Codes within a Specific Distance
Consolidating shipments, detecting overlapping territories, or clustering sites all reduce to the same question: which of these locations are close to each other? Send the whole list in codes with an upper distance threshold, and the match endpoint returns only the qualifying pairs, up to 4,950 pair evaluations from a single 100-code request.
# Response { "result_count": 2, "results": [ { "code_1": "56517", "code_2": "51549", "distance": 442.561 }, { "code_1": "71149", "code_2": "51549", "distance": 605.837 } ] }curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance/match?apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "codes": ["71149", "56517", "54510", "51549", "10009"], "country": "US", "distance": 1000, "unit": "mi" }'
Convert JSON Response to XML
Legacy WMS and EDI integrations often ingest XML, not JSON. Add format=xml to the query string and the same request returns the identical structure as XML, no separate endpoint, no transformation layer in your pipeline.
# Response <CodeDistance> <result_count>3</result_count> <results> <code_distance> <code>E1 0AZ</code> <distance>11.977</distance> </code_distance> <code_distance> <code>HD1 1AB</code> <distance>259.566</distance> </code_distance> <code_distance> <code>OX1 1PU</code> <distance>76.004</distance> </code_distance> </results> </CodeDistance>curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance?format=xml&apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "lat": 51.5132336, "long": -0.2273734, "compare": ["E1 0AZ", "HD1 1AB", "OX1 1PU"], "country": "GB" }'
FAQs
One POST request returns result_count and a results array with the straight-line distance from your base point to every code in the compare list. The base point can be a ZIP code, a postal code, or lat/long coordinates. Distances arrive in the unit you set with unit, defaulting to kilometers.
The ZIP Codes Radius Search API discovers codes, it returns every ZIP code inside a radius you define. The ZIP Code Distance API measures codes you already have. Use radius search to build the candidate list, then this API to score or rank it.
Yes. Replace code with lat and long in the request body and the API measures from those coordinates to every code in compare. The target codes still need a country, and all targets must be from that same country.
Pricing
To use the ZIP Code Distance and Distance Match APIs, API credits are required. Charges apply only for successful queries, defined by a 2xx status code. If a request results in a 4xx or 5xx status code, no credits will be deducted, and any credits already charged will be refunded.
For each successful request, 5 credit will be charged. Utilize the Credits Usage API to efficiently monitor your recent consumption of both one-off and subscription credits. This API provides a streamlined way to track and manage your credit usage, ensuring you stay informed about your remaining balance and can optimize your resource allocation effectively.