ASN Lookup API
You need to resolve IPs to their autonomous system number (ASN), organization, and basic security posture so you can make routing, fraud, or analytics decisions in real time. By the end of this guide, you’ll query an ASN lookup endpoint, authenticate correctly, parse the response fields you need, and integrate it into your application with a minimal, reliable flow.
What the ASN lookup returns and why it matters
An ASN lookup maps an IP address to the network that announces it on the internet (the AS), plus context you can use immediately: country, region, city, ISP, organization, and high-signal security flags. These attributes help you:
- Enforce network rules by AS or ISP.
- Geofence content or comply with regional policies (timezone and region fields).
- Screen for proxies, VPNs, or cloud providers during authentication and payments.
This article focuses on a single HTTP GET endpoint that returns JSON for an IP. All examples use the documented fixture IP and the exact path you can copy and paste into your code.
Endpoint overview
Endpoint path: /api/ip
Method: GET
Query parameter: ip=148.105.12.120 (fixture for examples only; use your own IPs in production)
Base host: https://ipxapi.com
Authentication: Authorization: Bearer YOUR_KEY
Important: The fixture below is static for documentation and not your current IP. Live responses can vary for flags like is_proxy or is_vpn. Always treat the example as a sample, not a guarantee of current status.
Authentication and headers
Authenticate with a Bearer token. Use the header Authorization: Bearer YOUR_KEY. Also request JSON explicitly to avoid content negotiation surprises:
- Accept: application/json
- Authorization: Bearer YOUR_KEY
Do not embed keys in URLs. Keep your key in a secure config store or secret manager and pass it as a header. Avoid logging full headers in production logs.
Quickstart: curl you can paste
Copy this exact request to verify connectivity and confirm your account setup. It uses the documented fixture IP and the canonical path.
curl "https://ipxapi.com/api/ip?ip=148.105.12.120" -H "Accept: application/json" -H "Authorization: Bearer YOUR_KEY"
Official JSON sample and field tour
Official product-fixture JSON for 148.105.12.120 (values shown here are from the documentation; live flags can change):
{
"status": "success",
"country": "United States",
"countryCode": "US",
"region": "US-CA",
"regionName": "California",
"city": "Mountain View",
"zip": "94043",
"lat": 37.40599,
"lon": -122.0786,
"timezone": "America/Los_Angeles",
"isp": "MailChimp",
"org": "MailChimp",
"as": "AS14782 MailChimp",
"query": "148.105.12.120",
"inEU": false,
"continentCode": "NA",
"security": {
"is_proxy": false,
"is_vpn": false,
"is_cloud_provider": true
}
}
What you’ll typically use in an ASN lookup:
- as: ASN string with a label (e.g., “AS14782 MailChimp”) for network-level decisions or audits.
- isp and org: Helpful to detect commercial hosting vs. residential service providers.
- security.is_proxy, security.is_vpn, security.is_cloud_provider: First-pass risk signals during sign-in and payments.
- country, countryCode, region, regionName, city, timezone: For geofencing and user experience adjustments (e.g., displaying local time). Timezone is an IANA TZ string.
- lat and lon: Decimal degrees for map overlays or coarse geolocation; do not use for precise personal location without appropriate consent and accuracy checks.
- query: Echo of the input IP for debugging and logging.
JavaScript example: request and parse the ASN
The snippet below calls the same endpoint and extracts fields typically needed for ASN-based routing, geofencing, and basic risk checks. Replace YOUR_KEY with your key when you run it.
// Minimal Node.js example using fetch (Node 18+ or add a fetch polyfill)
async function lookupIp(ip) {
const url = `https://ipxapi.com/api/ip?ip=${encodeURIComponent(ip)}`;
const res = await fetch(url, {
headers: {
Accept: 'application/json',
Authorization: 'Bearer YOUR_KEY'
},
// Consider short timeouts via AbortController in production
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(`ipxapi HTTP ${res.status}: ${text}`);
}
const data = await res.json();
// Read the essential fields
const result = {
ip: data.query,
as: data.as, // e.g., "AS14782 MailChimp"
isp: data.isp,
org: data.org,
country: data.country,
countryCode: data.countryCode,
region: data.region,
regionName: data.regionName,
city: data.city,
timezone: data.timezone, // e.g., "America/Los_Angeles"
lat: data.lat,
lon: data.lon,
inEU: data.inEU,
continentCode: data.continentCode,
is_proxy: data.security?.is_proxy === true,
is_vpn: data.security?.is_vpn === true,
is_cloud_provider: data.security?.is_cloud_provider === true
};
return result;
}
// Example usage with the documented fixture IP
lookupIp('148.105.12.120')
.then(info => {
console.log('ASN:', info.as);
console.log('ISP/Org:', info.isp, '/', info.org);
console.log('Geo:', info.country, info.regionName, info.city, '-', info.timezone);
console.log('Security flags:', {
proxy: info.is_proxy,
vpn: info.is_vpn,
cloud: info.is_cloud_provider
});
})
.catch(err => {
console.error('Lookup failed:', err);
});
Production notes that save time
Timezone semantics: timezone is an IANA string (e.g., America/Los_Angeles) that you can feed directly into most time libraries for local-time formatting. Do not guess DST rules; let the timezone database handle it.
Caching: IP metadata changes slower than user interactions. Cache successful lookups by IP in memory or your edge cache. A 24-hour TTL is common for operational use; choose a TTL aligned to your risk policy. If you detect a security-sensitive flow (e.g., high-value transaction), consider bypassing cache for a fresh decision.
Error handling: Treat non-2xx statuses as transient unless your application is sure the input is malformed. Implement exponential backoff for retries and budget your total retry time to avoid user-facing delays.
Security flags: is_proxy, is_vpn, and is_cloud_provider are booleans. They are high-signal but not exhaustive. Combine them with your own signals (velocity, device, account history) before denying access.
IP version: The example uses an IPv4 fixture. If you pass IPv6 to the same endpoint, ensure your input validation and storage support IPv6 strings fully (no assumptions about dotted quad formats). The endpoint path remains /api/ip.
Logging: Log the query IP and selected result fields (as, isp, security flags) for auditability. Avoid storing full address histories longer than required by your policy.
Development and testing via MCP
If you need a controlled environment or integration surface for your workflows, use MCP. It’s accessible at the following URL:
Keep your tests reproducible by pinning input IPs (like the fixture used here) and snapshotting responses when writing unit tests. Always segregate test keys from production keys and rotate them separately.
Onboarding, trial, and plan notes
Trial: 7 days or 50 requests, whichever comes first.
Basic plan: $29.99/mo.
Create an account to obtain YOUR_KEY and start making authenticated requests. You can register here:
For field definitions and additional examples, see the official docs:
Implementation checklist
- Store YOUR_KEY in a secure secret manager and pass it via Authorization: Bearer YOUR_KEY.
- Call GET https://ipxapi.com/api/ip?ip=YOUR_IP with Accept: application/json.
- Parse the as, isp, org, country, regionName, city, timezone, and security flags.
- Apply caching per IP with a TTL aligned to your tolerance for staleness.
- Instrument metrics on latency, hit ratio (cache), and the frequency of each security flag.
FAQ
Can I pass multiple IPs in one request?
This guide covers a single-IP query using /api/ip with the ip parameter. If you need bulk workflows, design them by batching calls client-side or consult the docs for options. Do not add undocumented parameters.
Are the security flags definitive?
No single signal is definitive. Use is_proxy, is_vpn, and is_cloud_provider as inputs to your risk engine. Always consider user context and additional telemetry before blocking.
How should I handle timezones?
Use the timezone field (IANA format) with a library that supports tzdata to render local times. Do not hardcode offsets; DST and regional changes are complex.
Is the sample IP my current address?
No. The fixture 148.105.12.120 is for documentation and testing only. It should not be treated as the reader’s IP, and live responses can differ from the sample values.
What happens when the API is temporarily unavailable?
Use short timeouts, exponential backoff, circuit breakers, and cached fallbacks. Degrade gracefully by skipping non-critical checks while logging the event for review.
Get started
Register to obtain YOUR_KEY, run the curl above against /api/ip with the fixture IP to confirm your setup, then wire the JavaScript snippet into your service to read as, isp, org, geo fields, and security flags. When you’re ready to move to production, enable caching, add retries, and monitor your key usage. Create your account here: Register.
