LangChain integration

Use langchain-aicheckerhumanizer to check drafts for AI writing and rewrite them. Call the tools directly from Python or add them to a LangChain agent.

Install

Shell
pip install langchain-aicheckerhumanizer
export AICHECKERHUMANIZER_API_KEY="ach_live_..."

The package works with LangChain v1 on Python 3.10 or later. It calls the AI detection API and the AI humanizer API with your key, so you need one: create it on your account page and put it in AICHECKERHUMANIZER_API_KEY.

The source is MIT-licensed and on GitHub.

Call the tools

AICheckerHumanizerToolkit returns three tools that share one API client. You can also use them on their own as AICheckerHumanizerDetectTool, AICheckerHumanizerHumanizeTool and AICheckerHumanizerGetResultTool.

Python
from pathlib import Path

from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit

toolkit = AICheckerHumanizerToolkit()
detect, humanize, get_result = toolkit.get_tools()
text = Path("draft.txt").read_text(encoding="utf-8")

print(detect.invoke({"text": text}))
rewrite = humanize.invoke({"text": text, "mode": "standard", "strength": "medium"})
print(rewrite)
Tools
Tool nameInputReturns
ai_checker_humanizer_detecttext, up to 10,000 words; optional idempotency_keyJSON with a 0–100 score and a verdict. Without a verdict, score is null and reason says why. English and Portuguese results can include sentence scores.
ai_checker_humanizer_humanizetext, up to 3,000 words; optional mode, strength and idempotency_keyThe task as JSON. When it ends as completed or partial, output is your text with the rewritten parts in place; unchanged returns your text as it was; failed and cancelled have no output.
ai_checker_humanizer_get_resulttask_idFetches the current task status and any available output as JSON.

All three tools support ainvoke and return a JSON string. The API documentation explains the response fields.

Async, using detect and text from above
import asyncio


async def main() -> None:
    print(await detect.ainvoke({"text": text}))


asyncio.run(main())
Detection output (excerpt: one sentence shown)
{
  "score": 100,
  "verdict": { "basis": "dominant_language", "language": "en", "words": 152, "label": "likely_ai" },
  "reason": null,
  "sentences": [
    {
      "text": "Meetings should have a clear purpose, especially when team members are spread across time zones.",
      "language": "en", "words": 15, "score": 100, "color": "ai"
    }
  ],
  "creditsCharged": 152,
  "creditsRemaining": 4848
}

Use it in an agent

Install langchain and the package for your chat model, and pick a model that supports tool calls. Set MODEL to its provider:model name and set that provider's credentials. The example asks the model to check the draft for AI writing and then rewrite it. The model chooses which tools to call.

Python
import os
from pathlib import Path

from langchain.agents import create_agent
from langchain.chat_models import init_chat_model

from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit

toolkit = AICheckerHumanizerToolkit()
agent = create_agent(init_chat_model(os.environ["MODEL"]), tools=toolkit.get_tools())
text = Path("draft.txt").read_text(encoding="utf-8")

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "Check the draft for AI writing, then rewrite it. Return the detection verdict and the rewritten text.\n\n" + text,
    }]
})
print(result["messages"][-1].content)

Rewrite options

Humanize options
OptionValuesDefault
modestandard, academic, casual, concisestandard
strengthlight, medium, heavymedium

For English drafts that get a detector check, mode sets the style and strength has no effect. The humanize section of the API docs lists which drafts get the check and what happens when a rewrite doesn't pass it.

Long rewrites

After submission, the rewrite tool polls for up to 120 seconds by default; set max_wait_seconds on the humanize tool to change the limit. If the task is still pending, pass its taskId as task_id to ai_checker_humanizer_get_result. Stop polling at completed, partial, unchanged, failed or cancelled, or if you get result_expired. Results are available for about 70 minutes after submission.

Python
import json
import time

task = json.loads(rewrite)  # rewrite from the example above
if "taskId" in task:
    time.sleep(task.get("retryAfter") or 3)
    print(get_result.invoke({"task_id": task["taskId"]}))
else:
    print(task["error"], task["message"])

Credits and retries

  • Detection costs 1 credit per scored word, and only when there's a verdict.
  • Rewriting costs 5 credits per original word in each chunk that was rewritten. A chunk is a paragraph or part of a long one, and chunks under 10 words count as 10.
  • Pass the same idempotency_key with the same text and options within 24 hours and a finished check or accepted rewrite isn't charged again.

Prices are on the pricing page. The tools don't retry on their own.

Errors

By default, errors return JSON with error and message, plus httpStatus if the server replied. During polling, network errors, HTTP 429, HTTP 5xx and malformed success responses return error, taskId and the last known status. Set handle_tool_error=False to raise a ToolException for other API and network errors.

Besides the API's own codes, the package can return timeout, request_error, invalid_response and http_error when the request or the response didn't get through cleanly.

If an error includes idempotencyKey, send the request again with it as idempotency_key and the same text and options. What a retry returns, and the API's error codes, are in the idempotency and errors sections of the API reference.