Start with git diff to find the Markdown docs and blog posts a pull request changed. Skip files below the word minimum, reuse results for unchanged prose for up to 24 hours, and post the verdict in a PR comment so the reviewer decides whether to merge.
The Python examples call AI Checker Humanizer's REST endpoint, /detect. A verdict comes with a score from 0 to 100, and English and Portuguese can also get sentence highlights. The tool's StackShare profile lists the rest of its features.
What one check costs
Detection costs 1 credit per scored word when there's a verdict. The $10 Starter pack gives you 250,000 credits, which works out to $0.04 per 1,000 scored words. Purchased credits expire after 365 days. The MCP config README on Gitea spells out the same pricing, plus the editor setup if you later want to run these checks from an assistant on the same key.
If all 1,200 words on a page are scored, one check costs 1,200 credits, and ten fresh checks of that page cost 12,000.
Send only changed files, and only prose
Start from the diff, not the whole tree:
git diff --name-only --diff-filter=AM origin/main...HEAD -- '*.md' '*.mdx'
Before sending a file, strip what isn't prose: front matter, fenced code blocks, and import lines in MDX. Code isn't what you're asking about, and you don't want it in the word count.
Then skip files that are too short for a verdict. For a single-language file, that's English prose under 150 words, or Spanish, Portuguese or French prose under 200. If you send one anyway, /detect returns verdict: null with reason: "too_short" and charges no credits, but the request still uses one of your hourly detections. In a repo full of short changelog entries, filtering locally keeps those slots for pages that can actually get a verdict.
Use the content hash as the idempotency key
The API accepts an Idempotency-Key header on /detect. Hash the cleaned text and send that as the key, so an edit to the prose produces a new one:
import hashlib, os, requests
API = "https://aicheckerhumanizer.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['AICH_API_KEY']}"}
def check(path, text, attempt=0):
digest = hashlib.sha256(text.encode("utf-8")).hexdigest()[:40]
key = f"docs-{digest}-{attempt}"
r = requests.post(
f"{API}/detect",
headers={**HEADERS, "Idempotency-Key": key},
json={"text": text},
timeout=70,
)
if r.status_code in (409, 429, 503):
body = r.json()
return {"path": path, "error": body.get("error"), "retry_after": body.get("retryAfter", 30)}
r.raise_for_status()
return {"path": path, **r.json()}
Within 24 hours of the first request, the same key and cleaned text replay a completed result without a second charge. If that first check is still running, the API returns 409 in_progress; retry with the same key after retryAfter seconds. Editing the prose produces a new key. Once the replay window ends, the same text can be checked again, with a charge only if it gets a verdict. Replays share the hourly limit of 20,000 result and balance checks, so this isn't a reason to rerun in a loop.
Two caveats. A result is replayed even when it had no verdict, so if a page came back too_many_unscored (the one reason worth retrying), call check() again with attempt=1. The original key would only replay the result with no verdict. Separately, a saved key sent with different text within 24 hours returns 422 idempotency_conflict. Because the key is built from the text you send, that only happens if something else reuses it.
Read the verdict and any sentence flags
When there's a verdict, the response has a score, a verdict object and a sentences array. Don't read the label off verdict.label blindly: branch on verdict.basis. With dominant_language, the label is on verdict.label. With per_language, each entry in verdict.parts has its own. The label is likely_ai, mixed or likely_human.
For English and Portuguese, put the sentences marked ai next to the verdict. A docs reviewer gets more from "these four sentences in section 2" than from a page score. The other sentence colors are suspicious, human, unscored and unsupported. Spanish and French get a verdict for the whole text only, with score: null on each sentence, so report the verdict alone:
def flagged(result):
return [s["text"] for s in result.get("sentences", []) if s.get("color") == "ai"]
Each sentence also has start and end. They're UTF-16 offsets into the cleaned text you sent, with end excluded, so they match JavaScript string indexes and not Python ones. Convert them if you need to slice that text in Python. They don't point into the original Markdown file, because you removed front matter and code first. To report line numbers, keep a line map while you strip the file. If a sentence's text appears exactly once in the original, you can also look it up directly.
Warn, don't fail the build
I'd keep this job advisory. Post a comment on the pull request with the page and the verdict, plus sentence flags when there are any, and leave the merge decision to the reviewer. A few reasons:
- A
mixedverdict means the detector couldn't make a clear call on the text it scored. It doesn't mean part of the page was machine-written. - Docs lean on templates. Reference pages and step lists can read alike no matter who wrote them.
- You stripped code and front matter, so the detector saw only part of what the reader sees.
If you do want a hard gate, gate on the label rather than a score cutoff you picked yourself, and give authors a way to override it in the pull request.
Limits for a busy repo
Per hour (UTC), an account gets 2,000 detections. Across all PR jobs using the account, run at most 2 detections at once before your first credit purchase, or 10 after. The helper above returns the error field with the delay, so check it before you schedule a retry. For 429 rate_limited or 503, wait retryAfter seconds and retry. A 503 costs no credits. If you run out of retries, say "check unavailable" in the comment rather than reporting a result. For 429 api_paused, the account hit its daily limit for work that wasn't charged, so don't start new checks until midnight UTC.
Store a dedicated CI key in the repo's secrets so you can revoke it on its own if it leaks. An account can have up to five active keys, and they all draw from the same balance.
Checklist
- Send only files changed in the pull request.
- Strip front matter and code, and skip files below the word minimum (150 in English, 200 in Spanish, Portuguese or French).
- Use a hash of the cleaned text as the idempotency key.
- Use a new key for
too_many_unscored. On a429, checkerrorbefore you retry or stop for the UTC day. - Post the verdict and any sentence flags as an advisory comment.
- Keep a separate key for CI so you can revoke it alone.
Top comments (0)