ANKIMAGE
LAB

DEVELOPER DOCUMENTATION

IMAGE
COMPRESSION API

Upload one image and get the finished file. For requests, you need an API key from your personal account. The API does not save the original images.

Supported formats

Input: JPEG/JPG, PNG and WebP. Only static images are supported.

Result: source format (no conversion compression), JPEG, PNG, or WebP.

From your list, the API accepts JPG/JPEG, PNG, and WebP; the API rejects GIF and BMP. The browser tool accepts HEIC: the browser converts it to JPEG before sending. The server API does not decode the HEIC. AVIF and JPEG XL are also available in the browser as output formats; the API does not yet create them.

The API does not process AVIF, JPEG XL, SVG, TIFF, or any other formats. For an unsupported type, the server will return an error 415 Unsupported Media Type. Animated PNG and WebP are also rejected; GIF is not supported regardless of animation.

Single file limits: 5 MB and 20 megapixels. The server compares the MIME type and signature with the format, checks that the decoder recognizes the content, then creates a new graphic file. Source bytes are not stored or returned, so the built-in executable tail or metadata is not transferred to the result. This is a content scan and cleanup, not an antivirus scan.

Access key

Create a key in personal account. The full value is shown only once. Pass it in the Authorization header and store it on your server, not in the frontend code or public repository.

Compression request

Method — POST, body type — multipart/form-data. The file field is called image, optional field format accepts original, jpeg, png or webp. The default is original. Optional field billing_mode accepts standard or bitrix; defaults to standard.

Below is a deliberately broken demo key. This is an example of a string format, it was not issued to the user and will never pass authorization:

curl -X POST 'https://ankpicpress.com/api-compress.php' \
  -H 'Authorization: Bearer ank_test_DEMO_ONLY_NOT_A_REAL_KEY' \
  -F 'image=@photo.jpg' \
  -F 'format=webp' \
  --output photo.webp

For a real request, replace the example with a valid key and run the query from the backend application. A successful response contains a binary file and headers with the original/final size and the remainder of the limit.

Write-off for Bitrix module

Module ank.imagecompress transmits billing_mode=bitrix and unique X-ANK-Request-ID header of 64 hexadecimal characters. Repeating the same task is required to pass the same ID. The API checks the request fingerprint and returns the saved result without recalculation; the use of the same ID for a different image or format is rejected by the response 409. Repeat results are stored for up to 30 days.

In this mode, the API checks the generated file and compares its size in bytes with the sent image. Credit is deducted only if the result is valid and strictly smaller than the input file. If the result is equal to or greater than the input, the API still returns the result, but the cost of the request is zero.

The response contains headers X-ANK-Billing-Mode, X-ANK-Request-ID, X-ANK-Result-Reduced, X-ANK-Credits-Cost, X-Original-Size and X-Optimized-Size. The module does not need to confirm that the file is saved to Bitrix. If the API returned a valid reduced result, a local error saving or connecting the file does not cancel the credit charge.

In standard standard mode, the size of the result does not affect the credit charge: successful processing costs 1 credit both when compressed and when converted.

Availability check

To check the readiness of the service, use GET https://ankpicpress.com/api-health.php without an API key and file. This request checks the required API components and does not process the image, change data, or spend credits. Response 200 with {"status":"ok"} means the service is ready; 503 with {"status":"unavailable"} — that the test failed. For HEAD, the same HTTP status is returned with no response body; other methods obtain 405.

In order not to create an unnecessary load, the Bitrix module checks availability only if there are pending images and only while the API is considered unavailable: no more than three attempts per cron run. After the first response 200 verification is terminated and the image queue is started. If all attempts fail, the next check will be no earlier than the next hourly cron run. When the API is already available, you don't need to poll it again every hour.

Checking the balance of credits

To verify your API key and remaining limits, please submit GET https://ankpicpress.com/api-balance.php with the header Authorization: Bearer <API_KEY>. The query file and parameters are not required. A valid key will be answered 200 with remaining balances only: free_remaining — free units until the end of the current calendar month, paid_credits — credits purchased, total_available — their amount. The names and email addresses of the owner are not returned. The request does not start processing, does not change the balance, and does not charge credits.

curl 'https://ankpicpress.com/api-balance.php' \
  -H 'Authorization: Bearer ank_test_DEMO_ONLY_NOT_A_REAL_KEY'

The example key above is non-functional; replace it with a valid key. Invalid or revoked key gets 401, exceeding the total limit of 60 requests per minute per key — 429. The rest of the errors are returned in JSON with the field error.

Cost and limits

  • The first 500 API units every calendar month are free of charge; the balance is not transferred.
  • One successful optimization costs 1 credit — both compression without changing the format and conversion, for example, JPEG to WebP.
  • Purchased credits do not burn out. Packages are listed on page tariffs.

The first 500 optimizations of each calendar month are available free of charge. Additional credits can be purchased in your personal account; after confirming the Robokassa payment, they are automatically added to the balance.

API Errors

  • 400 — The file is missing or the query is invalid.
  • 401 — the key is missing, incorrect or revoked.
  • 402 — Not enough free units and paid credits.
  • 413 — The file or image size limit has been exceeded.
  • 415 — Unsupported/corrupted format or animation.
  • 429 — The limit of 60 requests per minute per key has been exceeded.
  • 503 — a temporary error of the service.

If an error occurs, JSON is returned with a field error.