mirror of
https://github.com/hanzoai/kai.git
synced 2026-10-17 11:18:06 +00:00
Every runner printed whatever came back and exited 0, and fell back to a second raw HTTP call when the SDK import failed. Now each recipe carries expect.json, the answers a careful reader gives on its own input: a list of acceptable options for a choice, of level indices for a score, true or false for a noul. run.py and run.ts send request.json through the SDK, print every answer, and exit 1 when a checked one is wrong. A question with no obvious answer on its input is printed and not checked. Recipes 09 and 11 had no input with an obvious answer, so each state gains the one fact that decides it. The recipe READMEs describe what each recipe asks instead of capabilities it never exercised, and copy the request and checked answers from the two JSON files. Co-authored-by: Hanzo Dev <[email protected]>
Security: API Threat Scoring
Rate how threatening an IP's API traffic is and pick a firewall response.
Request (request.json)
{
"model": "kai",
"state": {
"source_ip": "45.154.255.82",
"requests_per_sec": 85,
"unique_api_keys_attempted": 14,
"failed_auth_percentage": 92.8
},
"questions": {
"threat_severity": {
"type": "score",
"instructions": "Score threat level",
"criteria": [
"normal traffic",
"minor rate spike",
"likely automated scraper",
"active credential stuffing attack"
]
},
"mitigation": {
"type": "choice",
"instructions": "Recommended firewall response",
"criteria": {
"throttle": "apply 1 req/sec rate limit",
"challenge": "issue Cloudflare challenge",
"drop": "drop packets at edge firewall"
}
}
}
}
Checked answers (expect.json)
threat_severity(score): most probable level 3active credential stuffing attackmitigation(choice): not checked, no obvious answer on this input
Run
From the repository root, after pip install -r requirements.txt and npm install:
curl -sS --fail-with-body https://api.hanzo.ai/v1/decisions \
-H "Authorization: Bearer $HANZO_API_KEY" \
-H "Content-Type: application/json" \
-d @recipes/15_security_threat_scoring/request.json
python3 recipes/15_security_threat_scoring/run.py
npx tsx recipes/15_security_threat_scoring/run.ts
run.py and run.ts print every answer and exit 1 when a checked answer is wrong.