---
title: "IP to country API: country, region and city for an IP address | APIFor"
description: "Turn an IPv4 or IPv6 address into a country code, region, city and coordinates with one GET request. Data from DB-IP Lite, CC BY 4.0. Examples in curl, Python and JavaScript."
canonical: "https://apifor.dev/guides/ip-to-country-api/"
---

**All guides All docs**

- [Guides](https://apifor.dev/guides/)
- IP to country API

# IP to country API: country, region and city for an IP address

GET /v1/ip?address=8.8.8.8 returns the country code (US), region, city and approximate coordinates for that address, and IPv6 works the same way. The data comes from DB-IP Lite under CC BY 4.0, and each lookup costs 1 credit.

Last checked 1 Dec 2026. Service: [IP geolocation dataset](https://apifor.dev/ip/). Reference: [endpoint docs](https://apifor.dev/docs/reference/ip/).

## What you get back

`country` is the ISO 3166-1 alpha-2 code and `continent` the two-letter continent code. `region`, `city`, `lat` and `lng` are approximate, and `version` says whether you sent IPv4 or IPv6.

There is no ISP, ASN, proxy or VPN flag. If you need fraud signals, this is the wrong tool; if you need a country to pick a currency, a language or a cookie banner, it is enough.

## Request

Send your key in the `x-api-key` header. New accounts get 1,000 free requests after email verification; [the quickstart](https://apifor.dev/docs/quickstart/) takes about a minute.

GET curl

```bash
curl 'https://api.apifor.dev/v1/ip?address=8.8.8.8' \
  -H 'x-api-key: YOUR_API_KEY'
```

Python

```
import os
import requests

r = requests.get(
    "https://api.apifor.dev/v1/ip",
    params={
        "address": "8.8.8.8",
    },
    headers={"x-api-key": os.environ["APIFOR_API_KEY"]},
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

JavaScript

```
const res = await fetch("https://api.apifor.dev/v1/ip?address=8.8.8.8", {
  headers: { "x-api-key": process.env.APIFOR_API_KEY },
});
const { data } = await res.json();
console.log(data);
```

## Response

This is the example recorded from the live API and published in our OpenAPI spec. The full spec is at [api.apifor.dev/v1/openapi.json](https://api.apifor.dev/v1/openapi.json).

200 OK

```json
{
  "success": true,
  "data": {
    "address": "8.8.8.8",
    "version": 4,
    "id": 18894,
    "continent": "NA",
    "country": "US",
    "region": "California",
    "city": "Mountain View",
    "lat": 37.422,
    "lng": -122.085
  }
}
```

## How accurate is it

Country is the reliable part. DB-IP describes its Lite files as a subset of the commercial database with reduced coverage and accuracy, so city and coordinates can be off, especially for mobile networks and corporate VPN exits. Treat the city as a hint.

Look up the address of the visitor on your server, from the connection or a trusted proxy header. Never trust a client-supplied address field for decisions that matter.

## Cache the results

Most sites see the same visitors again. Cache the result per address for a day or so and you will pay for a small share of page views. Since each lookup is 1 credit, a pack of 5,000 requests covers 5,000 distinct lookups.

## Typical uses

Preselect the country in a checkout or sign-up form, choose a default currency or language, show the right cookie notice, or route a support ticket to the team in the right time zone. In each case the user can still correct the guess. That suits approximate data.

Pair the country code with other lookups on the same key: [public holidays](https://apifor.dev/services/holidays/) to avoid scheduling on a day off, or [VAT rates](https://apifor.dev/services/tax/) to show prices with the right tax. Both take the same two-letter `country` code that this endpoint returns.

## Errors, limits and cost

A missing or wrong key returns 401, bad parameters return 400 with an `error.code`, and an unknown id returns 404. Rate limits are per key: a limited request gets 429 with a `Retry-After` header in seconds, so wait that long and retry. Calls that fail before any work starts are refunded. Details are in [errors](https://apifor.dev/docs/errors/) and [rate limits](https://apifor.dev/docs/rate-limits/).

This request costs 1 credit. Pricing is prepaid: 1,000 free requests once after email verification, then packs from $5 for 5,000 requests to $149 for 400,000. Credits never expire and there is no subscription. See [pricing](https://apifor.dev/pricing/).

## From an AI assistant

The same data is available as a tool on the APIFor MCP server at `https://mcp.apifor.dev/mcp`. Add it as a remote server in any client that supports remote MCP, sign in with OAuth or send your API key as a Bearer token, and ask in plain language. MCP calls use the same key and credits as REST. Setup steps are on the [MCP page](https://apifor.dev/docs/mcp/).

## Alternatives

- [DB-IP Lite downloads](https://db-ip.com/db/download/ip-to-country-lite): Free monthly CSV and MMDB files under CC BY 4.0. Host them yourself if you want no per-lookup cost and can keep the file updated.
- [ip-api.com free endpoint](https://ip-api.com/docs/legal): Free for non-commercial use only, limited to 45 requests per minute. Commercial use needs its pro plan.

Facts about other services come from their own pages or a test call on 1 Dec 2026. Prices and limits change, so confirm them there.

## Source and licence

IP geolocation by DB-IP (https://db-ip.com), DB-IP Lite, CC BY 4.0. If you show the location on a web page, DB-IP asks for a link back.

Every APIFor response carries the same attribution in `meta.attribution`. All sources are listed on [sources and licences](https://apifor.dev/sources/).

## FAQ

### Can I use this IP to country API in a commercial product?

Yes. The data is CC BY 4.0, which allows commercial use with attribution to DB-IP, and APIFor credits are paid per lookup.

### Does it support IPv6?

Yes. Pass an IPv6 address in address and the response has version 6.

### Does it detect VPNs or proxies?

No. It returns location fields only, with no network, ISP or proxy data.

## Related

- [IP geolocation dataset](https://apifor.dev/ip/)
- [Endpoint reference](https://apifor.dev/docs/reference/ip/)
- [Datasets by country](https://apifor.dev/countries/)
- [Phone number validation API](https://apifor.dev/services/phone/)
- [Domain lookup API](https://apifor.dev/services/domain/)
- [All guides](https://apifor.dev/guides/)

[Get a free API key](https://app.apifor.dev/register) [Use it from an AI client (MCP)](https://apifor.dev/docs/mcp/)
