Skip to content

HTTP API

Color checks. Simple JSON.

Check a text pair or find a foreground that works across several surfaces. No API key required.

Your first request

Call the API from a terminal or your server. This example checks black text on white and returns a ratio of 21:1.

Terminal
curl --get 'https://colorbox.io/api/contrast' \
  --data-urlencode 'foreground=000000' \
  --data-urlencode 'background=ffffff'

GET /api/contrast

Both parameters are required. Colors accept six-digit hex with or without #, or opaque, in-gamut OKLCH literals. URL-encode #, spaces, and parentheses; curl --data-urlencode handles this for you.

Pass/fail uses the unrounded ratio with a fixed minimum of 4.5:1. This checks one pair of colors, not the accessibility of an entire page.

foreground
Text color, such as 000000 or oklch(0.3 0 0).
background
One background color, such as ffffff.
Response · 200
{
  "foreground": "000000",
  "background": "ffffff",
  "ratio": 21,
  "minimum": 4.5,
  "passes": true
}

GET /api/repair-text-contrast

Suggest a text color that meets 4.5:1 on one to eight fixed backgrounds. The backgrounds stay unchanged. This is a bounded search for a passing color, not a guarantee of the smallest possible change.

foreground
Required. The current text color.
backgrounds
Required. One to eight comma-separated colors.
token
Optional. A CSS variable matching -- followed by a letter and up to 63 letters, digits, underscores, or hyphens.
verify
Optional. Set to 1 to include a relative verificationUrl for each surface.
Terminal
curl --get 'https://colorbox.io/api/repair-text-contrast' \
  --data-urlencode 'foreground=666666' \
  --data-urlencode 'backgrounds=0f0f0f,242424' \
  --data-urlencode 'token=--muted-foreground' \
  --data-urlencode 'verify=1'

Handle the result

A valid repair request returns HTTP 200 with a status. Always inspect that status before applying a suggestion.

unchanged
The original foreground already passes every supplied background.
repaired
suggestedForeground contains a passing candidate. checks includes before/after ratios for each background.
blocked
The search found no candidate. suggestedForeground and after ratios are null; no declaration is returned.
declaration
Included when a token was supplied and a passing foreground exists.

Errors and integration notes

HTTP 400 returns an error string for invalid input. HTTP 405 means the method is unsupported; use GET. Treat HTTP 429 as a signal to back off, honor Retry-After when supplied, and avoid repeated parallel retries.

These routes do not enable cross-origin browser requests. Use your own server to call them from an app hosted on another origin. Palette generation is available through MCP; there is no documented REST palette-generation endpoint.

Transparent colors, dynamic CSS expressions, and out-of-gamut colors are unsupported. Check every relevant background and mode in your rendered interface.