Kamero

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?

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:

  1. Fork the repository to your GitHub account
  2. Create a new Vercel project
  3. Deploy it automatically
  4. 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 --prod

Option 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

  1. Go to your Vercel project โ†’ Settings โ†’ Domains
  2. Add your domain (e.g., geo.yourdomain.com)
  3. Add the DNS records Vercel provides (CNAME or A record)
  4. Wait for DNS propagation (usually minutes)

Your API is now available at:

https://geo.yourdomain.com/api/geo

Vercel Free Tier Limits

Vercel's Hobby (free) plan is generous for API usage:

ResourceFree Tier Limit
Serverless Function Invocations100,000/month
Bandwidth100 GB/month
Edge Middleware Invocations1,000,000/month
DeploymentsUnlimited

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(),
  });
}

Deploy in 30 Seconds

One click. Free forever. Full control.

Deploy to Vercel โ†’