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.

We love helping customers get up and running with our system!
Should you have any questions about Kraken API simply contact us at support@kraken.io

How To Use

Kraken supports JPEG, PNG, GIF (including animated GIFs) and SVG images. You can optimize your images in two ways - by providing a 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:

Authentication

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": "your-api-key",
        "api_secret": "your-api-secret"
    }
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your-api-key", "your-api-secret");
var Kraken = require("kraken");

var kraken = new Kraken({
    "api_key": "your-api-key",
    "api_secret": "your-api-secret"
});
require 'rubygems'
require 'kraken-io'

kraken = Kraken::API.new(
    :api_key => 'your-api-key',
    :api_secret => 'your-api-secret'
)
package main

import (
    "log"
    "github.com/kraken-io/kraken-go"
)

func main() {
    kr, err := kraken.New("your-api-key", "your-api-secret")

    if err != nil {
        log.Fatal(err)
    }
}
using Kraken;
using Kraken.Http;

var connection = Connection.Create("your-api-key", "you-api-secret");
from krakenio import Client

api = Client('your-api-key', 'your-api-secret')

Responses

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, original image dimensions (px) and optimized image URL:

HTTP/1.1 200 OK

{
    "success": true,
    "file_name": "header.jpg",
    "original_size": 324520,
    "kraked_size": 165358,
    "saved_bytes": 159162,
    "original_width": 640,
    "original_height": 480,
    "kraked_url": "http://dl.kraken.io/ec/df/a5/c55d5668b1b5fe9e420554c4ee/header.jpg"
}

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

HTTP/1.1 422 Unprocessable Entity

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

Read more on:

Downloading Optimized 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.