Developer Center

Resources to get you started with Algorithmia

Javascript

Updated

We offer a vanilla JavaScript client for calling algorithms in the marketplace.

Download

You can download our JavaScript client from:

https://algorithmia.com/v1/clients/js/algorithmia-0.2.0.js

You can include the JavaScript file as a script tag:

<script src="//algorithmia.com/v1/clients/js/algorithmia-0.2.0.js" type="text/javascript"></script>

Call an Algorithm

Next, login to Algorithmia to get your API key:

Now import the Algorithmia library and create the Algorithmia client:

var client = Algorithmia.client("YOUR_API_KEY");

After setting your API key, you can then use the client variable from the above line to call algorithms.

The format for calling an algorithm is client.algo() with the algorithm name passed in. To pass input to the algorithm, use the .pipe method.

client.algo("demo/Hello").pipe(input)

Here is an example of how to authenticate and call an algorithm in JavaScript:

var input = 41;
var client = Algorithmia.client("YOUR_API_KEY");
client.algo("docs/JavaAddOne").pipe(input).then(function(output) {
  if(output.error) return console.error("error: " + output.error);
  console.log(output.result);
});

Enterprise Users Only: Specifying an On-Premises Endpoint

If you are running the Algorithmia platform on-premises with Algorithmia Enterprise, you can specify the API endpoint when you create the client object:

var client = Algorithmia.client("YOUR_API_KEY", "https://mylocalendpoint");

Limits

Your account can make up to 80 Algorithmia requests at the same time (this limit can be raised if needed).

Note: Working with Files

Because of security concerns, the JavaScript client does not implement the Data API which other clients use to move files into and out of Data Sources. This can be a problem if you call an algorithm which writes its output to a file (instead of returning it directly). However, there are workarounds:

For smaller files, the util/Cat and ANaimi/Base64DataConverter algorithms can be used for retrieving file contents.

For larger files, you can set up an Amazon S3 Connector to an S3 bucket with public read access. Then, direct the algorithms you call to write their output into that S3 connector (or use s3utilities/UploadFiletoS3/ to move it there). Once it is in the S3 bucket, you can access the file via its publicly-readable URL.

Alternately, you could implement a small piece of backend code in another language and use it to retrieve the file for you.