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

FieldTypeDescription
textrequiredstringThe 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.txt

Response

FieldTypeDescription
modelstringThe model that produced the scores.
scoresobjectAn 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

StatusCodeMeaning
400invalid_requestThe request body or parameters are not valid.
401unauthorizedThe API key or token sent with the request is not valid.
402account_suspendedThe account is suspended until its unpaid usage is paid. See help_url to pay it.
413payload_too_largeThe request body is too large.
429quota_exceededThe free plan's monthly allowance is used up. See help_url to subscribe for more.
429anonymous_quota_exceededRequests without an API key are limited per day. See help_url to sign up for more.
429rate_limitedToo many requests in a short time. Wait for Retry-After seconds and retry.
500internal_errorAn unexpected error occurred.
502analysis_failedThe analysis engine failed on this request. Retrying may succeed.
503auth_unavailableThe credential could not be checked right now. It may be valid; retry without discarding it.
503metering_unavailableUsage could not be recorded right now, so the request was not served. Retry.
503overloadedThe service is at capacity or still starting. Retry shortly.
504analysis_timeoutThe 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

ParameterTypeDescription
textrequiredstringThe 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

FieldTypeDescription
modelstringThe model that produced the scores.
scoresobjectAn 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

StatusCodeMeaning
400invalid_requestThe request body or parameters are not valid.
401unauthorizedThe API key or token sent with the request is not valid.
402account_suspendedThe account is suspended until its unpaid usage is paid. See help_url to pay it.
429quota_exceededThe free plan's monthly allowance is used up. See help_url to subscribe for more.
429anonymous_quota_exceededRequests without an API key are limited per day. See help_url to sign up for more.
429rate_limitedToo many requests in a short time. Wait for Retry-After seconds and retry.
500internal_errorAn unexpected error occurred.
502analysis_failedThe analysis engine failed on this request. Retrying may succeed.
503auth_unavailableThe credential could not be checked right now. It may be valid; retry without discarding it.
503metering_unavailableUsage could not be recorded right now, so the request was not served. Retry.
503overloadedThe service is at capacity or still starting. Retry shortly.
504analysis_timeoutThe 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.