One provider is never right about everything
IP databases disagree, especially at city level. Relying on a single source bakes its gaps into your product.
Use case — Geolocation
Localise content, default the right currency and timezone, enrich logs and sign-ups, or route requests by country. One GET returns location and network data for an IPv4 address, IPv6 address or domain.
01 — The problem
IP databases disagree, especially at city level. Relying on a single source bakes its gaps into your product.
Country names, codes, timezones and ASNs come back in different shapes from different services.
Geolocation often sits on the request path, so lookups need to be fast and cacheable.
02 — How it works
{
// …
"country": "Greece",
"country_code": "GR",
"city": "Athens",
"timezone": "Europe/Athens",
"isp": "…",
"asn": "…"
}
03 — Recipe
Call the API from your server, never from the browser, so your key stays private. Cache answers per IP on your side to save requests.
// Pick sensible defaults for a new visitor from their IP (works with a free key).
const LOOKUP = 'https://fast.ipapi.gr/api/lookup/';
async function visitorDefaults(ip) {
const r = await fetch(LOOKUP + encodeURIComponent(ip) + '?key=' + process.env.IPAPI_KEY,
{ signal: AbortSignal.timeout(1500) });
const geo = r.ok ? await r.json() : {};
const known = (v) => (v == null || v === 'No Data' ? null : v); // missing fields are "No Data"
return {
country: known(geo.country_code), // e.g. "GR"
timezone: known(geo.timezone) ?? 'UTC', // IANA, e.g. "Europe/Athens"
city: known(geo.city) // approximate; may be unknown
};
}
04 — Honest limits
05 — Questions
Yes. Free keys include geolocation and network data for a daily number of requests shown on the pricing page. Pro raises the limit and adds the bot-signal flags.
Yes. Pass an IPv4 address, an IPv6 address or a domain name. Domains are resolved and the resulting address is looked up.
Yes. GET /api/lookup/self returns data for the address the request comes from.
From the blog
Free: 1,000 requests a day, up to 20 API keys.