Framework: FastAPI
Suspicious login detection for FastAPI
Score FastAPI logins using a simple server-side call.
Add LoginLlama to FastAPI in one call
Call LoginLlama from your FastAPI login handler before you create the session. Send the email, IP, and user agent, then allow, challenge, or block based on the returned risk score.
from loginllama import LoginLlama, AuthenticationOutcome
from flask import Flask, request
app = Flask(__name__)
loginllama = LoginLlama(api_token=os.environ.get('LOGINLLAMA_API_KEY'))
# Use middleware for automatic IP/User-Agent detection
@app.before_request
def setup_loginllama():
loginllama.middleware()()
# Pre + Post Auth Pattern
@app.route('/login', methods=['POST'])
def login():
email = request.form['email']
password = request.form['password']
try:
# Step 1: Pre-auth check
pre_check = loginllama.check(
email,
authentication_outcome='pending'
)
if pre_check.risk_score > 7:
return {'error': 'Login blocked'}, 403
# Step 2: Authenticate
auth_result = authenticate(email, password)
# Step 3: Report outcome
if auth_result.success:
loginllama.report_success(auth_result.user.id)
return {'success': True}
else:
loginllama.report_failure(email)
return {'error': 'Invalid credentials'}, 401
except Exception as error:
print(f'LoginLlama error: {error}')
return {'success': True} # Fail open on errorsWhy teams choose LoginLlama for FastAPI
Score every login in under 100ms
Detect VPNs, proxies, and TOR exit nodes
Explain why a login is risky with clear risk reasons
Catch errors from the check and logins go ahead during an outage
How it works
Step 1
Install or connect LoginLlama
Choose the SDK or integration point that fits your auth flow and add your API key.
Step 2
Check risk at login time
Send the email, IP, and device context before completing authentication.
Step 3
Act on the risk score
Allow, challenge, or block the login based on risk score and reasons.
Signals we analyze
New device or browser fingerprints
Impossible travel and velocity checks
Bot-like login bursts and credential stuffing
Geo anomalies and risky IP reputation
Works well with your FastAPI stack
FastAPI login security FAQ
How do I add suspicious login detection to FastAPI?
Make a single POST request to https://loginllama.app/api/v1/login/check from your FastAPI login handler before you create the session. Send the user's email, IP address, and user agent, and branch on the returned risk score.
Will LoginLlama slow down FastAPI logins?
No. Risk scoring returns in under 100ms. If LoginLlama is unreachable the check throws an error, so catch it and let the FastAPI login go ahead. An outage then never blocks a real user.
What does LoginLlama detect on FastAPI logins?
New devices and browser fingerprints, impossible travel and login velocity, credential-stuffing bursts, and traffic from VPNs, proxies, TOR exit nodes, and high-risk IPs — each returned with a clear, human-readable reason code.
Does LoginLlama work with OAuth flows, Dependency injection, API routers?
Yes. LoginLlama runs at the login step itself, so it works alongside OAuth flows, Dependency injection, API routers and the rest of your FastAPI stack without replacing your existing authentication provider.
Other integrations
LoginLlama works with the same single API call across every stack.
FastAPI login protection
Protect FastAPI users from suspicious logins
Add LoginLlama in minutes and block risky logins in real time.