Rest Api Documentation

On to the API and the true power of Tweekit. The API currently consists of three calls, that’s it. Easy, Simple, Powerful just as promised.

It’s as simple as:

  • Upload your file
  • Transform and preview your changes
  • Download the transformed file

Read on for more, just remember all calls require authorization which can be accomplished by one of the following:

  • An "Authorization" header with "Bearer <token>" as the value. The bearer token can be acquired from logging in with the auth.cpucoin.io authorization server.
  • An "ApiKey" and "ApiSecret" pair of headers with the assigned APIKey and APISecret values received from the API Key generator REST API call.

Failure to include one of these sets of information will cause the request to return a 401 (unauthorized) status code and the request will fail.

/api/image/upload POST

Upload, the first step for any file transformation, you send the file to be transformed to this endpoint. Multiple examples of how to accomplish this are in the examples to the right.

When you successfully upload your file, and we return you a document ID, that has a 20-minute lifespan. One file per upload, one DocId per file.

The details:

Upload expects a multipart form in the usual format for file uploads. The backend code is also compatible with plUpload, but only in single file mode - multiple files and folders aren't supported. Uploaded documents expire after 20 minutes. At which point they are deleted permanently.

The request returns a DocId in both the body (as a JSON object with a DocId member) and in the response header under "X-TweekIT-DocId". These ID's are required to process the uploaded file.


const fetch = require('node-fetch'); const fs = require('fs'); const FormData = require('form-data'); const headers = { "apikey": "{Example Key}", "apisecret": "{Example Secret}" }; async function doUpload(name, path){ const url = 'https://www.tweekit.io/tweekit/api/image/upload'; const formData = new FormData(); formData.append("name", name); formData.append("file", fs.createReadStream(path)); const options = { method: 'POST', headers: headers, body: formData }; const response = await fetch(url, options); docID = response.headers.get('x-tweekit-docid'); return response; } const uploadeRes = await doUpload({Image Name}, {path to image file}) console.log(uploadeRes)


{ "docId":"81736373272E49248519DE8C203A6001" }

/api/image/preview POST or GET

Returns a preview of the uploaded document, using the CGN to perform the transformation of the file. This is the heart of Tweekit where the magic happens.

  • Want to scale the image, this is where you do it.
  • Want to crop the image, this is where you do it.
  • Want to transform a single page of a PDF to a JPG, you guessed it, this is where you do it.

When you successfully upload your file, the API response will provide you with your DocId. You use this DocId along with your credentials to make a call to preview the transformation of the uploaded file.

The details:

Both the Preview and the Image endpoint support both POST and GET methods for processing parameters.

  • When using POST parameters are passed in the body of a JSON object.
  • When using GET individual parameters are included in the query string.

Examples of using both methods are in the provided use cases

Regardless of the method used the DocId returned from the upload must either be specified as the last component of the path or (if left off) it must be passed as a header keyed under "X-TweekIT-DocId". See Examples to the right for more details. Below is a list of the Parameters that can be specified to transform the uploaded file.

Parameter Value

Return a page # other than page 1 for multi page file formats, alternatively return the frame # other than frame 1 for animated file formats. If missing or 0, returns page/frame 1 by default.


Scale output image to width. Leave off or set to 0 to constrain only to the height.


Scale output image to height. Leave off or set to 0 to constrain only to the width. If neither Width nor Height is specified, no scaling is performed.


Set the background color for any padded pixels in the image. If both Width and Height are specified, pad the image with this background color. Default is 0x000000 (Black).

Bg must be specified in Hex color using this format.

Note: Bg is also used to replace the alpha channel (add link explaining alpha channel) if the output image won't have an alpha channel.


Left crop coordinate on the horizontal axis. Used to specify 1 of the 4 coordinates necessary to create the cropping box for a given file.

Note: Both X or Y crop coordinates must be specified if the image is to be cropped along that axis. If only one axis is provided the image default with be used for the other axis.


Top crop coordinate on the vertical axis. Used to specify 1 of the 4 coordinates necessary to create the cropping box for a given image.


Right crop coordinate. IS EXCLUSIVE - so add one to this to get expected results.

For example, X1=10 and X2=30 will crop the source image to 20 pixels wide at X coordinate 10.


Y2 - Bottom crop coordinate. Same as X2 but on the vertical axis.


Set the crop to be Elliptical vs Square, default is false and thus a Square crop. If true, the crop coordinates if defined, define the outer edge of an ellipse and the image will be cropped as such.

Note: This will automatically generate an alpha channel if needed (see below).


Output file format. Restricted to web-compatible formats JPG, PNG, BMP, or GIF. Defaults to JPEG if not specified.


Creates a content-disposition in the response to trigger a file download instead of returning an inline image if set to true.

When set to true the file will be downloaded using the original doc's filename with the proper extension for the output format replacing the doc's original extension. The default is false. (Have Matt Review)


Controls the Alpha channel behavior for supported formats. If set to true, it will allow the alpha channel to pass through (for PNG and GIF). If set to false the original document's alpha channel with be replaced with the background color specified by the Bg parameter. JPEG and BMP always replace the alpha due to no alpha channel support for those formats. A more detailed description of how it works follows:

If the output format is not GIF or PNG, Alpha is forced to off no matter how it is set. Otherwise, when outputting to GIF or PNG and -

  • Alpha isn't specified and Elliptical is true, default Alpha to true.
  • Alpha isn't specified and Elliptical is false and the source image uploaded by the user has an alpha channel, set Alpha to true. Otherwise, set it to false.
  • Alpha is specified? Use the specified value - no default needed.


In addition to the image, this preview call also returns the page count for the document in the "X-CPUCoinMiner-PageCount" response header which can be used by the client to validate page # requests.

/api/image[/DocId] POST or GET

Returns a transformed output of the uploaded document, using the CGN to perform the final transform. When you are happy with your changes as previewed above, you make the same transformative call to the ‘image’ endpoint, and TweekIT returns your final transformed output, removes the file, and invalidates the DocId for that upload.

And that’s it, you are done. Go forth and transform the web one file at a time.

Easy, Simple, Powerful just as promised. Have questions, need help, want more - contact us here .