How to Self-Host Your Own Free IP Geolocation API on Vercel
Third-party API dependencies are a risk. They can go down, change pricing, add rate limits, or shut down entirely. If IP geolocation is critical to your app, self-hosting gives you full control โ and with Vercel, it's free.
Why Self-Host?
- Zero rate limits โ Your instance, your rules
- No API key management โ One less secret to rotate
- Privacy โ User IPs never leave your infrastructure
- Reliability โ No dependency on a third-party service
- Custom domain โ
geo.yourdomain.com - Free โ Vercel's free tier is generous for API usage
How It Works
Vercel's Edge Network automatically adds geolocation headers to every incoming request. These headers contain the visitor's city, country, coordinates, timezone, and more โ derived from their IP address at the edge.
The Kamero Geo API simply reads these headers and returns them as JSON. There's no external database, no API calls to third parties, and no IP processing on your end. Vercel does all the heavy lifting.
// This is the entire API โ it just reads Vercel headers
import { geolocation, ipAddress } from "@vercel/functions";
export async function GET(request) {
const geo = geolocation(request);
const ip = ipAddress(request);
return Response.json({
ip,
city: geo.city,
country: geo.country,
countryRegion: geo.countryRegion,
latitude: geo.latitude,
longitude: geo.longitude,
// ... more fields from headers
});
}Option 1: One-Click Deploy (30 Seconds)
The fastest way โ click the button and Vercel handles everything:
โ Deploy to Vercel (one click)
This will:
- Fork the repository to your GitHub account
- Create a new Vercel project
- Deploy it automatically
- Give you a live URL like
geo-location-api-xyz.vercel.app
Option 2: Manual Deploy (5 Minutes)
# Clone the repository
git clone https://github.com/kamero-ai/geo-location-api.git
cd geo-location-api
# Install dependencies
npm install
# or: bun install
# Deploy to Vercel
npx vercel deploy --prodOption 3: Fork and Customize
Fork the repo on GitHub, then customize the API to your needs:
// Add custom fields, filtering, or authentication
export async function GET(request) {
const geo = geolocation(request);
const ip = ipAddress(request);
// Add your custom logic
const isEU = ["AT","BE","BG","HR","CY","CZ","DK","EE",
"FI","FR","DE","GR","HU","IE","IT","LV","LT","LU",
"MT","NL","PL","PT","RO","SK","SI","ES","SE"
].includes(geo.country || "");
return Response.json({
ip,
city: geo.city,
country: geo.country,
latitude: geo.latitude,
longitude: geo.longitude,
timezone: request.headers.get("x-vercel-ip-timezone"),
isEU, // Custom field!
});
}Adding a Custom Domain
- Go to your Vercel project โ Settings โ Domains
- Add your domain (e.g.,
geo.yourdomain.com) - Add the DNS records Vercel provides (CNAME or A record)
- Wait for DNS propagation (usually minutes)
Your API is now available at:
https://geo.yourdomain.com/api/geoVercel Free Tier Limits
Vercel's Hobby (free) plan is generous for API usage:
| Resource | Free Tier Limit |
|---|---|
| Serverless Function Invocations | 100,000/month |
| Bandwidth | 100 GB/month |
| Edge Middleware Invocations | 1,000,000/month |
| Deployments | Unlimited |
For most projects, this is more than enough. If you outgrow it, Vercel's Pro plan ($20/month) significantly increases these limits.
Monitoring Your Instance
Vercel provides built-in analytics and logs. You can also add a simple health check endpoint:
// app/api/health/route.ts
export async function GET() {
return Response.json({
status: "ok",
timestamp: new Date().toISOString(),
});
}