Timeouts and Other Parameters

Before sending input into an Algorithm, you have the option to set several parameters which affect how the Algorithm runs. These are detailed in the API Docs, but two deserve special mention.

Timeouts

By default, any call to an algorithm will abort if it hasn't completed after 300 seconds (5 minutes). For many Algorithms, this is fine, but certain calls -- such as those which handle large amounts of data, or work with images or videos -- may take longer.

You can increase the amount of time a call is allowed to run by adjusting the "timeout" parameter, up to 3000 seconds (50 minutes).

In most languages, this is done using a setOptions() or similar function on the algo, e.g. algo = client.algo('demo/Hello/').set_options(timeout=600) in Python. See the API Docs for your language's syntax.

This can also be done by adding "?timeout=##" to the end of the Algorithm's identifier.  In JavaScript, for example, this would be client.algo("algo://demo/Hello/?timeout=600")

Output

By default, calls to Algorithms return the structure described in Input and Output, consisting of an object with the properties .result (for the actual output) and .metadata (containing information such as the execution time). By setting the "output' parameter on your algo before calling it, you can change how/if the results are returned. 

"raw" mode -- e.g. client.algo('demo/Hello/').set_options(output=Algorithmia.algorithm.OutputType.raw) or client.algo("algo://demo/Hello/?output=raw") -- just sends back the actual Algorithm output (what you'd normally find in the .results property), with no wrapper object or metadata. This is especially useful for creating streamlined code, such as piping the results of a cURL call directly into another utility.  For example, curl -X POST -d '{"document":"terrible"}' -H 'Content-Type: application/json' -H 'Authorization: Simple YOUR_API_KEY' https://api.algorithmia.com/v1/algo/nlp/SentimentAnalysis?output=raw | grep '-' ... a one-liner which only shows output if the sentiment score was negative (contained a "-" symbol).

"void" mode -- e.g. client.algo('demo/Hello/').set_options(output=Algorithmia.algorithm.OutputType.void) or client.algo("algo://demo/Hello/?output=void") -- returns immediately and sends back no results. Use this whenever you don't need to directly see the output of your call (for example, when using Algorithms which generate a file in a specified location that you'll look at later. By setting output=void, your local code doesn't need to wait for the Algorithm call to return before doing other work, since the call is non-blocking.


Now that you know how to call Algorithms, let's learn about working with files and managing data.

 


NEXT