Country API

Beginner's Pick Geocoding / No Auth Required Beginner HTTPS CORS
Free to Use
87 A
Measured Score 0 50 100 Speed 27/30 Consistency 17/20 Security 20/20 Browser access 15/15 Transparency 8/15 TESTED 2026-08-10

Overview

Country.is is a simple, free API that detects a visitor's country based on their IP address. It returns a two-letter country code in milliseconds with no authentication required. It is ideal for beginners who need basic IP geolocation without setting up complex libraries.

Beginner Tip

When testing locally, the API will return a loopback or private network result; deploy to a real server to see accurate country detection. You can also pass any IP as a query parameter: http://country.is/8.8.8.8.

Measurement Record

What actually happened when we called this API from our own infrastructure. Every value below was recorded by the request, not copied from the provider's documentation.

Request
GET https://api.country.is/77.1.2.3?fields=city,continent,subdivision,postal,location,asn
Result
HTTP 200 · application/json · 261 bytes · compressed
Response time
38 ms (median of 3) · fastest 36 ms
Transport
TLSv1.3 · TLS_AES_256_GCM_SHA384 · certificate issued by Google Trust Services
Browser CORS
Allowed — Access-Control-Allow-Origin: *
Served by
cloudflare
Recorded
2026-08-10

Fields Returned

Top-level fields present in the response we captured, with the type and value we actually received.

Field Type Value received
ip string 77.1.2.3
country string DE
city string Hamburg
continent string EU
subdivision string HH
postal string 22041
location object {4 fields}
asn object {2 fields}

Captured Response

Captured from a real request to https://api.country.is/77.1.2.3?fields=city,continent,subdivision,postal,location,asn on 2026-08-10. Long arrays and nested objects are truncated to keep the shape readable.

JSON Response · Captured
{
  "ip": "77.1.2.3",
  "country": "DE",
  "city": "Hamburg",
  "continent": "EU",
  "subdivision": "HH",
  "postal": "22041",
  "location": {
    "latitude": 53.5774,
    "longitude": 10.0785,
    "accuracy_radius": 10,
    "time_zone": "Europe/Berlin"
  },
  "asn": {
    "number": 6805,
    "organization": "Telefonica Germany"
  }
}

Field Reference

ip The IP address that was queried, either from the caller or the one specified in the URL path.
country Two-letter ISO 3166-1 alpha-2 country code (e.g., "US", "DE", "JP") corresponding to the IP address.

Implementation Example

Calls a real endpoint of this API. Replace any placeholder credentials with your own key.

Request
const url = "http://country.is/8.8.8.8";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

How This API Fails

We deliberately sent this API a broken request and recorded exactly what came back on 2026-08-10. Knowing the shape of an error before you hit it makes error handling much easier to write.

HTTP 404 Requesting a path that does not exist application/json
{
  "error": {
    "code": 404,
    "message": "Not Found"
  }
}

Common Errors & Troubleshooting

Generated guidance based on this API's documentation, not observed by us. Treat it as a starting point and check against the provider's own error reference.

Returns "ZZ" or empty country code The IP address is private, reserved, or not in the geolocation database.
Use a real public IP address. Local development will always return a private IP; test with a specific IP like /8.8.8.8.
CORS error in browser Some browser security policies block requests to HTTP (non-HTTPS) endpoints.
Make the request from your server-side code rather than directly from the browser, or use a proxy.
Incorrect country detected IP geolocation databases are not 100% accurate, especially for VPNs and proxies.
This is expected behavior. For critical use cases, use a more accurate paid geolocation service.

Measured Score Breakdown

Live HTTP request to the API endpoint

Speed 27/30
Consistency 17/20
Security 20/20
Browser access 15/15
Transparency 8/15
Endpoint Response Time 38ms

Fully tested on Aug 10, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS YES
Category Geocoding
Difficulty Beginner
Endpoint last called: 2026-08-10

Related Tags

Similar APIs

View All →