Detect AI-generated text via a simple REST API
If the space owner has set an API_KEY environment variable, include it with every request:
| Method | Example |
|---|---|
| Header | X-API-Key: your-key-here |
| Query param | ?api_key=your-key-here |
API_KEY is configured, all requests are accepted without authentication.When running on HuggingFace Spaces:
https://<owner>-<space-name>.hf.space
Locally:
http://localhost:7860
POST/api/v1/detect
Analyze a text string for AI-generated content.
| Field | Type | Description | |
|---|---|---|---|
text | string | required | The text to analyze (min 10 chars) |
curl -X POST https://<space-url>/api/v1/detect \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{"text": "Paste the text you want to analyze here."}'
{
"status": "success",
"ai_score": 0.87,
"ai_score_percent": "87.0%",
"confidence": "high",
"verdict": "AI-generated",
"detector_results": {
"tmr_detector": { "score": 0.91, "confidence": "very_high", ... },
"pattern": { "score": 0.12, "confidence": "low", ... }
},
"text_stats": { "word_count": 120, "char_count": 680, ... }
}
POST/api/v1/detect/file
Upload a file (PDF, DOCX, or TXT) and analyze its content.
| Field | Type | Description | |
|---|---|---|---|
file | file | required | PDF, DOCX, or TXT (max 50 MB) |
curl -X POST https://<space-url>/api/v1/detect/file \ -H "X-API-Key: your-key" \ -F "file=@essay.pdf"
Same shape as /api/v1/detect plus a filename field.
GET/api/v1/status
Returns the current detector configuration and API status. No auth required.
{
"status": "ok",
"timestamp": "2025-01-01T00:00:00Z",
"api_version": "1.0",
"auth_required": false,
"enabled_detectors": ["tmr_detector", "pattern"],
"aggregation_method": "weighted_average"
}
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad request (missing/invalid input) |
| 401 | Missing API key |
| 403 | Invalid API key |
| 500 | Internal server error |