Skip to content

Captcha Generation

The /captcha endpoint generates a CAPTCHA image. You can provide your own text or let the API generate a random one automatically.

Parameters

ParameterRequiredDescription
textNoThe captcha text. If omitted, a random string is generated
lengthNoLength of the auto-generated text (default 6)
widthNoImage width in pixels (default 300)
heightNoImage height in pixels (default 150)
noiseNoNumber of noise lines (default 5)
bgNoBackground color in hexadecimal (e.g. ffffff)
colorNoText color in hexadecimal (e.g. 000000)

Response

The endpoint returns a PNG image of the generated captcha.

Good to know

The response includes an X-Captcha-Text header containing the captcha answer, useful for server-side verification. When no text is provided, the auto-generated string avoids ambiguous characters (e.g. 0/O, 1/l).

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v4/captcha?length=8&width=400&noise=high&bg=f0f0f0"

Try It

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
length must be a numberThe length parameter is not a number
length must be between 1 and 20The length is out of range
width must be a numberThe width parameter is not a number
width must be between 100 and 800The width is out of range
height must be a numberThe height parameter is not a number
height must be between 50 and 400The height is out of range
noise must be one of: low, medium, highInvalid noise value
Invalid color (use hex like ff6600)A bg or color parameter is malformed