API documentation
One endpoint. Send text as JSON, as the body itself, or in the URL; get JSON back. The base address is https://api.staging.detoxify.sh.
Prefer a machine-readable description? The OpenAPI document is at https://api.staging.detoxify.sh/openapi.json, and there is an interactive reference built from it.
Authentication
Send your API key in the Authorization header:
Authorization: Bearer dtx_…Create keys in the console. A key is shown once, when you create it; keep it on your server, since anyone holding it can spend your allowance.
With no Authorization header at all, requests are served up to 5 a day per address. A header that is present but wrong is refused with 401; it does not fall back to the anonymous allowance.
Analyze text
POST/v1/analyzealso /analyze
Scores one piece of text for toxicity and related categories. Send {"text": ...} as application/json, or send the text itself as the body: a body with any other content type, or none, is read as plain UTF-8 text.
Request body
| Field | Type | Description |
|---|---|---|
textrequired | string | The text to analyze. At most 10,000 characters. |
The body can also be the text itself. Only a body sent as application/json is read as JSON; with any other content type, or none, the whole body is the text, read as UTF-8.
Examples
As JSON
curl https://api.staging.detoxify.sh/v1/analyze \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "You are a wonderful person."}'Or the text itself, with any content type but JSON (or none)
curl https://api.staging.detoxify.sh/v1/analyze \
-H "Authorization: Bearer $YOUR_API_KEY" \
--data-binary "You are a wonderful person."Or straight from a file
curl https://api.staging.detoxify.sh/v1/analyze \
-H "Authorization: Bearer $YOUR_API_KEY" \
--data-binary @comment.txtResponse
| Field | Type | Description |
|---|---|---|
model | string | The model that produced the scores. |
scores | object | An object with the fields toxicity, severe_toxicity, obscene, threat, insult, identity_attack. |
{
"model": "original",
"scores": {
"toxicity": 0.0006,
"severe_toxicity": 0.0001,
"obscene": 0.0002,
"threat": 0.0001,
"insult": 0.0002,
"identity_attack": 0.0001
}
}A successful call counts as one analysis. The same text always returns the same scores.
Errors
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_request | The request body or parameters are not valid. |
| 401 | unauthorized | The API key or token sent with the request is not valid. |
| 402 | account_suspended | The account is suspended until its unpaid usage is paid. See help_url to pay it. |
| 413 | payload_too_large | The request body is too large. |
| 429 | quota_exceeded | The free plan's monthly allowance is used up. See help_url to subscribe for more. |
| 429 | anonymous_quota_exceeded | Requests without an API key are limited per day. See help_url to sign up for more. |
| 429 | rate_limited | Too many requests in a short time. Wait for Retry-After seconds and retry. |
| 500 | internal_error | An unexpected error occurred. |
| 502 | analysis_failed | The analysis engine failed on this request. Retrying may succeed. |
| 503 | auth_unavailable | The credential could not be checked right now. It may be valid; retry without discarding it. |
| 503 | metering_unavailable | Usage could not be recorded right now, so the request was not served. Retry. |
| 503 | overloaded | The service is at capacity or still starting. Retry shortly. |
| 504 | analysis_timeout | The analysis did not complete in time. Retrying may succeed. |
Analyze text in the URL
GET/v1/analyzealso /analyze
The same analysis, with the text in the query string: GET /v1/analyze?text=.... Handy from a browser or a one-line script. Addresses are limited in length (about 16 KB at our edge, after URL encoding), and proxies and browsers may record them, so send long or private text with POST instead.
Query parameters
| Parameter | Type | Description |
|---|---|---|
textrequired | string | The text to analyze. At most 10,000 characters, before URL encoding. |
Examples
With curl, which encodes the text for you
curl -G https://api.staging.detoxify.sh/v1/analyze \
-H "Authorization: Bearer $YOUR_API_KEY" \
--data-urlencode "text=You are a wonderful person."Or open it in a browser, with no key, within the anonymous allowance
https://api.staging.detoxify.sh/v1/analyze?text=You%20are%20a%20wonderful%20person.Response
| Field | Type | Description |
|---|---|---|
model | string | The model that produced the scores. |
scores | object | An object with the fields toxicity, severe_toxicity, obscene, threat, insult, identity_attack. |
{
"model": "original",
"scores": {
"toxicity": 0.0006,
"severe_toxicity": 0.0001,
"obscene": 0.0002,
"threat": 0.0001,
"insult": 0.0002,
"identity_attack": 0.0001
}
}A successful call counts as one analysis. The same text always returns the same scores.
Errors
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_request | The request body or parameters are not valid. |
| 401 | unauthorized | The API key or token sent with the request is not valid. |
| 402 | account_suspended | The account is suspended until its unpaid usage is paid. See help_url to pay it. |
| 429 | quota_exceeded | The free plan's monthly allowance is used up. See help_url to subscribe for more. |
| 429 | anonymous_quota_exceeded | Requests without an API key are limited per day. See help_url to sign up for more. |
| 429 | rate_limited | Too many requests in a short time. Wait for Retry-After seconds and retry. |
| 500 | internal_error | An unexpected error occurred. |
| 502 | analysis_failed | The analysis engine failed on this request. Retrying may succeed. |
| 503 | auth_unavailable | The credential could not be checked right now. It may be valid; retry without discarding it. |
| 503 | metering_unavailable | Usage could not be recorded right now, so the request was not served. Retry. |
| 503 | overloaded | The service is at capacity or still starting. Retry shortly. |
| 504 | analysis_timeout | The analysis did not complete in time. Retrying may succeed. |
Error format
Every error has the same shape. Branch on code, which is stable; the message is for people and may change.
{
"error": {
"code": "invalid_request",
"details": [
{
"message": "must contain non-whitespace text",
"path": "text"
}
],
"message": "The request body or parameters are not valid."
}
}A 429 for a short-term rate limit carries a Retry-After header in seconds. quota_exceeded, account_suspended and anonymous_quota_exceeded carry a help_url: where to sign up, subscribe or pay.
Reading the scores
Each score is the model's estimate, from 0 to 1, that the text has that quality. They are independent of one another and do not sum to 1. There is no built-in threshold: what counts as too toxic depends on your community, so pick cut-offs by looking at scores for real examples of your own content.
The model can be wrong, and is known to be more likely to flag text that merely mentions some identities. Use scores to prioritise human review, not to replace it.