Integrations
Python
Classify a request from Python with the Vouched KYA REST API.
Prerequisites
- Python 3. The example uses the standard library.
- A Vouched KYA API key with read access to your project.
Quickstart
Create the script
Save the following as detect.py. The script reads CHECKPOINT_API_KEY from your environment or prompts for it without showing the key as you type.
import json
import os
from getpass import getpass
from urllib.request import Request, urlopen
api_key = os.environ.get("CHECKPOINT_API_KEY") or getpass("Vouched KYA API key: ")
payload = {
"userAgent": (
"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); "
"compatible; ChatGPT-User/1.0; +https://openai.com/bot"
)
}
request = Request(
"https://kya.vouched.id/api/v1/detect",
data=json.dumps(payload).encode("utf-8"),
headers={"Content-Type": "application/json", "X-API-Key": api_key},
method="POST",
)
with urlopen(request, timeout=10) as response:
result = json.load(response)["data"]["result"]
print(result["detectionClass"]["type"])Run the detection
python3 detect.pyThe script prints the detection class, such as AiAgent. In your web app, call the API from your server and replace the sample userAgent with the incoming request's User-Agent value. Keep your API key on the server.
See the Detect API reference for additional request fields and the full response.