TextSight SDK

How to detect AI-generated text in Python

This guide shows how to check text for ChatGPT, Claude or Gemini writing from a Python script, using the free textsight package and the TextSight AI content detector.

1. Install the package

pip install textsight

It has no dependencies and works on Python 3.8 and newer.

2. Add your API key

# macOS / Linux
export TEXTSIGHT_API_KEY=sk_live_...
# Windows
set TEXTSIGHT_API_KEY=sk_live_...

Get a key at app.textsight.ai/signup. Keep it on your server and out of source control.

3. Check a piece of text

from textsight import TextSight

ts = TextSight()                     # reads TEXTSIGHT_API_KEY
r = ts.detect(open("essay.txt").read())

print(r["verdict"])                  # "human", "mixed" or "ai"
print(r["humanization_score"])       # 0-100, higher = more human
for s in r["sentences"]:
    if s["label"] == "ai":
        print(round(s["score"], 2), s["text"])

4. Check many files at once

from pathlib import Path
from textsight import TextSight, RateLimitError

ts = TextSight()
for path in Path("submissions").glob("*.txt"):
    try:
        r = ts.score(path.read_text())   # lighter call, no sentence list
        print(f"{path.name}: {r['humanization_score']}")
    except RateLimitError:
        print("Rate limit hit, slow down")

The client retries rate limits and short outages on its own before raising an error.

5. Humanize text that was flagged

r = ts.rewrite(text, tone="academic", strength=3, preserve=["Smith (2021)"])
print(r["rewritten"])

Tones: conversational, professional, academic, blog and email. Strength runs from 1 (light edit) to 5 (heavy rewrite). Items in preserve stay unchanged. More on this in the AI humanizer API guide.

Reading the score responsibly

No AI detector is right every time. Short texts and writing by non-native English speakers are flagged more often. Treat the score as a signal to look closer, not as proof. TextSight explains why in Can AI detectors be wrong? and How AI detectors work.

FAQ

How do I detect AI-generated text in Python?

Install the textsight package with pip install textsight, set your TEXTSIGHT_API_KEY, then call TextSight().detect(text). It returns a verdict, a 0-100 humanization score and per-sentence scores.

Can Python detect ChatGPT text offline?

Not reliably. Accurate detection needs a trained model, so the textsight package sends text to the TextSight API and returns the result.

Is there a free AI detection API for Python?

The textsight library is free and open source. The API itself needs a TextSight plan with API access; for occasional checks the browser detector at textsight.ai is free.