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 index inputs and their predictions to later search against. You can also index inputs with concepts to later train your own model.
When you add an input to your app, the base workflow of your app runs, computing the outputs from all the models in that workflow and indexes those outputs. Those indexed outputs are what incur the indexing fee monthly, and enable search and training on top of the outputs of the base workflow models.
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.
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
importcom.clarifai.grpc.api.*;importcom.clarifai.grpc.api.status.*;// Insert here the initialization code as outlined on this page:// https://docs.clarifai.com/api-guide/api-overviewMultiInputResponse postInputsResponse =stub.postInputs(PostInputsRequest.newBuilder().addInputs(Input.newBuilder().setData(Data.newBuilder().setImage(Image.newBuilder().setUrl("https://samples.clarifai.com/metro-north.jpg").setAllowDuplicateUrl(true) ) ) ).build());if (postInputsResponse.getStatus().getCode() !=StatusCode.SUCCESS) {thrownewRuntimeException("Post inputs failed, status: "+postInputsResponse.getStatus());}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.PostInputs(
{
inputs: [{data: {image: {url: "https://samples.clarifai.com/metro-north.jpg", allow_duplicate_url: true}}}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/metro-north.jpg",
allow_duplicate_url=True
)
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
app.inputs.create({
url: "https://samples.clarifai.com/metro-north.jpg"
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
app.inputs.create_image_from_url("https://samples.clarifai.com/metro-north.jpg")
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Inputs;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.AddInputs(
new ClarifaiURLImage("https://samples.clarifai.com/metro-north.jpg"))
.ExecuteAsync();
}
}
}
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.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
import com.google.protobuf.ByteString;
import java.io.File;
import java.nio.file.Files;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder().addInputs(
Input.newBuilder().setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setBase64(ByteString.copyFrom(Files.readAllBytes(
new File("{YOUR_IMAGE_LOCATION}").toPath()
)))
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
const fs = require("fs");
const imageBytes = fs.readFileSync("{YOUR_IMAGE_LOCATION}");
stub.PostInputs(
{
inputs: [{data: {image: {base64: imageBytes}}}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
with open("{YOUR_IMAGE_LOCATION}", "rb") as f:
file_bytes = f.read()
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
base64=file_bytes
)
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
app.inputs.create({
base64: "Zvfauhti4D..."
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
# add from filename
app.inputs.create_image_from_filename(filename)
# add from base64 bytes
app.inputs.create_image_from_base64(base64_bytes)
using System.IO;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Inputs;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.AddInputs(
new ClarifaiFileImage(File.ReadAllBytes("image.png")))
.ExecuteAsync();
}
}
}
In cases where you have your own id and you only have one item per image, 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. If you have more than one item per image, it is recommended that you put the product id in metadata.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.addInputs(
Input.newBuilder()
.setId("train1")
.setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setUrl("https://samples.clarifai.com/metro-north.jpg")
.setAllowDuplicateUrl(true)
)
)
)
.addInputs(
Input.newBuilder()
.setId("puppy1")
.setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setUrl("https://samples.clarifai.com/puppy.jpeg")
.setAllowDuplicateUrl(true)
)
)
)
.build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
for (Input input : postInputsResponse.getInputsList()) {
System.out.println("Input " + input.getId() + " status: ");
System.out.println(input.getStatus() + "\n");
}
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.PostInputs(
{
inputs: [
{
id: "train1",
data: {image: {url: "https://samples.clarifai.com/metro-north.jpg", allow_duplicate_url: true}}
},
{
id: "puppy1",
data: {image: {url: "https://samples.clarifai.com/puppy.jpeg", allow_duplicate_url: true}}
},
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
for (const input of response.inputs) {
console.log("Input " + input.id + " status: ");
console.log(JSON.stringify(input.status, null, 2) + "\n");
}
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
inputs=[
resources_pb2.Input(
id="train1",
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/metro-north.jpg",
allow_duplicate_url=True
)
)
),
resources_pb2.Input(
id="puppy1",
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/puppy.jpeg",
allow_duplicate_url=True
)
)
),
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
for input_object in post_inputs_response.inputs:
print("Input " + input_object.id + " status:")
print(input_object.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
% tab title="js" %}
app.inputs.create([
{
url: "https://samples.clarifai.com/metro-north.jpg",
id: 'train1'
},
{
url: "https://samples.clarifai.com/puppy.jpeg",
id: 'puppy1'
}
]).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
app = ClarifaiApp(api_key='YOUR_API_KEY')
img1 = ClImage(url="https://samples.clarifai.com/metro-north.jpg", image_id="train1")
img2 = ClImage(url="https://samples.clarifai.com/puppy.jpeg", image_id="puppy1")
app.inputs.bulk_create_images([img1, img2])
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Inputs;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.AddInputs(
new ClarifaiURLImage(
"https://samples.clarifai.com/metro-north.jpg",
positiveConcepts: new List<Concept> {new Concept("id1")}),
new ClarifaiURLImage(
"https://samples.clarifai.com/wedding.jpg",
positiveConcepts: new List<Concept> {new Concept("id2")}))
.ExecuteAsync();
}
}
}
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.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder().addInputs(
Input.newBuilder().setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl("https://samples.clarifai.com/puppy.jpeg")
.setAllowDuplicateUrl(true)
)
.addConcepts(
Concept.newBuilder()
.setId("charlie")
.setValue(1f)
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.PostInputs(
{
inputs: [{data: {
image: {url: "https://samples.clarifai.com/puppy.jpeg", allow_duplicate_url: true},
concepts: [{id: "charlie", value: 1.}]
}}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/puppy.jpeg",
allow_duplicate_url=True
),
concepts=[resources_pb2.Concept(id="charlie", value=1.)]
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
app.inputs.create({
url: "https://samples.clarifai.com/puppy.jpeg",
concepts: [
{
id: "charlie",
value: true
}
]
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
app = ClarifaiApp(api_key='YOUR_API_KEY')
# add by url
app.inputs.create_image_from_url("https://samples.clarifai.com/puppy.jpeg", concepts=['charlie'])
# add by base64 bytes
app.inputs.create_image_from_base64(base64_bytes, concepts=['charlie'])
# add by raw bytes
app.inputs.create_image_from_bytes(raw_bytes, concepts=['charlie'])
# add by local file
app.inputs.create_image_from_filename(local_filename, concepts=['charlie'])
# add multiple with concepts
img1 = ClImage(url="https://samples.clarifai.com/puppy.jpeg", concepts=['charlie'], not_concepts=['our_wedding'])
img2 = ClImage(url="https://samples.clarifai.com/wedding.jpg", concepts=['our_wedding'], not_concepts=['cat','charlie'])
app.inputs.bulk_create_images([img1, img2])
client.addInputs()
.plus(ClarifaiInput.forImage("https://samples.clarifai.com/puppy.jpeg")
.withConcepts(
// To mark a concept as being absent, chain `.withValue(false)`
Concept.forID("charlie")
)
)
.executeSync();
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Inputs;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.AddInputs(
new ClarifaiURLImage(
"https://samples.clarifai.com/puppy.jpeg",
// To mark a concept as being absent, use negativeConcepts
positiveConcepts: new List<Concept> {new Concept("charlie")}))
.ExecuteAsync();
}
}
}
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.
If you have more than one item per image it is recommended to put the id in metadata like:
{
"product_id": "xyz"
}
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder().addInputs(
Input.newBuilder().setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl("https://samples.clarifai.com/puppy.jpeg")
.setAllowDuplicateUrl(true)
)
.setMetadata(
Struct.newBuilder()
.putFields("id", Value.newBuilder().setStringValue("id001").build())
.putFields("type", Value.newBuilder().setStringValue("animal").build())
.putFields("size", Value.newBuilder().setNumberValue(100).build())
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.PostInputs(
{
inputs: [{data: {
image: {url: "https://samples.clarifai.com/puppy.jpeg", allow_duplicate_url: true},
metadata: {id: "id001", type: "animal", size: 100}
}}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
from google.protobuf.struct_pb2 import Struct
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
input_metadata = Struct()
input_metadata.update({"id": "id001", "type": "animal", "size": 100})
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/puppy.jpeg",
allow_duplicate_url=True
),
metadata=input_metadata
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
app.inputs.create({
url: "https://samples.clarifai.com/puppy.jpeg",
metadata: {id: 'id001', type: 'plants', size: 100}
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
app = ClarifaiApp(api_key='YOUR_API_KEY')
# metadata must be defined as JSON object
metadata = {'id':'id001', 'type':'plants', 'size':100}
# adding metadata along with url, filename, etc
app.inputs.create_image_from_url(url="https://samples.clarifai.com/puppy.jpeg", metadata=metadata)
app.inputs.create_image_from_filename(filename="aa.jpg", metadata=metadata)
# define an image with metadata for bulk import
img = Image(url="", metadata=metadata)
app.inputs.bulk_create_images([img])
final JsonObject metadata = new JsonObject();
metadata.addProperty("isPuppy", true);
client.addInputs()
.plus(
ClarifaiInput.forImage("https://samples.clarifai.com/puppy.jpeg")
.withMetadata(metadata)
).executeSync();
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Inputs;
using Newtonsoft.Json.Linq;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
var metadata = new JObject(
new JProperty("key1", "val1"),
new JProperty("key2", "val2"));
await client.AddInputs(
new ClarifaiURLImage(
"https://samples.clarifai.com/puppy.jpeg",
metadata: metadata))
.ExecuteAsync();
}
}
}
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.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
MultiInputResponse listInputsResponse = stub.listInputs(
ListInputsRequest.newBuilder()
.setPage(1)
.setPerPage(10)
.build()
);
if (listInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List inputs failed, status: " + listInputsResponse.getStatus());
}
for (Input input : listInputsResponse.getInputsList()) {
System.out.println(input);
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.ListInputs(
{page: 1, per_page: 10},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List inputs failed, status: " + response.status.description);
}
for (const input of response.inputs) {
console.log(JSON.stringify(input, null, 2));
}
}
);
from clarifai_grpc.grpc.api import service_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
list_inputs_response = stub.ListInputs(
service_pb2.ListInputsRequest(page=1, per_page=10),
metadata=metadata
)
if list_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("List inputs failed, status: " + list_inputs_response.status.description)
for input_object in list_inputs_response.inputs:
print(input_object)
app.inputs.list({page: 1, perPage: 20}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
# this is a generator
app.inputs.get_all()
# get a page of inputs
app.inputs.get_by_page(page=1, per_page=20)
client.getInputs() // optionally takes a perPage parameter
.getPage(1)
.executeSync();
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.GetInputs()
.Page(1)
.ExecuteAsync();
}
}
}
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Inputs\ClarifaiInput;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->getInputs()->executeSync();
if ($response->isSuccessful()) {
$inputs = $response->get();
foreach ($inputs as $input) {
echo $input->id() . "\n";
}
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
curl -X GET \
-H "Authorization: Key YOUR_API_KEY" \
https://api.clarifai.com/v2/inputs?page=1&per_page=10
List inputs (streaming)
Another method for listing inputs which was built to scalably list app's inputs in an iterative / streaming fashion. StreamInputs will return per_page number of inputs from a certain input onward, controlled by the optional last_id parameter (defaults to the first input).
By default, the stream will return inputs from oldest to newest. Set the descending field to true to reverse that order.
import java.util.List;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
// To start from beginning, do not provide the last ID parameter.
MultiInputResponse firstStreamInputsResponse = stub.streamInputs(
StreamInputsRequest.newBuilder()
.setPerPage(10)
.build()
);
if (firstStreamInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Stream inputs failed, status: " + firstStreamInputsResponse.getStatus());
}
System.out.println("First response (starting from the first input):");
List<Input> inputs = firstStreamInputsResponse.getInputsList();
for (Input input : inputs) {
System.out.println("\t" + input.getId());
}
String lastId = inputs.get(inputs.size() - 1).getId();
// Set last ID to get the next set of inputs. The returned inputs will not include the last ID input.
MultiInputResponse secondStreamInputsResponse = stub.streamInputs(
StreamInputsRequest.newBuilder()
.setLastId(lastId)
.setPerPage(10)
.build()
);
if (secondStreamInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Stream inputs failed, status: " + secondStreamInputsResponse.getStatus());
}
System.out.println(String.format("Second response (first input is the one following input ID %s)", lastId));
for (Input input : secondStreamInputsResponse.getInputsList()) {
System.out.println("\t" + input.getId());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.StreamInputs(
{
per_page: 10
},
metadata,
(err, firstResponse) => {
if (err) {
done(err);
return;
}
if (firstResponse.status.code !== 10000) {
done(new Error("Received status: " + firstResponse.status.description + "\n" + firstResponse.status.details));
return;
}
console.log("First response (starting from the first input):");
for (const input of firstResponse.inputs) {
console.log("\t" + input.id);
}
const lastId = firstResponse.inputs[firstResponse.inputs.length - 1].id;
stub.StreamInputs(
{
last_id: lastId,
per_page: 10
},
metadata,
(err, secondResponse) => {
if (err) {
done(err);
return;
}
if (secondResponse.status.code !== 10000) {
done(new Error("Received status: " + secondResponse.status.description + "\n" + secondResponse.status.details));
return;
}
console.log("Second response (first input is the one following input ID " + lastId + ")");
for (const input of secondResponse.inputs) {
console.log("\t" + input.id);
}
done();
}
);
}
);
from clarifai_grpc.grpc.api import service_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
# To start from beginning, do not provide the last_id parameter.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(per_page=10),
metadata=metadata
)
if stream_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Stream inputs failed, status: " + stream_inputs_response.status.description)
print("First response (starting from the first input):")
for input_object in stream_inputs_response.inputs:
print("\t" + input_object.id)
last_id = stream_inputs_response.inputs[-1].id
# Set last_id to get the next set of inputs. The returned inputs will not include the last_id input.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(per_page=10, last_id=last_id),
metadata=metadata
)
print(f"Second response (first input is the one following input ID {last_id}):")
for input_object in stream_inputs_response.inputs:
print("\t" + input_object.id)
Get input by id
If you'd like to get a specific input by id, you can do that as well.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
SingleInputResponse getInputResponse = stub.getInput(
GetInputRequest.newBuilder()
.setInputId("{YOUR_INPUT_ID}")
.build()
);
if (getInputResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get input failed, status: " + getInputResponse.getStatus());
}
Input input = getInputResponse.getInput();
System.out.println(input);
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.GetInput(
{input_id: "{YOUR_INPUT_ID}"},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Get input failed, status: " + response.status.description);
}
const input = response.input;
console.log(JSON.stringify(input, null, 2));
}
);
from clarifai_grpc.grpc.api import service_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
get_input_response = stub.GetInput(
service_pb2.GetInputRequest(input_id="{YOUR_INPUT_ID}"),
metadata=metadata
)
if get_input_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Get input failed, status: " + get_input_response.status.description)
input_object = get_input_response.input
print(input_object)
app.inputs.get({id}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
image = app.inputs.get(input_id)
client.getInputByID("{id}").executeSync();
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.GetInput("{id}")
.ExecuteAsync();
}
}
}
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Inputs\ClarifaiURLImage;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->getInput('{input_id}')->executeSync();
if ($response->isSuccessful()) {
// Here we "cast" from ClarifaiInput to ClarifaiURLImage.
$input = $response->get();
echo $input->url();
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
curl -X GET \
-H "Authorization: Key YOUR_API_KEY" \
https://api.clarifai.com/v2/inputs/{YOUR_INPUT_ID}
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:
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
SingleInputCountResponse getInputCountResponse = stub.getInputCount(
GetInputCountRequest.newBuilder().build()
);
if (getInputCountResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get input count failed, status: " + getInputCountResponse.getStatus());
}
InputCount inputCount = getInputCountResponse.getCounts();
System.out.println(inputCount);
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.GetInputCount(
{},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Get input count failed, status: " + response.status.description);
}
const counts = response.counts;
console.log(JSON.stringify(counts, null, 2));
}
);
from clarifai_grpc.grpc.api import service_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
get_input_count_response = stub.GetInputCount(
service_pb2.GetInputCountRequest(),
metadata=metadata
)
if get_input_count_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Get input count failed, status: " + get_input_count_response.status.description)
counts = get_input_count_response.counts
print(counts)
app.inputs.getStatus().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
app.inputs.check_status()
client.getInputsStatus().executeSync();
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.GetInputsStatus()
.ExecuteAsync();
}
}
}
[app getInputsStatus:^(int numProcessed, int numToProcess, int errors, NSError *error) {
NSLog(@"number of inputs processed: %d", numProcessed);
}];
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.API.Requests.Models;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.ModifyInput(
"{input_id}",
ModifyAction.Merge,
positiveConcepts: new List<Concept> {new Concept("tree")},
negativeConcepts: new List<Concept> {new Concept("water")})
.ExecuteAsync();
}
}
}
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.API.Requests.Models;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.ModifyInput(
"INPUT_ID",
ModifyAction.Remove,
positiveConcepts: new List<Concept> {new Concept("tree")},
negativeConcepts: new List<Concept> {new Concept("water")})
.ExecuteAsync();
}
}
}
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
BaseResponse deleteInputResponse = stub.deleteInput(
DeleteInputRequest.newBuilder()
.setInputId("{YOUR_INPUT_ID}")
.build()
);
if (deleteInputResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete input failed, status: " + deleteInputResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.DeleteInput(
{
input_id: "{YOUR_INPUT_ID}"
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete input failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview
delete_input_response = stub.DeleteInput(
service_pb2.DeleteInputRequest(input_id="{YOUR_INPUT_ID}"),
metadata=metadata
)
if delete_input_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Delete input failed, status: " + delete_input_response.status.description)
app.inputs.delete(INPUT_ID).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
app.inputs.delete("INPUT_ID")
client.deleteInput("INPUT_ID")
.executeSync();
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.DeleteInputs("INPUT_ID")
.ExecuteAsync();
}
}
}
[_app deleteInputsByIDList:@[INPUT_ID] completion:^(NSError *error) {
NSLog(@"input has been deleted");
}];
use Clarifai\API\ClarifaiClient;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->deleteInputs('INPUT_ID')
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.DeleteInputs("{id1}", "{id2}")
.ExecuteAsync();
}
}
}
[_app deleteInputsByIDList:@[{id1}, {id2}] completion:^(NSError *error) {
NSLog(@"inputs have been deleted");
}];
use Clarifai\API\ClarifaiClient;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->deleteInputs(['INPUT_ID1', 'INPUT_ID2'])
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
If you would like to delete all inputs from an application, you can do that as well. This will happen asynchronously.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
BaseResponse listInputsResponse = stub.deleteInputs(
DeleteInputsRequest.newBuilder()
.setDeleteAll(true)
.build()
);
if (listInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete inputs failed, status: " + listInputsResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview
stub.DeleteInputs(
{
delete_all: true
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete inputs failed, status: " + response.status.description);
}
}
);
from clarifai_grpc.grpc.api import service_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
delete_inputs_response = stub.DeleteInputs(
service_pb2.DeleteInputsRequest(
delete_all=True
),
metadata=metadata
)
if delete_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Delete inputs failed, status: " + delete_inputs_response.status.description)
app.inputs.delete().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
app.inputs.delete_all()
client.deleteAllInputs().executeSync();
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.DeleteAllInputs()
.ExecuteAsync();
}
}
}
[app deleteAllInputs:^(ClarifaiInput *input, NSError *error) {
NSLog(@"all inputs have been deleted");
}];
use Clarifai\API\ClarifaiClient;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->deleteInputs([], true)
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}