Let verified crawlers in
Keep bots out of the numbers you report, let a crawler past your rules by the address it comes from, and spot a client posing as one.
A user agent is a claim any client can make. This guide shows you how to keep bots out of the numbers you report, let a crawler past your rules by the address it comes from, and treat a client that only claims to be one.
How it works
Every answer includes is_bot, which is true when a known bot uses the address: a search engine's or an AI company's crawler, an uptime monitor, an internet scanner or a webhook sender. On a paid plan, bot says whose bot it is, which bots use the address, what they do and whether the operator vouches for the address.
A request that names a crawler in its user agent is that crawler only when it comes from an address the crawler's operator vouches for. The same user agent from any other address is a client posing as the crawler, usually to get past rules that let crawlers in.
Before you begin
- The routes your bot rules protect, and the crawlers you want on them.
- The
User-Agentheader of each request, which every web framework exposes.
1. Check whether a bot uses the address
export async function isKnownBot(ip) {
const res = await fetch(`https://api.vpndetection.io/${ip}`);
const answer = await res.json();
return answer.is_bot;
}import requests
def is_known_bot(ip):
answer = requests.get(f"https://api.vpndetection.io/{ip}").json()
return answer["is_bot"]is_bot is on the free plan, with no key. It is true for 66.249.66.1, a Googlebot address, and false for 8.8.8.8.
2. Keep bots out of your numbers
To count only people, skip a sign-up, a page view or an ad click when is_bot is true before you report, bill or pay out on it. Crawlers, uptime monitors and link checkers otherwise land in your analytics as visits nobody made.
With a paid plan
A paid plan can judge a request's user agent for you. Send the request's User-Agent header as the user_agent parameter, and the answer's user_agent.verdict says whether the address belongs to the bot the user agent names:
verified: the bot's operator vouches for the address as that bot, so let the request through.spoofed: the operator publishes the bot's addresses or sends it from its own registered network, and this address is not one of them, or the address has posed as the bot before.unverifiable: the operator publishes nothing the API can check the address against. Where the operator documents a reverse DNS name for its bot, you can check that name yourself.not_bot: the user agent names a browser, an app or a script, so your other rules decide.
export async function crawlerVerdict(ip, userAgent) {
const url = new URL(`https://api.vpndetection.io/${ip}`);
url.searchParams.set("user_agent", userAgent);
const res = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.VPNDETECTION_API_KEY}` },
});
const answer = await res.json();
return answer.user_agent?.verdict;
}import os
import requests
def crawler_verdict(ip, user_agent):
answer = requests.get(
f"https://api.vpndetection.io/{ip}",
params={"user_agent": user_agent},
headers={"Authorization": f"Bearer {os.environ['VPNDETECTION_API_KEY']}"},
).json()
return (answer.get("user_agent") or {}).get("verdict")With Googlebot's user agent, the verdict is verified for 66.249.66.1 and spoofed for 3.5.140.2. Treat a spoofed request as you treat any unknown client, or more strictly: the client chose to hide behind a crawler's name. A batch lookup takes the same check as user_agents, an object that maps each address to its request's user agent. The API uses the user agent only to answer the request.
bot holds the evidence behind the verdict: bot.verified is true when the operator vouches for the address, and bot.agents lists the bots it vouches for there. bot.categories says what the bots do, so each kind can get its own rule. search_engine and ai_search bring you visitors, ai_training collects pages to train models, and monitoring checks your uptime. For example, let search crawlers through and refuse training crawlers on your content.