“What’s my IP” is one of the most common questions people type into a search engine, and every page that answers it works the same way under the hood. It reads the IP address the request came from, sends it to an IP geolocation API, and shows what comes back: a country, a city, an internet provider, maybe a time zone. That makes it one of the best first projects for learning an API. The core idea fits in one request, but getting it right touches the things that trip people up in real apps, like proxies, IPv6, rate limits and keeping keys secret.
I recently built one of these, IPWiz, on top of the ipstack API. In this article I’ll go through the API first, because once you understand what it returns and where it gets awkward, building the page around it is mostly presentation. After that I’ll show how I’d vibe code the whole tool with an AI assistant, including the prompts and the parts you should check yourself.
What is an IP geolocation API?
An IP geolocation API takes an IP address and tells you where it is and who operates it. Internet providers are assigned blocks of addresses, and companies like ipstack maintain databases that map those blocks to locations and networks. You send an address, and you get back structured data you can use in your app.
With ipstack, that data comes in a few groups. There’s the location itself: continent, country, region, city, postcode, and a latitude and longitude. Then there’s context about that location that’s surprisingly handy, like the time zone with the current local time, the local currency, the country’s calling code and languages, and a flag image and emoji. The connection block tells you which internet provider the address belongs to and its autonomous system number (ASN). Finally, the security module gives a verdict on whether the address is a proxy, a VPN, a Tor exit node or a known crawler, with a threat level.
Not every plan returns all of this. According to ipstack’s pricing page, the free plan (100 requests a month, not for commercial use) includes the location data only. Time zone, currency and connection data start on the Basic plan, and the security module is part of Professional Plus. The response below came from a key with the security module, so expect fewer fields on a free key.
A “what’s my IP” page is only one use for all that. The same lookup can show prices in a visitor’s currency, preselect their country on a checkout form, set the right time zone for a calendar, or flag a login that suddenly comes from a different country. Once you have the integration working for one feature, you can reuse it for all of them.
How do you call the ipstack API?
You call ipstack with a single GET request that has the IP address in the path and your access key in the query string. After signing up at ipstack.com and copying the key from the dashboard, this is all it takes:
curl "https://api.ipstack.com/134.201.250.155?access_key=YOUR_KEY&hostname=1&security=1"
The hostname=1 parameter asks for a reverse DNS lookup, and security=1 adds the security block on plans that include it. Here’s the response I got for that address, trimmed slightly so it fits on the page:
{
"ip": "134.201.250.155",
"type": "ipv4",
"country_code": "US",
"country_name": "United States",
"region_name": "California",
"city": "Los Angeles",
"zip": "90013",
"latitude": 34.04759979248047,
"longitude": -118.29226684570312,
"location": {
"capital": "Washington D.C.",
"country_flag_emoji": "πΊπΈ",
"calling_code": "1",
"is_eu": false
},
"time_zone": {
"id": "America/Los_Angeles",
"current_time": "2026-10-26T08:34:54-07:00",
"code": "PDT"
},
"currency": { "code": "USD", "symbol": "$" },
"connection": {
"asn": 25876,
"isp": "Los Angeles Department of Water & Power"
},
"security": {
"is_proxy": false,
"is_tor": false,
"is_crawler": false,
"threat_level": "low",
"vpn_service": null,
"hosting_facility": false
}
}
Most of this maps straight onto a UI. The country name and flag emoji go at the top, the city and region underneath, and the time zone gives you a live clock almost for free. The latitude and longitude are good enough to drop a pin on a map, as long as you label it “approximate”. IP geolocation is usually right about the country and often right about the city, but it was never meant to find a street address, and your page shouldn’t suggest otherwise.
There’s also a /check endpoint that looks up whoever is making the request. It’s convenient for a quick test from your terminal, but it’s the wrong tool for a web app. When your server calls /check, ipstack sees your server’s address, so every visitor would be told they’re in whichever data centre you deploy to.
How do you get the visitor’s real IP address?
You read it from the request headers, specifically the first entry in x-forwarded-for. This is where most “what’s my IP” tutorials go wrong, because they assume the connection to your app comes straight from the visitor. On any modern host it doesn’t. Vercel, Netlify, Cloudflare and most load balancers sit in front of your code, and they pass the original address along in that header. If there were several proxies in the chain, each one appends to the list, which is why you take the first entry. Some platforms also set x-real-ip, which makes a sensible fallback.
Once you have an address, filter out the ones that mean nothing to a geolocation database before you spend a request on them. In local development you’ll see ::1 or 127.0.0.1. Office and home networks use private ranges like 10.x, 192.168.x and 172.16.x to 172.31.x, and IPv6 has its own private range starting with fc or fd. For any of those, skip the API and show a friendly “you’re on a local network” message instead.
The other thing to know is how ipstack reports errors. An invalid key, for example, comes back with a 401 status and a JSON body containing “success”: false and an error object with a code, a type and a message. Read that body rather than relying on the status code alone, so your page can show a clear message instead of a page full of empty fields.
Put together, the server side is short. Here it is as a Next.js route handler:
// app/api/lookup/route.ts
import { headers } from "next/headers";
const PRIVATE = /^(::1|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|f[cd])/i;
export async function GET() {
const h = await headers();
const ip = h.get("x-forwarded-for")?.split(",")[0]?.trim() || h.get("x-real-ip");
if (!ip || PRIVATE.test(ip)) return Response.json({ local: true });
const url = `https://api.ipstack.com/${encodeURIComponent(ip)}?access_key=${process.env.IPSTACK_ACCESS_KEY}&hostname=1&security=1`;
const res = await fetch(url, { cache: "no-store" });
const data = await res.json();
if (!res.ok || data.success === false) {
return Response.json({ error: data.error?.info ?? "Lookup failed" }, { status: 502 });
}
return Response.json(data);
}
When enabled, the returned payload includes an enriched security block:
Notice that the key never leaves the server. Because ipstack takes the key as a query parameter, calling the API from browser JavaScript would put it in plain view of anyone who opens the network tab. Keep the call in a route like this one, and if you log request URLs for debugging, mask the key first. The same goes for any developer panel that shows the request URL to visitors.
Why does showing both IPv4 and IPv6 need two requests?
A server only ever sees the one address a browser used to connect, so finding the other one takes a second request that can only travel over that type of connection. Many people now have both an IPv4 and an IPv6 address, and their browser picks one when it connects. If it picked IPv6, your server sees the IPv6 address and has no way of knowing the IPv4 one.
The way around this is to have the browser call two extra hostnames, one that only has an IPv4 address in DNS and one that only has IPv6. ident.me publishes exactly that pair, v4.ident.me and v6.ident.me, and it allows calls from browser JavaScript, so you can fetch both in parallel from the page. Each one replies with the address it saw as plain text. Give them a timeout of a few seconds, and treat a failure as a real answer rather than an error: if the IPv6 probe can’t connect, the visitor simply doesn’t have IPv6 on that network. If you’d rather not depend on a third party, you can set up the same thing on your own domain with an A-only and an AAAA-only subdomain.
How can you tell if someone is using a VPN?
If your plan includes ipstack’s security module (Professional Plus at the time of writing), you read it from the response: security.is_proxy, security.vpn_service and security.hosting_facility tell you whether the address belongs to a proxy, which VPN provider runs it if known, and whether it’s in a data centre. Tor exit nodes and known crawlers have their own flags.
On plans that include connection data but not the security module, you can still make a reasonable guess from the connection block. Home and mobile internet comes from consumer providers, while commercial VPNs rent servers from hosting companies. If connection.isp contains a name like Amazon, Google Cloud, Microsoft, DigitalOcean, Hetzner, OVH, Vultr or M247, the visitor is very likely on a VPN or proxy. Show the reasoning in a sentence, such as “this address belongs to DigitalOcean, which runs servers rather than home connections”. Present it as “likely” rather than certain. Some people genuinely browse from cloud machines, and some VPNs use residential addresses that no keyword list will catch.
How to vibe code the whole tool
With the API side understood, the rest of the build is a good fit for an AI coding assistant. I’d use a tool that edits a real project, like Claude Code or Cursor, rather than a single chat, because you’ll iterate on the same files over several prompts. The trick is to put the details from the sections above into your prompts. AI tools write very plausible code for this kind of app, and they also reliably make the mistakes we just covered: calling /check from the server, putting the key in client code, and ignoring the 200-status errors.
Start with the server route. This prompt covers the header handling, private addresses and error format, and it adds a way to look up any address, which visitors use more than you’d expect:
Create a Next.js App Router project. Add a GET route /api/lookup that reads the
visitor IP from x-forwarded-for (first entry), falls back to x-real-ip, and
calls ipstack at https://api.ipstack.com/{ip}?access_key=...&hostname=1&security=1
using IPSTACK_ACCESS_KEY from the environment. Never call ipstack for private or
loopback addresses (127.0.0.1, ::1, 10.x, 192.168.x, 172.16-31.x, fc/fd); return
{ local: true } instead. ipstack errors have success:false and an error object
in the JSON body: detect that and return a clear error. Never send the key to the browser. Also
accept ?ip= to look up any address, validated as IPv4 or IPv6.
When it’s done, open the route in your browser and search the response and the page source for your key. It shouldn’t appear anywhere. Then deploy a preview and check that the IP it reports matches what your phone shows on mobile data, which is the quickest way to confirm the forwarded header is being read correctly.
Next comes the page itself. People searching “what’s my IP” want the address immediately, in large type with a copy button, so tell the AI that explicitly or it will bury the address under a dashboard:
Build the home page: a large card with the visitor's IP address and a copy
button, then country with flag emoji, city and region, ISP, time zone with the
live local time, and currency. Below it, a search box to look up any IP. Show a
small map pin using Leaflet with OpenStreetMap tiles at the returned latitude and
longitude, with "approximate location" under it. Add light and dark themes.
The third prompt adds the two features that make the page better than the dozens of existing ones, IPv4 and IPv6 side by side and a VPN verdict with a reason:
In the browser, call https://v4.ident.me and https://v6.ident.me in parallel
(6-second timeout each) and show "IPv4" and "IPv6" rows; if one fails, show
"Not available on your connection". Add a VPN/proxy verdict: if the ipstack
response has a security object, use is_proxy, vpn_service and hosting_facility.
Otherwise flag "likely VPN or proxy" when connection.isp matches a list of
hosting providers (amazon, google, microsoft, digitalocean, hetzner, ovh, m247,
vultr, linode, cloudflare...). Explain the reason in one sentence.
Test this one with a VPN switched on and off. You should see the verdict change, and with many VPNs the IPv6 row will disappear, because they block IPv6 to stop it leaking around the tunnel.
The last prompt is optional, but it’s the feature developers remember. It shows the request and the raw JSON, so someone evaluating the API can see exactly what it returns for their own connection:
Add a collapsible "API trace" panel showing the exact request URL (with the
access key replaced by β’β’β’β’), the response status, how long it took in
milliseconds, and the full JSON response with syntax highlighting.
Between prompts, read the diff rather than accepting it wholesale. The parts worth your attention are small: where the IP comes from, where the key is used, and what happens when the API returns an error. If those three are right, the rest is layout, and you can let the AI iterate on that as much as you like.
Things to sort out before you launch
The first thing to watch is your quota, because on a “what’s my IP” page every visit is a lookup. Cache results by IP address for a few hours, since the location of an address rarely changes faster than that, and don’t run lookups for search engine crawlers at all. Their user agents are easy to detect, and they’ll otherwise eat a noticeable share of your requests.
Think about privacy too. In many countries an IP address counts as personal data, so if you keep a history of lookups, say so on the page and give people a way to clear it. Tying saved lookups to an anonymous cookie instead of an account keeps that simple.
Finally, add a short FAQ below the tool. Visitors who find out their IP address usually have a follow-up question: why their location looks wrong, whether someone can find their house from their IP, or what the difference between IPv4 and IPv6 is. Answering those on the page helps the people who ask them, and it’s also the content search engines show in their results.
Wrapping up
The finished tool is one API call with careful handling around it: read the right header, skip private addresses, check the response body for errors, keep the key on the server, and make a second pair of requests if you want both IP versions. ipstack does the hard part of mapping billions of addresses to places and networks, and an AI assistant can write most of the code around it in an afternoon if you give it those details up front.
You can try the finished version at ipstack.com/devtools/what-is-my-ip.
Try ipstack free
IP-to-location, ASN, ISP, time zone and threat data from one endpoint. Get a key and make your first call in under a minute.
Karam Alsalhani
All articles by Karam β