Inputs

The API is built around a simple idea. You send inputs (images) to the service and it returns predictions. In addition to receiving predictions on inputs, you can also 'save' inputs and their predictions to later search against. You can also 'save' inputs with concepts to later train your own model.

Add Inputs

You can add inputs one by one or in bulk. If you do send bulk, you are limited to sending 128 inputs at a time.

Images can either be publicly accessible URLs or file bytes. If you are sending file bytes, you must use base64 encoding.

You are encouraged to send inputs with your own id. This will help you later match the input to your own database. If you do not send an id, one will be created for you.

Important: adding inputs is an asynchronous operation. That means it will process indexing of your inputs through your default workflow in the background, which can take some time. In order to check the status of each input you add, see the section on Get Input by ID to look for status 30000 (INPUT_IMAGE_DOWNLOAD_SUCCESS) status code on each input to know when it's successfully been indexed.

Add an input using a publicly accessible URL

js
python
java
csharp
objective-c
php
cURL
app.inputs.create({
url: "https://samples.clarifai.com/metro-north.jpg"
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Add an input using bytes

The data must be base64 encoded. When you add a base64 image to our servers, a copy will be stored and hosted on our servers. If you already have an image hosting service we recommend using it and adding images via the url parameter.

js
python
java
csharp
objective-c
php
cURL
app.inputs.create({
base64: "Zvfauhti4D..."
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Add multiple inputs with ids

js
python
java
csharp
objective-c
php
cURL
app.inputs.create([
{
url: "https://samples.clarifai.com/metro-north.jpg",
id: 'train1'
},
{
url: "https://samples.clarifai.com/puppy.jpg",
id: 'puppy1'
}
]).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Add Inputs With Concepts

If you would like to add an input with concepts, you can do so like this. Concepts play an important role in creating your own models using your own concepts. You can learn more about creating your own models above. Concepts also help you search for inputs. You can learn more about search here.

When you add a concept to an input, you need to indicate whether the concept is present in the image or if it is not present.

You can add inputs with concepts as either a URL or bytes.

js
python
java
csharp
objective-c
php
cURL
app.inputs.create({
url: "https://samples.clarifai.com/puppy.jpg",
concepts: [
{
id: "boscoe",
value: true
}
]
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Add Inputs With Custom Metadata

In addition to adding an input with concepts, you can also add an input with custom metadata. This metadata will then be searchable. Metadata can be any arbitrary JSON.

js
python
java
csharp
objective-c
php
cURL
app.inputs.create({
url: "https://samples.clarifai.com/puppy.jpg",
metadata: {id: 'id001', type: 'plants', size: 100}
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Add Input With A Crop

When adding an input, you can specify crop points. The API will crop the image and use the resulting image. Crop points are given as percentages from the top left point in the order of top, left, bottom and right.

As an example, if you provide a crop as 0.2, 0.4, 0.3, 0.6 that means the cropped image will have a top edge that starts 20% down from the original top edge, a left edge that starts 40% from the original left edge, a bottom edge that starts 30% from the original top edge and a right edge that starts 60% from the original left edge.

js
python
java
csharp
objective-c
php
cURL
app.inputs.create(
{
"url": "https://samples.clarifai.com/metro-north.jpg",
"crop": [0.2, 0.4, 0.3, 0.6]
}
).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Get Inputs

You can list all the inputs (images) you have previously added either for search or train.

If you added inputs with concepts, they will be returned in the response as well.

This request is paginated.

js
python
java
csharp
objective-c
php
cURL
app.inputs.list({page: 1, perPage: 20}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Get Input By Id

If you'd like to get a specific input by id, you can do that as well.

js
python
java
csharp
objective-c
php
cURL
app.inputs.get({id}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Get Inputs Status

If you add inputs in bulk, they will process in the background. You can get the status of all your inputs (processed, to_process and errors) like this:

js
python
java
csharp
objective-c
php
cURL
app.inputs.getStatus().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Update Input With Concepts

To update an input with a new concept, or to change a concept value from true/false, you can do that:

js
python
java
csharp
objective-c
php
cURL
app.inputs.mergeConcepts([
{
id: "{id}",
concepts: [
{
id: "tree"
},
{
id: "water",
value: false
}
]
},
])
// or if you have an input instance
app.inputs.get({id}).then(
function(input) {
input.mergeConcepts([
{
id: "tree",
value: true
},
{
id: "water",
value: false
}
])
},
function(err) {
// there was an error
}
);

Delete Concepts From An Input

To remove concepts that were already added to an input, you can do this:

js
python
java
csharp
objective-c
php
cURL
app.inputs.deleteConcepts([
{
id: "{id}",
concepts: [
{
id: "tree"
},
{
id: "water",
value: false
}
]
},
])
// or if you have an input instance
app.inputs.get({id}).then(
function(input) {
input.deleteConcepts([
{
id: "tree",
value: true
},
{
id: "water",
value: false
}
])
},
function(err) {
// there was an error
}
);

Bulk Update Inputs With Concepts

You can update an existing input using its Id. This is useful if you'd like to add concepts to an input after its already been added.

js
python
java
csharp
objective-c
php
cURL
app.inputs.mergeConcepts([
{
id: "{id1}",
concepts: [
{
id: "tree",
value: true
},
{
id: "water",
value: false
}
]
},
{
id: "{id2}",
concepts: [
{
id: "animal",
value: true
},
{
id: "fruit",
value: false
}
]
}
]).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Bulk Delete Concepts From A List Of Inputs

You can bulk delete multiple concepts from a list of inputs:

js
python
java
csharp
objective-c
php
cURL
app.inputs.deleteConcepts([
{
id: "{id1}",
concepts: [
{ id: "tree" },
{ id: "water" }
]
},
{
id: "{id2}",
concepts: [
{ id: "animal" },
{ id: "fruit" }
]
}
]).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Delete Input By Id

You can delete a single input by id:

js
python
java
csharp
objective-c
php
cURL
app.inputs.delete(INPUT_ID).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Delete A List Of Inputs

You can also delete multiple inputs in one API call. This will happen asynchronously.

js
python
java
csharp
objective-c
php
cURL
app.inputs.delete([{id1}, {id2}]).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Delete All Inputs

If you would like to delete all inputs from an application, you can do that as well. This will happen asynchronously.

js
python
java
csharp
objective-c
php
cURL
app.inputs.delete().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);