Loading
Loading
The IP Geolocation API turns any IPv4 or IPv6 address — or a hostname — into its physical location and network owner in a single API call. One response returns the full location hierarchy (city, region, country, postal code, and coordinates with an accuracy radius), the ISP and Autonomous System behind the address, and the country's currency and dialing metadata — with optional hostname, timezone, abuse-contact, and user-agent data. It's built for developers adding geo-targeting, signup and checkout risk screening, and log enrichment to applications that need accurate location data without shipping and maintaining a local database.
Every response resolves an address from the continent down through country, region or state (with its ISO code), district, city, and neighbourhood, alongside the postal code, latitude and longitude, and a flag for whether the country is in the EU. Two values make the precision explicit: an accuracy radius in kilometres and a confidence rating for the match. Use it to drive country- and city-level personalisation, regional routing, and analytics segmentation from a single response.
Trim any response to return only the data your application reads, which cuts payload size and parsing overhead on high-volume calls. Responses are JSON by default and available as XML. Place names can be localised into nine languages — English, German, Russian, Japanese, French, Chinese (Simplified), Spanish, Czech, and Italian — so the returned location reads naturally for a global audience.
Read the country and region from each lookup to localise language, content, and compliance rules at the edge of a request. To show prices in the visitor's own currency from the same IP, pair this with the Geolocalized Currency Converter.
Compare the IP's country against the billing country to flag mismatches at registration or payment. When a session needs a real risk decision — proxy, VPN, Tor, or known-attacker signals with a single score — route the IP to the IP Threat Intelligence API and act on the result.
Resolve raw IPs in event logs to city, country, and operator before they reach your warehouse, so dashboards can segment by geography and network type. For datasets larger than a single address per call, the Bulk IP Geolocation Lookup processes up to 50,000 IPs in one request.
Read the operating organisation and network type from each lookup to separate consumer-ISP traffic from datacenter and hosting providers — useful for telling real users apart from server-to-server calls in reporting.
$ pip install requestsimport requests
url = "https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&lang=en&fields=location&include=security%2ChostnameFallbackLive"
payload = {}
headers = {
'X-apiKey': 'API-KEY'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Pass the address in the ip parameter. It accepts any IPv4 or IPv6 address, or a hostname, which the API resolves before locating. One call returns the location hierarchy, the network.asn operator, the country metadata, and the currency.
# Geolocate an IPv4 address (an IPv6 address or hostname works the same way){ "ip": "8.8.8.8", "location": { "continent_name": "North America", "country_code2": "US", "country_name": "United States", "state_prov": "California", "district": "Santa Clara", "city": "Mountain View", "accuracy_radius": "23.387", "confidence": "low", "zipcode": "94043-1351", "latitude": "37.42240", "longitude": "-122.08421", "is_eu": false }, "country_metadata": { "calling_code": "+1", "tld": ".us", "languages": ["en-US", "es-US", "haw", "fr"] }, "network": { "asn": { "as_number": "AS15169", "organization": "Google LLC", "asn_name": "GOOGLE", "type": "BUSINESS", "rir": "ARIN" } }, "currency": { "code": "USD", "name": "US Dollar", "symbol": "$" } }curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&apiKey=API-KEY'
Use fields with a comma-separated, dot-notation list to return only the values you read, or excludesto drop what you don't need. This keeps responses small on high-volume paths and isolates the one value a request actually needs.
# Country code only{ "ip": "8.8.8.8", "location": { "country_code2": "US" } } # Coordinates onlycurl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&fields=location.country_code2&apiKey=API-KEY'{ "ip": "8.8.8.8", "location": { "latitude": "37.42240", "longitude": "-122.08421" } } # The operator (ISP / organization) behind the IPcurl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&fields=location.latitude,location.longitude&apiKey=API-KEY'{ "ip": "8.8.8.8", "network": { "asn": { "organization": "Google LLC", "type": "BUSINESS" } } }curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&fields=network.asn.organization,network.asn.type&apiKey=API-KEY'
For dedicated Autonomous System data — full CIDR ranges and BGP peers — pass the AS number to the ASN Lookup API.
Call the endpoint without an ip parameter and it returns the geolocation of the IP that made the request.
# Geolocate the requesting IP{ "ip": "39.60.245.243", "location": { "country_code2": "PK", "country_name": "Pakistan", "state_prov": "Punjab", "city": "Lahore", "accuracy_radius": "2.991", "confidence": "high", "latitude": "31.52037", "longitude": "74.35875" }, "network": { "asn": { "as_number": "AS17557", "organization": "Pakistan Telecommunication company limited", "type": "ISP", "rir": "APNIC" } }, "currency": { "code": "PKR", "name": "Pakistan Rupee", "symbol": "₨" } }curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?apiKey=API-KEY'
The include parameter adds optional objects to the same response. Combine several with commas (include=hostname,time_zone).
include= value | Adds to the response |
|---|---|
| hostname · liveHostname · hostnameFallbackLive | Reverse hostname for the IP — from the stored database, from live sources, or database-then-live fallback. |
| time_zone | Timezone for the IP's location. For timezone data on its own, use the Timezone Lookup API. |
| security | IP risk signals — VPN, proxy, and Tor detection with a threat score. For risk decisions or screening at scale, use the IP threat intelligence API. |
| user_agent | Parses the request's User-Agent into browser, OS, and device. For user-agent parsing on its own, use the User Agent Parser API. |
| abuse | Network abuse-contact record (handle, email, phone) for the IP's range. |
| dma | US Designated Market Area code, for regional ad targeting. |
# Add hostname and timezone to a geolocation lookup{ "ip": "8.8.8.8", "hostname": "dns.google", "location": { "city": "Mountain View" }, "time_zone": { "name": "America/Los_Angeles", "current_time": "2025-09-01 07:15:31.164-0700", "current_tz_abbreviation": "PDT" } }curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&include=hostname,time_zone&fields=location.city&apiKey=API-KEY'
Adding security or abuseraises the credit cost of the call; the other values don't. See Pricing.
Set lang to return place names in any of nine languages — en, de, ru, ja, fr, cn, es, cs, it. Responses default to JSON; pass format=xml for XML.
# City and country in German{ "ip": "8.8.8.8", "location": { "city": "Mountain View", "country_name": "Vereinigte Staaten" } }curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/lookup?ip=8.8.8.8&lang=de&fields=location.city,location.country_name&apiKey=API-KEY'
To use the IP Geolocation API, you will need API credits. We only charge for successful queries, defined by a 2xx status code. If your request results in a 4xx or 5xx status code, no credits will be charged, and any deducted credits will be returned.
| Service | Credits |
|---|---|
| IP Geolocation (base) | 2 |
| + IP Security (include=security) | 6 |
| + Abuse Contact (include=abuse) | 6 |
| + IP Security + Abuse (include=security,abuse) | 10 |
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.