Skip to content

CSS Minify API

Overview

Minifies CSS text and returns a temporary download URL and preview. Body mode runs synchronously; URL and file modes create an asynchronous job.

Endpoint

POST https://api.apidatatools.com/css-minify-api

Authentication

Include your API key in the x-api-key header.

Input modes

Set x-source-type to select an input mode:

Mode Behavior
body Send raw CSS text. Processing is synchronous. This is the default mode.
url Submit a JSON object containing a URL to a CSS file. Processing is asynchronous.
file Submit a JSON object containing a pre-uploaded file key. Processing is asynchronous.

Headers

Header names are case-insensitive. The lowercase spellings shown here are documented spellings.

Header Type Required Default / values Description
x-api-key string Yes No default API key used for authentication.
x-source-type string No Defaults to body; body, url, or file Selects the input mode.
x-tab-space string No No default; not used by this minifier Recognized header, but it does not affect CSS minification.

Accepted file extensions

For URL and file modes, the accepted extensions are txt, css, and log.

Request body

  • Body mode: Send raw CSS text, not a JSON object.
  • URL mode: Send a JSON object with a url string, for example {"url":"https://example.com/styles.css"}.
  • File mode: Send a JSON object with a file string containing the exact storage key returned by the upload workflow. Do not add a prefix to the key.

Body-size and file-size limits depend on your plan. See the tool limits.

curl examples

Body mode

curl -X POST 'https://api.apidatatools.com/css-minify-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'x-source-type: body' \
  --data-raw 'body { margin: 0; padding: 0; }'

URL mode

curl -X POST 'https://api.apidatatools.com/css-minify-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'x-source-type: url' \
  --data-raw '{"url":"https://example.com/styles.css"}'

File mode

curl -X POST 'https://api.apidatatools.com/css-minify-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'x-source-type: file' \
  --data-raw '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'

Success responses

Synchronous body mode

A successful response has HTTP 200 and includes a temporary download URL in file and the output text in preview:

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "file": "https://downloads.apidatatools.com/OUTPUT_FILE",
  "preview": "body{margin:0;padding:0}"
}

The download URL is temporary; retention depends on your plan.

Asynchronous URL and file modes

A successful job submission has HTTP 202:

{
  "status": "accepted",
  "job_id": "JOB_ID",
  "status_url": "https://api.apidatatools.com/jobs/JOB_ID",
  "request_id": "REQUEST_ID"
}

Async job status

Poll GET https://api.apidatatools.com/jobs/{job_id} with your API key. The response includes request_id, job_id, status, created_at, and updated_at.

For queued and processing jobs, the response also includes a message and retry interval:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "queued",
  "created_at": 1700000000,
  "updated_at": 1700000000,
  "message": "Your job is being processed.",
  "retry_after": 2
}

The same shape applies when status is processing.

For a successful job, result contains the worker result:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "success",
  "created_at": 1700000000,
  "updated_at": 1700000001,
  "result": {
    "status": "success",
    "file": "https://downloads.apidatatools.com/OUTPUT_FILE",
    "preview": "body{margin:0;padding:0}"
  }
}

For a failed job, error contains the code, message, and details:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "failed",
  "created_at": 1700000000,
  "updated_at": 1700000001,
  "error": {
    "code": "ERROR_CODE",
    "message": "Error message",
    "details": {
      "message": "Error message"
    }
  }
}

Example status request:

curl -X GET 'https://api.apidatatools.com/jobs/JOB_ID' \
  -H 'x-api-key: YOUR_API_KEY'

Error handling

Error responses use this envelope. Additional fields may appear in details.

{
  "status": "error",
  "error": "ERROR_CODE",
  "request_id": "REQUEST_ID",
  "details": {
    "message": "Description of the error"
  }
}

The following HTTP statuses and errors are applicable to this API:

HTTP status Error codes When it applies
400 INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, CSS_MINIFY_ERROR, CSS_INPUT_TOO_LARGE, INVALID_UTF8, EMPTY_CSS, MISSING_INPUT_FILE Invalid mode or body; or an input or minification error. CSS_INPUT_TOO_LARGE refers to the CSS processing limit.
401 UNAUTHORIZED Authentication is missing or invalid.
404 USER_NOT_FOUND, UNKNOWN_FUNCTION The authenticated user or requested API endpoint was not found.
413 PAYLOAD_TOO_LARGE, FILE_TOO_LARGE The request body or input file exceeds the applicable limit.
429 QUOTA_EXCEEDED, RATE_LIMITED The plan quota or request rate limit was exceeded.
500 PLAN_NOT_FOUND, INTERNAL_ERROR, CONFIG_ERROR, PLAN_CONFIG_ERROR A plan, processing, or async-job configuration error occurred.

URL and file mode can also return these input-validation errors:

HTTP status Error codes
400 INVALID_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION

Errors encountered while processing an accepted job, such as DOWNLOAD_FAILED or UPLOAD_FAILED, are reported as a failed job in the status response rather than as an HTTP error from the original submission.

The job-status endpoint can return HTTP 400 for INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, or DDB_ERROR. Authentication and plan-limit errors can also apply to status requests.

Notes

  • Body mode is synchronous. URL and file modes are asynchronous.
  • Request-body and file-size limits, quota, rate limits, and download retention depend on your plan. See the tool limits.
  • Download URLs are temporary.