API Reference and Developer Documentation

Getting Started

To plug into the power of Kraken API you need to sign up for Kraken API services and obtain your unique API Key and API Secret. You will find those in your Account under the API Credentials section. Once you have set-up your account, you can start using Kraken API in your applications.

How to use

Kraken supports JPEG, PNG and GIF files. You can optimize your images in two ways - by providing an URL of the image you want to optimize or by uploading an image file directly to Kraken API.

The first option (image URL) is great for images that are already in production or any other place on the Internet. The second one (direct upload) is ideal for your deployment process, build script or the on-the-fly processing of your user's uploads where you don't have the images available online yet.

» Read more on Direct Upload and Image URL.

Kraken API accepts HTTPS POST requests only. Note that we offer API access through SSL secured connections, which means you have to use the HTTPS protocol in your requests. Every POST request body must include a well-formed JSON object with mandatory auth section conaining your api_key and api_secret, for example:

{
  "auth": {
    "api_key": "c1cf24cf4aa6b8833286f9393d30695a",
    "api_secret": "35c938d191f9a549924e069dc2e67d06c5643724"
  }
}
        

Depending on a choosen response option (Wait or Callback URL) in the response body you will find either the optimization ID or optimization results containing a success property, file name, original file size, kraked file size, amount of savings and optimized image URL:

» Read more on Wait option and Callback URL.

{
  "success": true,
  "file_name": "header.jpg",
  "original_size": 324520,
  "kraked_size": 165358,
  "saved_bytes": 159162,
  "kraked_url": "http://dl.kraken.io/ecdfa5c55d5668b1b5fe9e420554c4ee/header.jpg"
}
        

If no saving were realised, the API will return a "success":false property and a descriptive error message:

{
  "success": false,
  "error": "This image can not be optimized any further"
}
        

If anything goes wrong with the optimization process you will also find the "success": false property and error message in the response body:

{
  "success": false,
  "error": "Couldn't fetch this image from a given URL"
}
        

Downloading Images

Remember - never link to optimized images offered to download. You have to download them first, and then replace them in your websites or applications. Optimized images are available on our servers for one hour only.