API=https://api.enokilabs.ai/api/v1
AUTH="Authorization: Bearer $ENOKI_API_KEY"
RUN_ID=$(curl -sf -X POST "$API/run" -H "$AUTH" -H "Content-Type: application/json" \
-d "{\"model_id\": \"$ENOKI_MODEL_ID\"}" | jq -r .run_id)
# A run takes a while; checking once a minute is plenty.
while :; do
RUN=$(curl -sf "$API/run/$RUN_ID?min_severity=high" -H "$AUTH")
[ "$(jq -r .status <<<"$RUN")" != running ] && break
sleep 60
done
# Pass only a completed run with a pass verdict and all of its results read.
jq -e '.status == "completed" and .verdict == "pass" and (.ingest_incomplete | not)' \
<<<"$RUN" > /dev/null || { jq . <<<"$RUN"; exit 1; }