API Documentation

REST API documentation


The authentication is required on all endpoints. To authenticate using your API key you need to specify a header named X-API-KEY and the api key as value.


Method Description


This method is used to send image for optimization and accepts the parameters as descirbed bellow.

Accepted HTTP parameters: (Note: json encoded parameters aren’t supported at this time)

Parameter Possible Values
compression intelligent, ultra or lossless (default: intelligent)
type url, urls, file, files. file/s are local paths
webp 1 or 0 (default: 0)
cmyktorgb 1 or 0 (default: 1)
keep_exif 1 or 0 (default: 0)
max_height 0 or N (default: 0 – disabled)
max_width 0 or N (default: 0 – disabled)
url Required if type is url
urlN Required if type is urls. Can be url1,url2 up to 5.
file Required if type is file
fileN Required if type is files. Can be file1,file2 up to 5.
callback_url If specified the request results will be send to this url using HTTP POST

Example Response:

    "status": "processing",
    "code": 202,
    "process_id": "a4f1d060-c292-11e8-b3e3-edd916bf7758"

The process_id identifies the job that is currently processing on the server and can be used to retrieve the final results.



This method is used to retrieve the results for specific process_id that you receive in /v1/optimize call.

To retrieve the results, send a POST to the results url specifying the process_id as follows:


Accepted HTTP parameters: (Note: json encoded parameters aren’t supported at this time)

Parameter Possible Values
timeout Numeric value in seconds. Defaults to 120.

Example Response (webp property is null when webp parameter is 0)

      "name":"John Doe",
      "email":"[email protected]",

This endpoint is used to query the api user details, such as name, email and remaining tokens.


Example Response:

    "status": "ok",
    "code": 200,
    "result": {
        "name": "John Doe",
        "email": "[email protected]",
        "tokens": 42

Return codes

The API will always return status 200 for any call, but the result contains “code” property which gives you the exact code.

Code Endpoints Notes
200 /users/info, /register, /optimize/uuid/result /
202 /optimize The /optimize endpoint returns 202 when job is successfully queued.
400 /register, /optimize, /optimize/uuid/result When there is validation error. Such as wrong parameter value, etc.
401 /users/info, /optimize/uuid/result When data is accessed that does not belong to the provided api key.
404 AUTH, /optimize/uuid/result /optimize/uuid/result returns 404 when job is not found. AUTH guard returns 404 when the api key not found in the system.
455 /optimize When the account doesn’t have enough api tokens to proceed with optimization.
500 /register, /optimize/uuid/result, /optimize Internal server error, should be reported to [email protected].
504 /optimize/uuid/result Once the result endpoint timesout – when provided timeout parameter seconds are reached.

Rate Limiting

The following table outlines the rate limit set on each endpoint. We rate limit endpoints in order to prevent attacks. The rate limit rules are within normal boundaries, so nothing to worry. If you are not abuser you will not be rate limited.

Endpoint Limits
https://api.megaoptim.com/v1/optimize 120 requests per 1 minute
https://api.megaoptim.com/v1/optimize/process_id/result 120 requests per 1 minute
https://api.megaoptim.com/v1/users/info 120 requests per 1 minute