The Terrene API is organized around REST. Our API has predictable, resource-oriented URLs, and uses HTTP response codes to indicate API errors. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which are understood by off-the-shelf HTTP clients. We support cross-origin resource sharing, allowing you to interact securely with our API from a client-side web application (though you should never expose your secret API key in any public website's client-side code). JSON is returned by all API responses, including errors, although our API libraries convert responses to appropriate language-specific objects.
In this tutorial, you'll learn how to use a model trained by Terrene in your Swift app. If you haven't already trained a model on Terrene, please refer to one of the model training tutorials and then come back here once you're done.
1. Create an Authentication Token
To access Terrene's API, first create an authentication token in Terrene's portal. To do so click on the
settings icon in the top toolbar of the dashboard.
Then click on the
account security tab and then generate a new authentication token.
Copy and store your newly created authentication token.
2. Find The Unique Identifier of Your Predictive Endpoint
On the workspace page in Terrene's portal, click on the "Model Endpoints" option from the left menu then click on the predictive endpoint which you want to use.
Then find and save the
object_id of your predictive endpoint.
3. Make a HTTP Request
Terrene uses JSON Web Tokens to authenticate your HTTP requests. The JWT must to be passed as an
Authorization header with the format of
In order to make a prediction, you need to json serialize your input dictionary. Please make sure the key names in your dictionary match the input variables for your predictive model.
Now you can construct your HTTP request.
Now that the HTTP request is constructed, you can go ahead an run it.
Here's the completed code for your reference:
// comming soon