# IP lookup

```http
POST https://api.qelka.com/v1/ip
```

Looks up a public IPv4 or IPv6 address. Costs 1 credit. Errors are not billed, including the `422` returned for private and other special-purpose addresses.

## Request

```json
{
  "ip": "8.8.8.8",
  "fresh": false
}
```

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `ip` | string | Yes | none | A public IPv4 or IPv6 address, such as `8.8.8.8` or `2606:4700:4700::1111`. |
| `fresh` | boolean | No | `false` | `true` skips the 7-day result cache and runs the lookup again. |

## Response

```json
{
  "id": "lkp_01M84BQ42CYKZT70N43DNMM29E",
  "object": "ip",
  "input": "8.8.8.8",
  "version": 4,
  "country": { "code": "US", "name": "United States" },
  "region": null,
  "city": null,
  "asn": { "number": 15169, "org": "Google LLC", "type": "hosting" },
  "flags": { "tor": false, "vpn": false, "proxy": false, "datacenter": true },
  "risk": { "score": 35, "level": "medium" },
  "credits_used": 1,
  "cached": false
}
```

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup: `lkp_` and 26 characters. |
| `object` | string | Always `ip`. |
| `input` | string | The `ip` value you sent. |
| `version` | integer | `4` or `6`. |
| `country` | object or null | Country the address is registered or located in. Null when unknown. |
| `country.code` | string | ISO 3166-1 alpha-2 code. |
| `country.name` | string | English short name of the country. |
| `region` | string or null | Region, state or province. Null when unknown. |
| `city` | string or null | City. Null when unknown. |
| `asn` | object or null | The autonomous system that announces the address. Null when the address is not announced by a known network. |
| `asn.number` | integer | Autonomous system number, such as `15169`. |
| `asn.org` | string or null | Name of the organization that holds the autonomous system. Null when unknown. |
| `asn.type` | string | Kind of network. See [network types](#network-types). |
| `flags` | object | Four yes-or-no signals about the address. See [flags](#flags). |
| `flags.tor` | boolean | `true` when the address is a Tor exit node. |
| `flags.vpn` | boolean | `true` when the address belongs to a known VPN provider's network. |
| `flags.proxy` | boolean | `true` when the address belongs to a known proxy network. |
| `flags.datacenter` | boolean | `true` when the network is classified as hosting. |
| `risk` | object | Overall risk of traffic from this address. |
| `risk.score` | integer | From 0 to 100. See [IP risk score](/docs/ip-risk-score). |
| `risk.level` | string | `low`, `medium` or `high`. See [risk levels](#risk-levels). |
| `credits_used` | integer | Credits debited for this call. |
| `cached` | boolean | `true` when the result was served from the 7-day cache. |

## Network types

`asn.type` is classified from the network's registered name and from a curated list of hosting networks.

| `asn.type` | Meaning |
|---|---|
| `hosting` | Hosting, cloud or data center network. Traffic from it usually comes from servers, not from people at home. |
| `isp` | Internet service provider serving homes and businesses. |
| `mobile` | Mobile network operator. Many users share a few addresses behind carrier-grade NAT, so one address says little about one person. |
| `business` | A company's own network. |
| `education` | A school or university network. |
| `government` | A government network. |
| `unknown` | The network could not be classified. |

## Flags

| Flag | How it is set | Limits |
|---|---|---|
| `datacenter` | The network is classified as `hosting`. | Cloud desktops, corporate proxies and some privacy services also run on hosting networks. |
| `tor` | The address is on the Tor Project's list of exit nodes. | Only exit nodes are listed: the address a Tor user's traffic leaves from. |
| `vpn` | The address belongs to a known VPN provider's network. | Best effort. A VPN that runs on networks we do not know about is not flagged. |
| `proxy` | The address belongs to a known proxy network. | Best effort. Residential proxies, which route traffic through home connections, are generally not detectable. |

A `false` flag means "not detected", not "proven clean". Use the flags as signals next to the rest of what you know, as [Flag VPN and data center traffic](/docs/guides/flag-vpn-and-datacenter-traffic) shows.

## Risk levels

| `risk.level` | `risk.score` |
|---|---|
| `low` | 0 to 29 |
| `medium` | 30 to 69 |
| `high` | 70 to 100 |

The score is computed from the network flags, plus a small amount when the network that announces the address is unknown. [IP risk score](/docs/ip-risk-score) lists the exact weights.

## Location data

Country and ASN come from IPinfo Lite, region and city from DB-IP Lite. Both are free databases published under Creative Commons licenses, credited on the [data sources page](/data-sources). An IP address locates a network, not a person: the city is where the network's addresses are registered or routed, which can be far from the user. Treat `region` and `city` as approximate.

## Addresses that cannot be looked up

Private, loopback, link-local, documentation and other special-purpose addresses do not belong to any public network. The API answers `422 unprocessable_input` for them, and the call is not billed. The IANA special-purpose registries, described in RFC 6890, list them all. The most common ones:

| Kind | IPv4 | IPv6 |
|---|---|---|
| Private (RFC 1918) and unique local (RFC 4193) | `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` | `fc00::/7` |
| Loopback | `127.0.0.0/8` | `::1` |
| Link-local | `169.254.0.0/16` | `fe80::/10` |
| Documentation (RFC 5737, RFC 3849) | `192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24` | `2001:db8::/32` |
| Shared address space for carrier-grade NAT (RFC 6598) | `100.64.0.0/10` | none |

The most common surprise is local development: your server sees `127.0.0.1` or `::1` as the client address. Treat a `422` as "no signal" rather than as a failure.

## Examples

```bash
curl https://api.qelka.com/v1/ip \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"ip": "8.8.8.8"}'
```

```javascript
const response = await fetch('https://api.qelka.com/v1/ip', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ ip: '8.8.8.8' }),
})
const result = await response.json()
```

The response is the one shown above. With a live key, a documentation address returns an error instead. Test keys return sample data for the documentation ranges; see [Test mode](/docs/test-mode).

```bash
curl https://api.qelka.com/v1/ip \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"ip": "203.0.113.42"}'
```

```json
{
  "error": {
    "type": "unprocessable_input",
    "message": "203.0.113.42 is in Documentation (TEST-NET-3) (RFC 5737) and has no public location.",
    "docs": "https://qelka.com/docs/errors#unprocessable_input"
  }
}
```

Values in the examples are illustrative.

## Errors

| Status | Type | When |
|---|---|---|
| 400 | [invalid_request](/docs/errors#invalid_request) | `ip` is missing, shorter than 2 or longer than 64 characters, or the body has a field that is not listed above |
| 401 | [invalid_api_key](/docs/errors#invalid_api_key) | The key is missing, invalid or revoked |
| 402 | [insufficient_credits](/docs/errors#insufficient_credits) | Your balance is below 1 credit |
| 403 | [forbidden](/docs/errors#forbidden) | The key is restricted to other endpoints |
| 422 | [unprocessable_input](/docs/errors#unprocessable_input) | The address does not parse, or it is private, loopback, link-local, documentation or another special-purpose address |
| 429 | [rate_limited](/docs/errors#rate_limited) | Too many requests; wait `Retry-After` seconds |
| 500 | [internal_error](/docs/errors#internal_error) | Unexpected error on our side; retry with backoff |

None of these responses is billed.

## Related

- [Flag VPN and data center traffic](/docs/guides/flag-vpn-and-datacenter-traffic)
- Free tools: [IP lookup](/tools/ip-lookup), [VPN and proxy detection](/tools/vpn-proxy-detection), [ASN lookup](/tools/asn-lookup), [what is my IP](/tools/what-is-my-ip)
