← CSS to OKLCH
Your token

CSS to OKLCH API

Finding the colors in a stylesheet, converting them to oklch(), the contrast and hue-drift checks, the variables and the downloads all run free in the browser and need no API. The API is for the one metered step: send the colors (each with an id, its oklch() value, hex, alpha, how often it is used and where), and get back, as JSON, a CSS variable name and a role for each. The model never writes a color value; the page checks every name and refuses any it cannot use.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "name".

taskWhat it doesReply
nameGives each color a --color- variable name for its job (primary, text, border, danger…) and a role word, from its oklch() numbers and the properties and selectors it is used in.One JSON object

Input fields

All values are strings. task and colors are required.

FieldMeaning
task"name"
colorsJSON text: [{id, value, hex, alpha, uses, where}]. id like c3; value as oklch(L C H) or oklch(L C H / a); hex without alpha; alpha as text; uses a count; where up to four strings like background-color in .btn:hover. At most 60 colors.
takenComma-separated variable names the stylesheet already defines, or "".
colors_noteEmpty, or a sentence saying how many colors were left out.

The reply

job.output.output is text holding one JSON object (sometimes inside a ```json fence): {"tokens": [{"id", "name", "role"}]}, one entry per color sent. name starts with --color-, lowercase words joined by hyphens, at most 40 characters; role is one of brand, accent, text, text-muted, background, surface, border, success, warning, danger, info, overlay, other. Before using it, check that every id is one you sent and appears once, that names are valid, distinct, not numbered (--color-3) and not in taken; the page does all of this, keeps a numbered name for any color left out, and lists what it refused. If the balance ran low, truncated is true and the list may stop early; the page keeps every entry that arrived whole.

Worked example

Input (input.json), the button styles sample on the page:

{
  "task": "name",
  "colors": "[{\"id\":\"c1\",\"value\":\"oklch(0.278 0.03 256.848)\",\"hex\":\"#1f2937\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"color in body\"]},{\"id\":\"c2\",\"value\":\"oklch(1 0 0)\",\"hex\":\"#ffffff\",\"alpha\":\"1\",\"uses\":2,\"where\":[\"background in body\",\"color in .btn\"]},{\"id\":\"c3\",\"value\":\"oklch(0.546 0.215 262.881)\",\"hex\":\"#2563eb\",\"alpha\":\"1\",\"uses\":3,\"where\":[\"color in a\",\"background-color in .btn\",\"background in .hero\"]},{\"id\":\"c4\",\"value\":\"oklch(0.488 0.217 264.376)\",\"hex\":\"#1d4ed8\",\"alpha\":\"1\",\"uses\":2,\"where\":[\"color in #nav a:hover\",\"background-color in .btn:hover\"]},{\"id\":\"c5\",\"value\":\"oklch(0.546 0.215 262.881 / 0.6)\",\"hex\":\"#2563eb\",\"alpha\":\"0.6\",\"uses\":1,\"where\":[\"border in .btn\"]},{\"id\":\"c6\",\"value\":\"oklch(0 0 0 / 0.08)\",\"hex\":\"#000000\",\"alpha\":\"0.08\",\"uses\":1,\"where\":[\"box-shadow in .btn\"]},{\"id\":\"c7\",\"value\":\"oklch(0.714 0.019 261.325)\",\"hex\":\"#9ca3af\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"color in .btn-ghost\"]},{\"id\":\"c8\",\"value\":\"oklch(0.967 0.003 264.542)\",\"hex\":\"#f3f4f6\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"background in .btn-ghost\"]},{\"id\":\"c9\",\"value\":\"oklch(0.444 0.161 26.899)\",\"hex\":\"#991b1b\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"color in .alert-error\"]},{\"id\":\"c10\",\"value\":\"oklch(0.971 0.013 17.38)\",\"hex\":\"#fef2f2\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"background in .alert-error\"]},{\"id\":\"c11\",\"value\":\"oklch(0.577 0.215 27.325)\",\"hex\":\"#dc2626\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"border-left in .alert-error\"]},{\"id\":\"c12\",\"value\":\"oklch(0.542 0.245 293.016)\",\"hex\":\"#7c3bed\",\"alpha\":\"1\",\"uses\":1,\"where\":[\"background in .hero\"]}]",
  "taken": "",
  "colors_note": ""
}

Reply:

{"tokens": [{"id": "c1", "name": "--color-text", "role": "text"}, {"id": "c2", "name": "--color-bg", "role": "background"}, {"id": "c3", "name": "--color-primary", "role": "brand"}, {"id": "c4", "name": "--color-primary-hover", "role": "brand"}, {"id": "c5", "name": "--color-primary-border", "role": "border"}, {"id": "c6", "name": "--color-shadow", "role": "overlay"}, {"id": "c7", "name": "--color-text-muted", "role": "text-muted"}, {"id": "c8", "name": "--color-surface", "role": "surface"}, {"id": "c9", "name": "--color-danger-text", "role": "danger"}, {"id": "c10", "name": "--color-danger-bg", "role": "danger"}, {"id": "c11", "name": "--color-danger", "role": "danger"}, {"id": "c12", "name": "--color-accent", "role": "accent"}]}

On the page, a :root block of these twelve variables goes at the top of the converted CSS and every rule uses var(--color-primary), var(--color-text-muted) and so on in place of the raw colors.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://css-to-oklch.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"css-to-oklch"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "name", "colors": "[...]", "taken": "", "colors_note": ""}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="css-to-oklch:name:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: {tokens: [{id, name, role}]}
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: css-to-oklch:name:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json