Have I Been Pwned API
Check if an email or password appeared in known data breaches.
What it does
Have I Been Pwned (HIBP) lets you check whether an email address or password has appeared in a known data breach. The account APIs need a key; the Pwned Passwords range API is free, key-less and uses k-anonymity so you never send a full password or its full hash.
Base URL
Authentication
Breach/account endpoints require an hibp-api-key header from a paid subscription (tiers differ by rate limit). Every request must also set a descriptive User-Agent. Pwned Passwords (https://api.pwnedpasswords.com/range/{prefix}) needs neither.
Code examples
# SHA-1 of "P@ssw0rd" = 21BD1...; send only the first 5 hex chars curl https://api.pwnedpasswords.com/range/21BD1
import hashlib, requests
def pwned_count(pw):
h = hashlib.sha1(pw.encode()).hexdigest().upper()
prefix, suffix = h[:5], h[5:]
r = requests.get(f"https://api.pwnedpasswords.com/range/{prefix}", timeout=10)
for line in r.text.splitlines():
s, count = line.split(":")
if s == suffix:
return int(count)
return 0
print(pwned_count("password")) # a very large numberRate limits & quotas
Pwned Passwords: effectively unlimited, cache-friendly (CDN-backed), add ?mode=ntlm or the Add-Padding: true header to hide response size. Account APIs: rate limited by subscription tier (e.g. 10 requests/minute on the entry plan), returning HTTP 429 with Retry-After when exceeded.
Key response fields
| (range response) | Lines of HASH_SUFFIX:COUNT — match your suffix to get the breach count |
| Name / Title / BreachDate | Breach metadata from /breachedaccount |
| DataClasses[] | What was exposed (Emails, Passwords, Phone numbers…) |
| IsVerified / IsSensitive | Whether the breach is confirmed / sensitive |
Common errors
| 401 | Missing or invalid hibp-api-key on an account endpoint. |
| 403 | Missing User-Agent header — it is mandatory. |
| 404 | Account not found in any breach (this is the ‘good’ answer). |
| 429 | Rate limit exceeded — wait Retry-After seconds. |
When to use it (and alternatives)
Use Pwned Passwords to block compromised passwords at sign-up or password-change — it is free and privacy-preserving. Use the paid breach API for security dashboards and user notifications. Never send a raw password anywhere; the range API exists precisely so you don’t have to.
FAQ
Is Have I Been Pwned free?
The Pwned Passwords range API is free and needs no key. Checking whether an email address is in a breach requires a paid API key, priced by rate-limit tier.
How does k-anonymity protect the password?
You hash the password with SHA-1 and send only the first 5 hex characters of the hash. The API returns every breached suffix under that prefix (hundreds of hashes); you match the rest locally, so the service never learns which one you asked about.
Why do I get a 403?
You did not send a User-Agent header. HIBP rejects requests without one to discourage anonymous abuse.
New to APIs?
Short guides for working with this API — and any other.