API documentation.
Complete guide to integrating The IP API into your applications.
Getting started
Follow these simple steps to start using The IP API in your application.
1. Get your API key
Sign up for a free account at theipapi.com to get your API key. The free plan includes 1,000 requests per day.
2. Make your first request
Use your API key to make a request to our geolocation endpoint:
curl "https://api.theipapi.com/v1/ip/8.8.8.8?api_key=YOUR_API_KEY"
3. Parse the response
The API returns JSON data with geolocation information:
{
"status": "OK",
"body": {
"asn": {
"asn": 13335,
"asn_description": "CLOUDFLARENET, US",
"country": "AU",
"created": "2010-07-15",
"network": "1.1.1.0/24",
"org_name": "Cloudflare, Inc.",
"rir": "ARIN",
"updated": "2021-07-01"
},
"company": {
"address": "101 Townsend Street, San Francisco, CA, US",
"name": "APNIC and Cloudflare DNS Resolver project",
"network": "1.1.1.0 - 1.1.1.255",
"route": "1.1.1.0/24"
},
"ip": "1.1.1.1",
"location": {
"city": "Los Angeles",
"country": "United States of America",
"country_code": "US",
"latitude": 34.052571,
"longitude": -118.243907,
"region": "California",
"timezone": "America/Los_Angeles"
},
"is_bogon": false,
"is_datacenter": false,
"is_vpn": false
},
"response_time_ms": 10
}
API reference
IP geolocation endpoint
Returns geolocation data for a specific IP address.
Parameters
ip_address(required) - The IP address to look upapi_key(required) - Your API key
Example request
curl "https://api.theipapi.com/v1/ip/8.8.8.8?api_key=YOUR_API_KEY"
Response fields
status- Response status ("OK" for successful requests)body.ip- The queried IP addressbody.location.country_code- Two-letter country codebody.location.country- Full country namebody.location.city- City namebody.location.region- State/region namebody.location.latitude- Latitude coordinatebody.location.longitude- Longitude coordinatebody.location.timezone- Timezone informationbody.asn.asn- Autonomous System Numberbody.asn.org_name- ASN organization namebody.asn.asn_description- ASN descriptionbody.company.name- Company namebody.company.address- Company addressbody.is_bogon- Whether IP is a bogon (private/invalid)body.is_datacenter- Whether IP belongs to a datacenterbody.is_vpn- Whether IP belongs to a VPN serviceresponse_time_ms- API response time in milliseconds
ASN lookup endpoint
Returns information about an Autonomous System Number (ASN).
Parameters
asn_number(required) - The ASN to look upapi_key(required) - Your API key
Example request
curl "https://api.theipapi.com/v1/asn/15169?api_key=YOUR_API_KEY"
Example response
{
"status": "OK",
"body": {
"asn": {
"asn": 15169,
"asn_description": "Google LLC",
"country": "US",
"created": "2005-11-23",
"org_name": "Google LLC",
"rir": "ARIN",
"updated": "2019-10-31"
}
},
"response_time_ms": 0
}
Response fields
status- Response status ("OK" for successful requests)body.asn.asn- The Autonomous System Numberbody.asn.asn_description- ASN description/namebody.asn.country- Country code where ASN is registeredbody.asn.created- Date when ASN was createdbody.asn.org_name- Organization namebody.asn.rir- Regional Internet Registry (ARIN, RIPE, APNIC, etc.)body.asn.updated- Last update dateresponse_time_ms- API response time in milliseconds
Batch IP geolocation endpoint
Look up geolocation data for multiple IP addresses in a single request. Up to 100 IPs per request. Each unique IP counts as one request against your API quota.
Parameters
api_key(required) - Your API key (query parameter)ips(required) - JSON array of IP addresses (request body)
Notes
- Maximum of 100 IP addresses per request
- Duplicate IPs are automatically deduplicated and only counted once
- All IPs are validated upfront - if any IP is invalid, the entire request is rejected
- Quota is checked before processing - if you don't have enough remaining requests for all unique IPs, the batch is rejected
Example request
curl -X POST "https://api.theipapi.com/v1/ip/batch?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"ips": ["8.8.8.8", "1.1.1.1", "192.168.1.1"]}'
Example response
{
"status": "OK",
"results": {
"8.8.8.8": {
"status": "OK",
"body": {
"ip": "8.8.8.8",
"location": {
"city": "Mountain View",
"country": "United States of America",
"country_code": "US",
"latitude": 37.386,
"longitude": -122.0838,
"region": "California",
"timezone": "America/Los_Angeles"
},
"asn": { "asn": 15169, "org_name": "Google LLC", ... },
"company": { "name": "Google LLC", ... },
"is_bogon": false,
"is_datacenter": true,
"is_vpn": false
},
"response_time_ms": 12
},
"1.1.1.1": {
"status": "OK",
"body": { ... },
"response_time_ms": 8
},
"192.168.1.1": {
"status": "OK",
"body": {
"ip": "192.168.1.1",
"is_bogon": true
},
"response_time_ms": 1
}
},
"total_ips": 3,
"response_time_ms": 15
}
Response fields
status- Overall request status ("OK" if the batch was accepted)results- Dictionary keyed by IP address, each containing the same response format as the single IP endpointtotal_ips- Number of unique IPs processedresponse_time_ms- Total batch processing time in milliseconds
Error responses
400- Invalid JSON body, no IPs provided, more than 100 IPs, or invalid IP address401- Missing or invalid API key405- Method not allowed (must use POST)429- Insufficient API quota for the batch size
Code examples
JavaScript (Node.js)
const https = require('https');
const options = {
hostname: 'api.theipapi.com',
path: '/v1/ip/8.8.8.8?api_key=YOUR_API_KEY',
method: 'GET'
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const result = JSON.parse(data);
console.log(result);
});
});
req.on('error', (error) => {
console.error(error);
});
req.end();
Python
import requests
url = "https://api.theipapi.com/v1/ip/8.8.8.8"
params = {"api_key": "YOUR_API_KEY"}
response = requests.get(url, params=params)
data = response.json()
print(data)
PHP
<?php
$url = "https://api.theipapi.com/v1/ip/8.8.8.8?api_key=YOUR_API_KEY";
$response = file_get_contents($url);
$data = json_decode($response, true);
print_r($data);
?>
Go
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api.theipapi.com/v1/ip/8.8.8.8?api_key=YOUR_API_KEY"
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var result map[string]interface{}
json.Unmarshal(body, &result)
fmt.Println(result)
}
Batch request - Python
import requests
url = "https://api.theipapi.com/v1/ip/batch"
params = {"api_key": "YOUR_API_KEY"}
payload = {
"ips": ["8.8.8.8", "1.1.1.1", "9.9.9.9"]
}
response = requests.post(url, params=params, json=payload)
data = response.json()
for ip, result in data["results"].items():
location = result["body"]["location"]
print(f"{ip}: {location['city']}, {location['country_code']}")
Batch request - JavaScript (Node.js)
const response = await fetch(
"https://api.theipapi.com/v1/ip/batch?api_key=YOUR_API_KEY",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
ips: ["8.8.8.8", "1.1.1.1", "9.9.9.9"]
})
}
);
const data = await response.json();
for (const [ip, result] of Object.entries(data.results)) {
console.log(`${ip}: ${result.body.location.city}`);
}
Batch request - curl
curl -X POST "https://api.theipapi.com/v1/ip/batch?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"ips": ["8.8.8.8", "1.1.1.1", "9.9.9.9"]}'
Rate limits
API requests are rate limited based on your subscription plan:
- › Free: 1,000 requests per day
- › Beginner: 600,000 requests per month
- › Standard: 3,000,000 requests per month
- › Premium: 15,000,000 requests per month
Rate limits reset daily for the Free plan and monthly for paid plans. For batch requests, each unique IP address counts as one request. Check your usage in the dashboard.
Error handling
The API returns standard HTTP status codes:
200- Success400- Bad Request (invalid parameters)401- Unauthorized (invalid API key)429- Too Many Requests (rate limit exceeded)500- Internal Server Error
Error response format
{
"error": {
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid"
}
}
Best practices
- › Cache results: IP geolocation data doesn't change frequently, so cache results to reduce API calls.
- › Handle errors: Always implement proper error handling for network issues and API errors.
- › Respect rate limits: Monitor your usage and implement backoff strategies.
- › Use HTTPS: Always use HTTPS endpoints for secure communication.
- › Validate input: Validate IP addresses before making API calls.
Need more help?
If you need additional assistance or have questions about the API:
- › Check out our FAQ page for common questions
- › Read our getting started guide
- › Contact our support team for personalized help