Runnable examples for the TextSight v2 API — AI content detection and rewriting — in Python, JavaScript, PHP and curl.
Every example here has been executed against the live API. No pseudocode, no dependencies beyond each language's standard library, and no framework to learn — each client is a single file you can copy into your own project.
git clone https://github.com/textsight/textsight-api-examples
cd textsight-api-examples
export TEXTSIGHT_API_KEY=sk_live_... # from https://app.textsight.ai/api-keys
python3 python/detect.py # Python 3
node javascript/detect.mjs # Node 18+
php php/detect.php # PHP 8+
./curl/examples.sh detect # curlAll four print the same thing. Official reference: textsight.ai/api-docs.html.
ai_probability is a fraction. The other scores are percentages.
| Field | Range |
|---|---|
ai_probability |
0.0 – 1.0 |
humanization_score |
0 – 100 |
confidence |
0 – 100 |
sentences[].score |
0.0 – 1.0 |
0.75 means 75% likely AI. Showing it to a user as "0.75% AI" — or multiplying
the wrong field by 100 — is the single easiest mistake to make against this API.
Every example here converts explicitly and prints the raw value alongside.
Create one at app.textsight.ai/api-keys. Keys are shown once, at creation. Both auth forms work:
Authorization: Bearer sk_live_... # documented form, used by these examples
x-api-key: sk_live_... # also accepted
⚠️ TextSight keys start withsk_live_, the same prefix Stripe uses for secret keys. Label them carefully if you handle both — they are indistinguishable at a glance. GitHub's secret scanner reads this shape as a Stripe key and will block a push containing one, including a fake one in a test fixture.
Keep keys server-side. Never ship one in client-side JavaScript.
Base URL: https://api.textsight.ai
| Method | Path | What it does |
|---|---|---|
POST |
/v2/detect |
Full analysis: score, verdict, reasoning, per-sentence breakdown |
POST |
/v2/score |
The same scores without sentences or reasoning — smaller response |
POST |
/v2/rewrite |
Rewrite the text, returning it plus the score of the rewrite |
Bulk scanning (/v2/bulk) and job polling (/v2/jobs/<id>) are documented as
planned and currently return 404. Do not build against them yet.
{ "text": "..." }Response:
{
"humanization_score": 25,
"ai_probability": 0.75,
"verdict": "ai",
"confidence": 85,
"reasoning": "Analysis complete.",
"sentences": [
{ "text": "...", "score": 0.75, "label": "ai" }
],
"model": "gpu",
"request_id": "req_5d73f8b7-f57a-464d-b690-8022a47558ea"
}verdictishuman,mixedorai.mixedis an inconclusive result, not a weak accusation. Short or ambiguous input lands here with lowconfidence. Treat it as "the detector could not commit" and present it that way to users.request_ididentifies the call. Quote it in any support request.- There is no minimum text length, but very short input produces a
low-confidence
mixed— as it should.
Same request. Returns humanization_score, ai_probability, confidence and
request_id — no sentences, no reasoning. Use it when you only need the
number.
{ "text": "..." }Response:
{
"rewritten": "...",
"humanization_score": 12,
"ai_probability": 0.88,
"score_reliable": true,
"request_id": "req_2d627b17-5524-4ab7-9363-e82a443a546d"
}Two things to get right:
- The scores describe the rewrite, not your input. There is no
before-and-after in one call. To show a genuine comparison, call
/v2/detecton the input first — which is exactly whatrewrite.py,rewrite.mjsandrewrite.phpdo here. score_reliable: falsemeans do not present those scores as fact. Render them as unavailable rather than showing a number the API has told you not to trust.
{ "error": { "code": "unauthorized", "message": "Invalid API key." } }The error object is nested — error.code and error.message, not a
top-level error string.
| Status | code |
Meaning |
|---|---|---|
400 |
invalid_request |
text missing or not a non-empty string |
401 |
unauthorized |
Key missing or rejected |
429 |
— | Rate limited |
Rate limits and quotas follow your plan tier; see textsight.ai/pricing.
python/ textsight.py + detect.py, score.py, rewrite.py stdlib only
javascript/ textsight.mjs + detect.mjs, rewrite.mjs Node 18+, built-in fetch
php/ textsight.php + detect.php, rewrite.php ext-curl, ext-json
curl/ examples.sh all three endpoints as raw curl
Each language has a small client file and one script per endpoint. CI checks that all three compile and that they fail identically when the key is missing or rejected.
It rewrites text for readability and reports the detector's score honestly.
It is not an "undetectable" tool. No rewriter can guarantee a given detector's verdict — detectors change without notice, and none of these tools have access to the target model. Evading detection in an academic submission is misconduct at most institutions regardless of which tool produced the text.
If you want to know how reliable AI detection actually is, we publish our own detector's false-positive rate — including the results that do not flatter us — at textsight/ai-detector-benchmarks.
MIT. Copy these into your own project, commercial or otherwise.
Bug reports and examples in other languages are welcome. If a snippet here does not run, that is a bug — please open an issue.