API Reference and Developer Documentation

Amazon S3 Integration

Kraken API allows you to store optimized images directly in your S3 bucket. With just a few additional parameters your optimized images will be pushed to S3 in no time.

If you're using a custom bucket policy and restricting actions that could be performed on the bucket's objects be sure to add "s3:PutObjectAcl" in the actions parameter in your bucket policy.
Mandatory Parameters:
keyYour unique Amazon "Access Key ID"
secretYour unique Amazon "Secret Access Key"
bucketName of a destination bucket on your Amazon S3 account
regionName of the region your S3 bucket is located in. This field is mandatory if the region is different from the default one (us-east-1). The full list of S3 regions can be found here.
Optional Parameters:
pathDestination path in your S3 bucket (e.g. "images/layout/header.jpg"). Defaults to root "/"
aclPermissions of a destination object. This can be "public_read" or "private". Defaults to "public_read"
metadataS3 Metadata you would like to assign to your S3 object (optimized image)
headersAny custom headers you would like to pass along with your S3 object (optimized image). See example below for proper formatting
tagsAny custom tags you would like to assign to your S3 object. Up to ten tags can be applied per object. See below JSON example.

The above parameters must be passed in a s3_store object:

{
    "s3_store": {
        "key": "your-amazon-access-key",
        "secret": "your-amazon-secret-key",
        "bucket": "destination-bucket",
        "region": "your-s3-bucket-location"
    }
}

Below you can find an example of a complete JSON request that uses s3_store to push optimized image into your S3 bucket. We will use the url option to feed the API with the URL of the image to be optimized. Note: You must replace the example credentials given below with your own.

{
    "auth": {
        "api_key": "your-api-key",
        "api_secret": "your-api-secret"
    },
    "s3_store": {
        "key": "AKIAO4AD5J4F1NA33Q12",
        "secret": "AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe",
        "bucket": "assets",
        "path": "images/layout/header.png",
        "region": "ap-southwest-2",
        "headers": {
            "Cache-Control": "max-age=2592000000",
            "Expires": "2026-04-04T12:06:11+00:00"
        },
        "tags": {
            "tag1": "my-first-tag",
            "tag2": "my-second-tag"
        }
    },
    "url": "http://awesome-website.com/images/header.png",
    "wait": true,
    "lossy": true
}
<?php

require_once("Kraken.php");

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

$params = array(
    "url" => "http://awesome-website.com/images/header.png",
    "wait" => true,
    "lossy" => true,
    "s3_store" => array(
        "key" => "AKIAO4AD5J4F1NA33Q12",
        "secret" => "AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe",
        "bucket" => "assets",
        "path" => "images/layout/header.png",
        "region" => "ap-southwest-2",
        "headers" => array(
            "Cache-Control" => "max-age=2592000000",
            "Expires" => "2026-04-04T12:06:11+00:00"
        )
    )
);

$data = $kraken->url($params);

if ($data["success"]) {
    echo "Success. Optimized image URL: " . $data["kraked_url"];
} else {
    echo "Fail. Error message: " . $data["message"];
}
var Kraken = require("kraken");

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

var params = {
    "url": "http://awesome-website.com/images/header.png",
    "wait": true,
    "s3_store": {
        "key": "AKIAO4AD5J4F1NA33Q12",
        "secret": "AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe",
        "bucket": "assets",
        "path": "images/layout/header.png",
        "region": "ap-southwest-2",
        "headers": {
            "Cache-Control": "max-age=2592000000",
            "Expires": "2026-04-04T12:06:11+00:00"
        }
    }
};

kraken.url(params, function (status) {
    if (status.success) {
        console.log("Success. Optimized image URL: %s", status.kraked_url);
    } else {
        console.log("Fail. Error message: %s", status.message);
    }
});
require 'rubygems'
require 'kraken-io'

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

params = {
    :wait => true,
    :s3_store => {
        'key' => 'AKIAO4AD5J4F1NA33Q12',
        'secret' => 'AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe',
        'bucket' => 'assets',
        'path' => 'images/layout/header.png',
        'region' => 'ap-southwest-2',
        'headers' => {
            'Cache-Control': 'max-age=2592000000',
            'Expires': '2026-04-04T12:06:11+00:00'
        }
    }
}

data = kraken.url('http://awesome-website.com/images/header.png', params)

if data.success
    puts 'Success! Optimized image URL: ' + data.kraked_url
else
    puts 'Fail. Error message: ' + data.message
end
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)
    }

    params := map[string]interface {} {
        "wait": true,
        "url": "http://awesome-website.com/images/header.png",
        "s3_store": map[string]interface {} {
            "key": "AKIAO4AD5J4F1NA33Q12",
            "secret": "AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe",
            "bucket": "assets",
            "path": "images/layout/header.png",
            "region": "ap-southwest-2",
            "headers": map[string]interface {} {
                "Cache-Control": "max-age=2592000000",
                "Expires": "2026-04-04T12:06:11+00:00"
            }
        }
    }

    data, err := kr.URL(params)

    if err != nil {
        log.Fatal(err)
    }

    if data["success"] != true {
        log.Println("Failed, error message ", data["message"])
    } else {
        log.Println("Success, Optimized image URL: ", data["kraked_url"])
    }
}
using Kraken;
using Kraken.Http;
using Kraken.Model.S3;
using OptimizeWaitRequest = Kraken.Model.S3.OptimizeWaitRequest;

var client = Connection.Create("your-api-key", "your-api-secret");

var response = client.OptimizeWait(new OptimizeWaitRequest(
    new Uri("http://image-url.com/file.jpg"), "account", "key", "container", "region")
    {
        Lossy = true
    });

if (response.Result.StatusCode == HttpStatusCode.OK) {
    var url = response.Result.Body.KrakedUrl;
}
from krakenio import Client

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

data = {
    'wait': True,
    'lossy': True,
    's3_store': {
        'key': 'AKIAO4AD5J4F1NA33Q12',
        'secret': 'AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe',
        'bucket': 'assets',
        'path': 'images/layout/header.png',
        'region': 'ap-southwest-2',
        'headers': {
            'Cache-Control': 'max-age=2592000000',
            'Expires': '2026-04-04T12:06:11+00:00'
        }
    }
}

result = api.url('http://awesome-website.com/images/header.png', data);

if result.get('success'):
    print result.get('kraked_url')
else:
    print result.get('message')

The optimization results will contain a kraked_url property which points directly to the optimized file location in your Amazon S3 bucket, for example:

http://s3.amazonaws.com/assets/images/layout/header.jpg