Add, Get, Update, Delete
Manage the data in your app
The API is built around a simple idea. You send inputs (such as 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 indexing 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.
The initialization code used in the following examples is outlined in detail on the client installation page.
Add Inputs
You can add inputs one by one or in bulk. If you send them in bulk, you are limited to sending 128 inputs at a time.
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 Inputs and look for status 30000 (INPUT_IMAGE_DOWNLOAD_SUCCESS) status code on each input to know when it has successfully been indexed.
Add Inputs via URL
Below is an example of how to add inputs via a publicly accessible URL.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##########################################################################
# In this section, we set the user authentication, app ID, and input URL.
# Change these strings to run your own example.
##########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to whatever image input you want to add
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
)
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input URL.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever image input you want to add
const IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"data": {
"image": {
"url": IMAGE_URL,
"allow_duplicate_url": true
}
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input URL.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever image input you want to add
const IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
inputs: [
{ data: { image: { url: IMAGE_URL, allow_duplicate_url: true } } }
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input URL.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to whatever image input you want to add
static final String IMAGE_URL = "https://samples.clarifai.com/metro-north.jpg";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder().setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setUrl(IMAGE_URL)
.setAllowDuplicateUrl(true)
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input URL.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever image input you want to add
$IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Image;
use Clarifai\Api\Input;
use Clarifai\Api\PostInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT ]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsRequest([
'user_app_id' => $userDataObject,
'inputs' => [
new Input([ // The Input object wraps the Data object in order to meet the API specification
'data' => new Data([ // The Data object is constructed around the Image object. It offers a container that has additional image independent
// metadata. In this particular use case, no other metadata is needed to be specified
'image' => new Image([ // In the Clarifai platform, an image is defined by a special Image object
'url' => $IMAGE_URL,
'allow_duplicate_url' => true
])
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
$response->getStatus()->getDetails());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg",
"allow_duplicate_url": true
}
}
}
]
}'
Add Inputs via Bytes
Below is an example of how to add inputs via 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.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################################
# In this section, we set the user authentication, app ID, and the location
# of the image we want as an input. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to whatever image input you want to add
IMAGE_FILE_LOCATION = 'YOUR_IMAGE_FILE_LOCATION'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
with open(IMAGE_FILE_LOCATION, "rb") as f:
file_bytes = f.read()
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
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:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the location
// of the image we want as an input. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever image input you want to add
const BYTES_STRING = '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAoACgDASIAAhEBAxEB/8QAGQAAAgMBAAAAAAAAAAAAAAAAAAYDBQcE/8QAMBAAAQMDAwMDAgQHAAAAAAAAAQIDBAAFEQYSIQcTMTJBURRhCBYikSNScXKhsdH/xAAZAQACAwEAAAAAAAAAAAAAAAAFBgIDBAf/xAAtEQABAwMBBgQHAQAAAAAAAAABAgMRAAQhMQUSE0FRYQaBocEUFiJCcrHR8P/aAAwDAQACEQMRAD8A3+RYY1unSYzCS0ttZUkAgktn0q5yT7jPyDUC4wdGwycH5U2Kt9ZQ7VI1qw5PkvQy3CSVPpf7aQjuKyFH25xzn3pHn3TVNy01Hl2hyy6YdkSpKsS9sl/6RlI3rRu3dxWd6spwnAGPIJTfl925fcLaoSDHXvyo6i9SlCQrU9wKln3OyWiaDN1RAbW3kKbSd7gPtwMkH/tTWy9afuy1iPfnXMAblITwkE4yf08cn3pSbYt1uts24XH6fUbiLAuY1MWyGkLEmUW0rcCRvUpQ5CtwKQCPgi4S1ZbDe4sd9NntDEe79m3uOBLTr0IR9jzodSMqUpTu9JJ8owD7UTT4ZCfv9PbP7860m+s+HBSrejWRuz2kAxoesGYxTW/Zlpkwo1vkuSly3UgKWQUhHJUvIHsAaKTemF8XE6sWmxyZkiaZrMh1jv8ArQNpUVqB8FW0njHqx4zRVVhsph1KlKk5xQ+7uHmikaSJrQerMByet2IwvtuTLa4xv2k7Rk84H9x/esHv92d01boenLXGcuiWrFIhLlpbcaQ2/JdK3VJCkAq2pAR7Zz7YxWudY9fxNIdQbNGkR5TyX4aisNNpUMFZAzkj4NK0jq9ZpbLr0PSlzkhrlZDaQlP3P8Q4/ap3F87bPucJEkx/hHv60b2TYXLrKN5sramYECSQRk9M6c6zmJ+eb5Hi22M7cnWGIQgFLbX0zSo4PDa1YBcTgDyMjJ/qbGPabH08SJt1Uzc9QqRliGg5QySPKvgc+TyfYDmmTUWpNYz7ctxoQdPQshCktupckDJUPUcJT6DwMq8YyaQ9VL0pCS8zapcq4SVOBZmPDO8/cnknlWcDBwn4NYnPjLkQ+qE9OtOVlYpeVHDCEkkkJyT+SuQzy5Y0ru6Ez511/Efa5s1fdkOtyVurIxgdlQAA9gOKKPwolU7remU5hCGYEgo38KUv9I/0TRTDYJCWQBSF4rIN/CRgAR0iTpVD1j1g/qDqJcJqlKcjB9bcda142MpOEJAzgeMnjyTSyze5KEuNRpDoDvC0oe4X9iAeaKKFK+oya6fbOqYbDTeEiAPKpHdS3gBLYc7RQkp3ApQog+cq8nwPJrljzxnPZbUfnugn/NFFRgEVch9xKsH0H8pg6e3x3T3UC1ajaZITGkJLoS4MKbOUrzz/ACKVRRRVzVwtoQmhG1NkWu0HuI+JI8u/Kv/Z';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"data": {
"image": {
"base64": BYTES_STRING
},
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the location
// of the image we want as an input. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever image input you want to add
const IMAGE_FILE_LOCATION = 'YOUR_IMAGE_FILE_LOCATION';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
const fs = require("fs");
const imageBytes = fs.readFileSync(IMAGE_FILE_LOCATION);
stub.PostInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
inputs: [
{ data: { image: { base64: imageBytes } } }
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status)
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
import com.google.protobuf.ByteString;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the location
// of the image we want as an input. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to whatever image input you want to add
static final String IMAGE_FILE_LOCATION = "YOUR_IMAGE_FILE_LOCATION";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) throws IOException {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder().setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setBase64(ByteString.copyFrom(Files.readAllBytes(
new File(IMAGE_FILE_LOCATION).toPath()
)))
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the location
// of the image we want as an input. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever image input you want to add
$IMAGE_FILE_LOCATION = 'YOUR_IMAGE_FILE_LOCATION';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Image;
use Clarifai\Api\Input;
use Clarifai\Api\PostInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT ]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
$imageData = file_get_contents($IMAGE_FILE_LOCATION); // Get the image bytes data from the location
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsRequest([
'user_app_id' => $userDataObject,
'inputs' => [
new Input([ // The Input object wraps the Data object in order to meet the API specification
'data' => new Data([ // The Data object is constructed around the Image object. It offers a container that has additional image independent
// metadata. In this particular use case, no other metadata is needed to be specified
'image' => new Image([ // In the Clarifai platform, an image is defined by a special Image object
'base64' => $imageData
])
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
$response->getStatus()->getDetails());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"data": {
"image": {
"base64": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAoACgDASIAAhEBAxEB/8QAGQAAAgMBAAAAAAAAAAAAAAAAAAYDBQcE/8QAMBAAAQMDAwMDAgQHAAAAAAAAAQIDBAAFEQYSIQcTMTJBURRhCBYikSNScXKhsdH/xAAZAQACAwEAAAAAAAAAAAAAAAAFBgIDBAf/xAAtEQABAwMBBgQHAQAAAAAAAAABAgMRAAQhMQUSE0FRYQaBocEUFiJCcrHR8P/aAAwDAQACEQMRAD8A3+RYY1unSYzCS0ttZUkAgktn0q5yT7jPyDUC4wdGwycH5U2Kt9ZQ7VI1qw5PkvQy3CSVPpf7aQjuKyFH25xzn3pHn3TVNy01Hl2hyy6YdkSpKsS9sl/6RlI3rRu3dxWd6spwnAGPIJTfl925fcLaoSDHXvyo6i9SlCQrU9wKln3OyWiaDN1RAbW3kKbSd7gPtwMkH/tTWy9afuy1iPfnXMAblITwkE4yf08cn3pSbYt1uts24XH6fUbiLAuY1MWyGkLEmUW0rcCRvUpQ5CtwKQCPgi4S1ZbDe4sd9NntDEe79m3uOBLTr0IR9jzodSMqUpTu9JJ8owD7UTT4ZCfv9PbP7860m+s+HBSrejWRuz2kAxoesGYxTW/Zlpkwo1vkuSly3UgKWQUhHJUvIHsAaKTemF8XE6sWmxyZkiaZrMh1jv8ArQNpUVqB8FW0njHqx4zRVVhsph1KlKk5xQ+7uHmikaSJrQerMByet2IwvtuTLa4xv2k7Rk84H9x/esHv92d01boenLXGcuiWrFIhLlpbcaQ2/JdK3VJCkAq2pAR7Zz7YxWudY9fxNIdQbNGkR5TyX4aisNNpUMFZAzkj4NK0jq9ZpbLr0PSlzkhrlZDaQlP3P8Q4/ap3F87bPucJEkx/hHv60b2TYXLrKN5sramYECSQRk9M6c6zmJ+eb5Hi22M7cnWGIQgFLbX0zSo4PDa1YBcTgDyMjJ/qbGPabH08SJt1Uzc9QqRliGg5QySPKvgc+TyfYDmmTUWpNYz7ctxoQdPQshCktupckDJUPUcJT6DwMq8YyaQ9VL0pCS8zapcq4SVOBZmPDO8/cnknlWcDBwn4NYnPjLkQ+qE9OtOVlYpeVHDCEkkkJyT+SuQzy5Y0ru6Ez511/Efa5s1fdkOtyVurIxgdlQAA9gOKKPwolU7remU5hCGYEgo38KUv9I/0TRTDYJCWQBSF4rIN/CRgAR0iTpVD1j1g/qDqJcJqlKcjB9bcda142MpOEJAzgeMnjyTSyze5KEuNRpDoDvC0oe4X9iAeaKKFK+oya6fbOqYbDTeEiAPKpHdS3gBLYc7RQkp3ApQog+cq8nwPJrljzxnPZbUfnugn/NFFRgEVch9xKsH0H8pg6e3x3T3UC1ajaZITGkJLoS4MKbOUrzz/ACKVRRRVzVwtoQmhG1NkWu0HuI+JI8u/Kv/Z",
"allow_duplicate_url": true
}
}
}
]
}'
Add Multiple Inputs With IDs
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 the metadata.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################################
# In this section, we set the user authentication, app ID, and the URLs and IDs
# of the images we want as inputs. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever inputs you want to add
IMAGE_URL_1 = 'https://samples.clarifai.com/metro-north.jpg'
IMAGE_URL_2 = 'https://samples.clarifai.com/puppy.jpeg'
INPUT_ID_1 = 'mytrain'
INPUT_ID_2 = 'mypuppy'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL_1,
allow_duplicate_url=True
)
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL_2,
allow_duplicate_url=True
)
)
),
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print("There was an error with your request!")
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)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the URLs and IDs
// of the images we want as inputs. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever inputs you want to add
const IMAGE_URL_1 = 'https://samples.clarifai.com/metro-north.jpg';
const IMAGE_URL_2 = 'https://samples.clarifai.com/puppy.jpeg';
const INPUT_ID_1 = 'input1';
const INPUT_ID_2 = 'puppy1';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"data": {
"image": {
"url": IMAGE_URL_1,
"allow_duplicate_url": true
}
},
"id": INPUT_ID_1
},
{
"data": {
"image": {
"url": IMAGE_URL_2,
"allow_duplicate_url": true
}
},
"id": INPUT_ID_2
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the URLs and IDs
// of the images we want as inputs. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever inputs you want to add
const IMAGE_URL_1 = 'https://samples.clarifai.com/metro-north.jpg';
const IMAGE_URL_2 = 'https://samples.clarifai.com/puppy.jpeg';
const INPUT_ID_1 = 'train1';
const INPUT_ID_2 = 'puppy1';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
inputs: [
{
id: INPUT_ID_1,
data: {image: {url: IMAGE_URL_1, allow_duplicate_url: true}}
},
{
id: INPUT_ID_2,
data: {image: {url: IMAGE_URL_2, 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);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the URLs and IDs
// of the images we want as inputs. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever inputs you want to add
static final String IMAGE_URL_1 = "https://samples.clarifai.com/metro-north.jpg";
static final String IMAGE_URL_2 = "https://samples.clarifai.com/puppy.jpeg";
static final String INPUT_ID_1 = "train1";
static final String INPUT_ID_2 = "puppy1";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder()
.setId(INPUT_ID_1)
.setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setUrl(IMAGE_URL_1)
.setAllowDuplicateUrl(true)
)
)
)
.addInputs(
Input.newBuilder()
.setId(INPUT_ID_2)
.setData(
Data.newBuilder().setImage(
Image.newBuilder()
.setUrl(IMAGE_URL_2)
.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());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the URLs and IDs
// of the images we want as inputs. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever inputs you want to add
$IMAGE_URL_1 = "https://samples.clarifai.com/metro-north.jpg";
$IMAGE_URL_2 = "https://samples.clarifai.com/puppy.jpeg";
$INPUT_ID_1 = "train1";
$INPUT_ID_2 = "puppy1";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Image;
use Clarifai\Api\Input;
use Clarifai\Api\PostInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsRequest([
"user_app_id" => $userDataObject,
"inputs" => [
new Input([
// The Input object wraps the Data object in order to meet the API specification
"id" => $INPUT_ID_1,
"data" => new Data([
// The Data object is constructed around the Image object. It offers a container that has additional image independent
// metadata. In this particular use case, no other metadata is needed to be specified
"image" => new Image([
// In the Clarifai platform, an image is defined by a special Image object
"url" => $IMAGE_URL_1,
"allow_duplicate_url" => true
])
])
]),
new Input([
"id" => $INPUT_ID_2,
"data" => new Data([
"image" => new Image([
"url" => $IMAGE_URL_2,
"allow_duplicate_url" => true
])
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print "There was an error with your request!" . "<br>";
foreach ($response->getInputs() as $input_object) {
print "Input " . $input_object->getId() . " status: ";
print $input_object->getStatus()->getDetails() . "<br>";
}
throw new Exception("Post inputs failed, status: " . $response->getStatus()->getDescription());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg",
"allow_duplicate_url": true
}
},
"id": "train1"
},
{
"data": {
"image": {
"url": "https://samples.clarifai.com/puppy.jpeg",
"allow_duplicate_url": true
}
},
"id": "puppy1"
}
]
}'
Add Inputs With Concepts
If you would like to add an input with concepts, you can do so. Concepts play an important role in creating your own models.
You can learn more about creating your own models here.
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 not.
You can add inputs with concepts via URLs or bytes.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################################
# In this section, we set the user authentication, app ID, and the input to add
# with concept. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever input and concept you want to add
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
CONCEPT_ID = 'charlie'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
concepts=[resources_pb2.Concept(id=CONCEPT_ID, value=1.)]
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input to add
// with concept. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever input and concept you want to add
const IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
const CONCEPT_ID = 'charlie';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"data": {
"image": {
"url": IMAGE_URL,
"allow_duplicate_url": true
},
// Optionally add a concept with your input
"concepts": [
{
"id": CONCEPT_ID,
"value": 1
}
]
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input to add
// with concept. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever input and concept you want to add
const IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
const CONCEPT_ID = 'charlie';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
inputs: [{
data: {
image: { url: IMAGE_URL, allow_duplicate_url: true },
concepts: [{ id: CONCEPT_ID, 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);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input to add
// with concept. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever input and concept you want to add
static final String IMAGE_URL = "https://samples.clarifai.com/puppy.jpeg";
static final String CONCEPT_ID = "charlie";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder().setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl(IMAGE_URL)
.setAllowDuplicateUrl(true)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID)
.setValue(1f)
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input to add
// with concept. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever input and concept you want to add
$IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
$CONCEPT_ID = 'charlie';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\Api\Concept;
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Image;
use Clarifai\Api\Input;
use Clarifai\Api\PostInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsRequest([
"user_app_id" => $userDataObject,
"inputs" => [
new Input([
// The Input object wraps the Data object in order to meet the API specification
"data" => new Data([
// The Data object is constructed around the Image object. It offers a container that has additional image independent
// metadata. In this particular use case, no other metadata is needed to be specified
"image" => new Image([
// In the Clarifai platform, an image is defined by a special Image object
"url" => $IMAGE_URL,
"allow_duplicate_url" => true
]),
"concepts" => [
new Concept([
"id" => $CONCEPT_ID,
"value" => 1
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/puppy.jpeg",
"allow_duplicate_url": true
},
"concepts":[
{
"id": "charlie",
"value": 1
}
]
}
}
]
}'
Add Inputs With Multiple Concepts
You can also add an input with multiple concepts in a single API call. You can provide the concepts in a list and iterate through it.
You can add the inputs via URLs or bytes.
- Python
- JavaScript (REST)
- NodeJS
##################################################################################
# In this section, we set the user authentication, app ID, and the input to add
# with concepts. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever input and concepts you want to add
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six']
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
# We use Python list comprehension to iterate through the list of concepts
concepts=[resources_pb2.Concept(id=str(i), value=1.) for i in CONCEPT_IDS_LIST]
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input to add
// with concepts. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever input and concepts you want to add
const IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
const CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six'];
// We use a map function to iterate through the list of concepts
const myFunction = () => {
return CONCEPT_IDS_LIST.map((concept)=>({"id":concept,"value":1}));
}
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"data": {
"image": {
"url": IMAGE_URL,
"allow_duplicate_url": true
},
"concepts": myFunction()
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input to add
// with concepts. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever input and concepts you want to add
const IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
const CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six'];
// We use a map function to iterate through the list of concepts
const myFunction = () => {
return CONCEPT_IDS_LIST.map((concept) => ({"id":concept,"value":1}));
}
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
inputs: [{
data: {
image: { url: IMAGE_URL, allow_duplicate_url: true },
concepts: myFunction()
}
}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
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.
If you have more than one item per image, it is recommended to put the id
in the metadata like:
{
"product_id": "xyz"
}
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
####################################################################################
# In this section, we set the user authentication, app ID, and the custom metadata
# and input we want to add. Change these strings to run your own example.
####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever input and custom metadata you want to add
CUSTOM_METADATA = {"id": "id001", "type": "animal", "size": 100}
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
input_metadata = Struct()
input_metadata.update(CUSTOM_METADATA)
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
metadata=input_metadata
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and custom
// metadata we want to add. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever input and custom metadata you want to add
const IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
const CUSTOM_METADATA = { "id": "id001", "type": "animal", "size": 100 };
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"data": {
"image": {
"url": IMAGE_URL,
"allow_duplicate_url": true
},
"metadata": CUSTOM_METADATA
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and custom
// metadata we want to add. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever input and custom metadata you want to add
const IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg';
const CUSTOM_METADATA = { id: "id001", type: "animal", size: 100 };
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
inputs: [{
data: {
image: { url: IMAGE_URL, allow_duplicate_url: true },
metadata: CUSTOM_METADATA
}
}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input
// we want to add. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to whatever input you want to add
static final String IMAGE_URL = "https://samples.clarifai.com/puppy.jpeg";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder().setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl(IMAGE_URL)
.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());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and custom
// metadata we want to add. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever input and custom metadata you want to add
$IMAGE_URL = "https://samples.clarifai.com/puppy.jpeg";
$CUSTOM_METADATA = '{"id": "id001", "type": "animal", "size": 100}';
// Decode a JSON object into a PHP object
$CUSTOM_METADATA_DECODE = var_dump(json_decode($CUSTOM_METADATA));
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Image;
use Clarifai\Api\Input;
use Clarifai\Api\PostInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsRequest([
"user_app_id" => $userDataObject,
"inputs" => [
new Input([
// The Input object wraps the Data object in order to meet the API specification
"data" => new Data([
// The Data object is constructed around the Image object. It offers a container that has additional image independent
// metadata. In this particular use case, no other metadata is needed to be specified
"image" => new Image([
// In the Clarifai platform, an image is defined by a special Image object
"url" => $IMAGE_URL,
"allow_duplicate_url" => true
]),
"metadata" => $CUSTOM_METADATA_DECODE
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/puppy.jpeg",
"allow_duplicate_url": true
},
"metadata": {"id": "id001", "type": "animal", "size": 100}
}
}
]
}'
Add Inputs From Cloud Storage
You can add inputs from various cloud storage platforms, such as S3 (Amazon Simple Storage Service) and GCP (Google Cloud Platform), by simply providing their corresponding URLs. In cases where access credentials are necessary, you can include them as part of the request.
This simplifies the process of adding inputs to our platform, offering a more efficient alternative to the conventional method of using the PostInputs endpoint for users who already have data stored in the cloud platforms.
This functionality has been introduced starting from the 10.1 release.
-
Image files stored in the cloud platforms will be treated as image inputs, video files as video inputs, etc. Archives will be extracted, and their contents will also be processed like this.
-
We do not support extraction of archives located inside other archives.
-
The cloud URL will serve as a filter prefix. For instance, in the case of an S3 URL like
s3:/bucket/images_folder/abc
, files within theimages_folder
will be processed starting withabc
, or within a subfolder beginning withabc
. For example, files such asbucket/images_folder/abcImage.png
orbucket/images_folder/abc-1/Data.zip
will be processed accordingly.
Add Inputs via Cloud Storage URLs
Below is an example of pulling inputs from a subfolder of an S3 bucket.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
######################################################################################################
# In this section, we set the user authentication, app ID, ID to collect statistics about inputs job
# to be created, and cloud storage URL. Change these strings to run your own example.
######################################################################################################
USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change these to create your own extraction job
INPUTS_JOB_ID = "" # If empty, ID will be autogenerated; if non-empty, the given ID will be used
CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (("authorization", "Key " + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_inputs_response = stub.PostInputsDataSources(
service_pb2.PostInputsDataSourcesRequest(
user_app_id=userDataObject,
app_pat=PAT,
data_sources=[
resources_pb2.InputsDataSource(
inputs_add_job_id=INPUTS_JOB_ID,
url=resources_pb2.DataSourceURL(
url=CLOUD_STORAGE_URL,
# Uncomment to add credentials
# credentials=resources_pb2.DataSourceCredentials(
# s3_creds=resources_pb2.AWSCreds(
# id="ADD_ACCESS_ID_HERE",
# secret="ADD_SECRET_HERE",
# region="ADD_AWS_REGION_HERE"
# )
# If using GCP
# gcpCreds="" # GCP uses service account key data (creds.json) as Byte array for authentication
# ),
),
)
],
),
metadata=metadata,
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception(
"Post inputs failed, status: " + post_inputs_response.status.description
)
print(post_inputs_response)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, ID to collect statistics about inputs job
// to be created, and cloud storage URL. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change these to create your own extraction job
const INPUTS_JOB_ID = ""; // If empty, ID will be autogenerated; if non-empty, the given ID will be used
const CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"app_pat": PAT,
"data_sources": [
{
"inputs_add_job_id": INPUTS_JOB_ID,
"url": {
"url": CLOUD_STORAGE_URL,
// Uncomment to add credentials
/* "credentials": {
"s3_creds": { "id": "ADD_ACCESS_ID_HERE", "secret": "ADD_SECRET_HERE", "region": "ADD_AWS_REGION_HERE" }
}*/
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs/data_sources/", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, ID to collect statistics about inputs job
// to be created, and cloud storage URL. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change these to create your own extraction job
const INPUTS_JOB_ID = ""; // If empty, ID will be autogenerated; if non-empty, the given ID will be used
const CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputsDataSources(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
"app_pat": PAT,
"data_sources": [
{
"inputs_add_job_id": INPUTS_JOB_ID,
"url": {
"url": CLOUD_STORAGE_URL,
// Uncomment to add credentials
/* "credentials": {
"s3_creds": { "id": "ADD_ACCESS_ID_HERE", "secret": "ADD_SECRET_HERE", "region": "ADD_AWS_REGION_HERE" }
}*/
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post inputs failed, status: " + response.status.description);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, ID to collect statistics about inputs job
// to be created, and cloud storage URL. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to create your own extraction job
static final String INPUTS_JOB_ID = ""; // If empty, ID will be autogenerated; if non-empty, the given ID will be used
static final String CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputsAddJobResponse postInputsResponse = stub.postInputsDataSources(
PostInputsDataSourcesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAppPat(PAT)
.addDataSources(InputsDataSource.newBuilder().setInputsAddJobId(INPUTS_JOB_ID)
.setUrl(DataSourceURL.newBuilder()
.setUrl(CLOUD_STORAGE_URL)
// Uncomment to add credentials
/*.setCredentials(DataSourceCredentials.newBuilder()
.setS3Creds(AWSCreds.newBuilder()
.setId("ADD_ACCESS_ID_HERE")
.setSecret("ADD_SECRET_HERE")
.setRegion("ADD_AWS_REGION_HERE")
)
)*/
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
System.out.println(postInputsResponse);
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, ID to collect statistics about inputs job
// to be created, and cloud storage URL. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
# Change these to create your own extraction job
$INPUTS_JOB_ID = ''; # If empty, ID will be autogenerated; if non-empty, the given ID will be used
$CLOUD_STORAGE_URL = 's3://samples.clarifai.com/storage/';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostInputsDataSourcesRequest;
use Clarifai\Api\InputsDataSource;
use Clarifai\Api\DataSourceURL;
use Clarifai\Api\DataSourceCredentials;
use Clarifai\Api\AWSCreds;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputsDataSources(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsDataSourcesRequest([
'user_app_id' => $userDataObject,
'app_pat' => $PAT,
'data_sources' => [
new InputsDataSource([
'inputs_add_job_id' => $INPUTS_JOB_ID,
'url' => new DataSourceURL([
'url' => $CLOUD_STORAGE_URL,
// Uncomment to add credentials
/*'credentials' => new DataSourceCredentials([
's3_creds' => new AWSCreds([
'id' => 'ADD_ACCESS_ID_HERE',
'secret' => 'ADD_SECRET_HERE',
'region' => 'ADD_AWS_REGION_HERE'
])
])*/
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
$response->getStatus()->getDetails());
}
echo $response->serializeToJsonString();
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/data_sources/" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"app_pat": "YOUR_PAT_HERE",
"data_sources": [
{
"inputs_add_job_id": "",
"url": {
"url": "s3://samples.clarifai.com/storage/",
"credentials": {
"s3_creds": {"id":"ADD_ACCESS_ID_HERE", "secret":"ADD_SECRET_HERE", "region":"ADD_AWS_REGION_HERE"},
// Or, you can use GCP credentials
"gcpCreds": "" // GCP uses service account key data (creds.json) as Byte array for authentication
}
}
}
]
}'
Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "8759d87e31403bbd838794fe6016f36d"
}
inputs_add_jobs {
id: "2581ebd8d7cd42e7ac0da2bec14d5426"
progress {
}
created_at {
seconds: 1708361354
nanos: 820114719
}
modified_at {
seconds: 1708361354
nanos: 847655746
}
extraction_jobs {
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
id: "2a6f1f69cced42029986a72009e7d4da"
url: "s3://samples.clarifai.com/storage/"
progress {
}
created_at {
seconds: 1708361354
nanos: 835105396
}
modified_at {
seconds: 1708361354
nanos: 835105396
}
}
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
}
Track Upload Process
After starting to pull the inputs from a cloud storage service, you can track the progress of the exercise. Note that we’ll use the inputs_extraction_job_id
returned after running the extraction job.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################################################
# In this section, we set the user authentication, app ID, and the inputs extraction job ID.
# Change these strings to run your own example.
###################################################################################################
USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change this ID to whatever inputs you want to track their upload process
INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (("authorization", "Key " + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
get_inputs_extraction_response = stub.GetInputsExtractionJob(
service_pb2.GetInputsExtractionJobRequest(
user_app_id=userDataObject,
inputs_extraction_job_id=INPUTS_EXTRACTION_JOB_ID
),
metadata=metadata,
)
if get_inputs_extraction_response.status.code != status_code_pb2.SUCCESS:
print(get_inputs_extraction_response.status)
raise Exception(
"Get input failed, status: " + get_inputs_extraction_response.status.description
)
print(get_inputs_extraction_response)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever inputs you want to track their upload process
const INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/jobs/extraction/${INPUTS_EXTRACTION_JOB_ID}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever inputs you want to track their upload process
const INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.GetInputsExtractionJob(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs_extraction_job_id": INPUTS_EXTRACTION_JOB_ID
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Get inputs failed, status: " + response.status.description);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever inputs you want to track their upload process
static final String INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
SingleInputsExtractionJobResponse getInputsResponse = stub.getInputsExtractionJob(
GetInputsExtractionJobRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setInputsExtractionJobId(INPUTS_EXTRACTION_JOB_ID)
.build()
);
if (getInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + getInputsResponse.getStatus());
}
System.out.println(getInputsResponse);
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
// Change this ID to whatever inputs you want to track their upload process
$INPUTS_EXTRACTION_JOB_ID = '2a6f1f69cced42029986a72009e7d4da';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\GetInputsExtractionJobRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->GetInputsExtractionJob(
// The request object carries the request along with the request status and other metadata related to the request itself
new GetInputsExtractionJobRequest([
'user_app_id' => $userDataObject,
'inputs_extraction_job_id' => $INPUTS_EXTRACTION_JOB_ID
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception('Error: {$status->details}');
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception('Failure response: ' . $response->getStatus()->getDescription() . ' ' .
$response->getStatus()->getDetails());
}
echo $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/jobs/extraction/YOUR_INPUTS_EXTRACTION_JOB_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "bae1f832c8931d47388f875653e7035d"
}
inputs_extraction_job {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "2a6f1f69cced42029986a72009e7d4da"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708361354
nanos: 835105000
}
modified_at {
seconds: 1708361355
nanos: 386004000
}
}
List Inputs Extraction Jobs
You can list all your inputs extraction jobs and get their details.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
###################################################################
USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (("authorization", "Key " + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_inputs_extraction_jobs = stub.ListInputsExtractionJobs(
service_pb2.ListInputsExtractionJobsRequest(
user_app_id=userDataObject, per_page=1000, page=1
),
metadata=metadata,
)
if list_inputs_extraction_jobs.status.code != status_code_pb2.SUCCESS:
print(list_inputs_extraction_jobs.status)
raise Exception(
"List input failed, status: " + list_inputs_extraction_jobs.status.description
)
print(list_inputs_extraction_jobs)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/jobs/extraction?per_page=1000&page=1`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListInputsExtractionJobs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
per_page: 1000,
page: 1
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("List inputs failed, status: " + response.status.description);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputsExtractionJobResponse listInputsResponse = stub.listInputsExtractionJobs(
ListInputsExtractionJobsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setPerPage(100).setPage(1)
.build()
);
if (listInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List inputs failed, status: " + listInputsResponse.getStatus());
}
System.out.println(listInputsResponse);
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
///////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListInputsExtractionJobsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListInputsExtractionJobs(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListInputsExtractionJobsRequest([
'user_app_id' => $userDataObject,
'per_page'=> 1000,
'page'=> 1
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception('Error: {$status->details}');
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception('Failure response: ' . $response->getStatus()->getDescription() . ' ' .
$response->getStatus()->getDetails());
}
echo $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/jobs/extraction?per_page=1000&page=1" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
Output Example
----
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "487d863784804390a92e1108ee1ae1fb"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708406450
nanos: 685101000
}
modified_at {
seconds: 1708406451
nanos: 191007000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "16d65cdff5d64ae8ba94ae59f5d7f43c"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708406156
nanos: 2926000
}
modified_at {
seconds: 1708406156
nanos: 560108000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "423b4dfa36f64fffbe79cf845918d4c0"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708405684
nanos: 297689000
}
modified_at {
seconds: 1708405684
nanos: 778885000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "a5af6a185ab148d4b7eb02e713d3340d"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708405639
nanos: 186106000
}
modified_at {
seconds: 1708405639
nanos: 696943000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "1c10da09706d40448bf11fc5aaa8664b"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708405297
nanos: 953730000
}
modified_at {
seconds: 1708405298
nanos: 506209000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "10ad7ba72e5e49899a042637178c9452"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708404787
nanos: 575667000
}
modified_at {
seconds: 1708404788
nanos: 141744000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "8d7a240f39494ce18c3a5f4aeea687c1"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708403207
nanos: 89134000
}
modified_at {
seconds: 1708403207
nanos: 729276000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "2a6f1f69cced42029986a72009e7d4da"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708361354
nanos: 835105000
}
modified_at {
seconds: 1708361355
nanos: 386004000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "6db64516daf04abd97852407f9076e42"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708361312
nanos: 309789000
}
modified_at {
seconds: 1708361313
nanos: 435552000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "7e4bd42e84294e8f9423e0a01783e3b1"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708354769
nanos: 17131000
}
modified_at {
seconds: 1708354769
nanos: 473323000
}
input_template {
data {
concepts {
id: "lamborghini23_A"
value: 1
}
concepts {
id: "spiderman_a"
value: 1
}
metadata {
fields {
key: "id"
value {
string_value: "id001"
}
}
}
}
dataset_ids: "dataset-1"
}
}
-----
Cancel Extraction Jobs
You can cancel the process of extraction of inputs from a cloud storage service. Note that we’ll use the inputs_extraction_job_id
returned after starting the extraction process.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#####################################################################################################
# In this section, we set the user authentication, app ID, and the inputs extraction job ID.
# Change these strings to run your own example.
#####################################################################################################
USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change this ID to whatever inputs you want to cancel their upload process
INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (("authorization", "Key " + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
cancel_inputs_extraction_response = stub.CancelInputsExtractionJobs(
service_pb2.CancelInputsExtractionJobsRequest(
user_app_id=userDataObject, ids=[INPUTS_EXTRACTION_JOB_ID]
),
metadata=metadata,
)
if cancel_inputs_extraction_response.status.code != status_code_pb2.SUCCESS:
print(cancel_inputs_extraction_response.status)
raise Exception(
"Cancel input failed, status: "
+ cancel_inputs_extraction_response.status.description
)
print(cancel_inputs_extraction_response)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever inputs you want to cancel their upload process
const INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/jobs/extraction/${INPUTS_EXTRACTION_JOB_ID}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever inputs you want to cancel their upload process
const INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.CancelInputsExtractionJobs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
ids: [INPUTS_EXTRACTION_JOB_ID]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("List inputs failed, status: " + response.status.description);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever inputs you want to cancel their upload process
static final String INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputsExtractionJobResponse cancelInputsResponse = stub.cancelInputsExtractionJobs(
CancelInputsExtractionJobsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addIds(INPUTS_EXTRACTION_JOB_ID)
.build()
);
if (cancelInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + cancelInputsResponse.getStatus());
}
System.out.println(cancelInputsResponse);
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
///////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs extraction job ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
// Change this ID to whatever inputs you want to cancel their upload process
$INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\CancelInputsExtractionJobsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->CancelInputsExtractionJobs(
// The request object carries the request along with the request status and other metadata related to the request itself
new CancelInputsExtractionJobsRequest([
'user_app_id' => $userDataObject,
'ids' => [$INPUTS_EXTRACTION_JOB_ID]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception('Error: {$status->details}');
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception('Failure response: ' . $response->getStatus()->getDescription() . ' ' .
$response->getStatus()->getDetails());
}
echo $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/jobs/extraction/YOUR_INPUTS_EXTRACTION_JOB_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
Add Inputs With Concepts and Datasets
You can also add inputs from cloud storage platforms while attaching relevant concepts, assigning them to an already existing dataset, or adding other metadata information to them.
The input_template
parameter allows you to do that.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#####################################################################################################
# In this section, we set the user authentication, app ID, and the details of the extraction job.
# Change these strings to run your own example.
####################################################################################################
USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change these to make your own extraction
INPUTS_JOB_ID = ""
CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/"
CUSTOM_METADATA = {"id": "id001"}
DATASET_ID_1 = "dataset-1"
CONCEPT_ID_1 = "lamborghini23_A"
CONCEPT_ID_2 = "spiderman_a"
##############################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##############################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (("authorization", "Key " + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
input_metadata = Struct()
input_metadata.update(CUSTOM_METADATA)
post_inputs_response = stub.PostInputsDataSources(
service_pb2.PostInputsDataSourcesRequest(
user_app_id=userDataObject,
app_pat=PAT,
data_sources=[
resources_pb2.InputsDataSource(
inputs_add_job_id=INPUTS_JOB_ID,
url=resources_pb2.DataSourceURL(url=CLOUD_STORAGE_URL),
input_template=resources_pb2.Input(
dataset_ids=[DATASET_ID_1], # List of dataset IDs that this input is part of
data=resources_pb2.Data(
metadata=input_metadata,
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1),
resources_pb2.Concept(id=CONCEPT_ID_2, value=1),
],
),
),
)
],
),
metadata=metadata,
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception(
"Post inputs failed, status: " + post_inputs_response.status.description
)
print(post_inputs_response)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the extraction job.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change these to make your own extraction
const INPUTS_JOB_ID = "";
const CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/";
const CUSTOM_METADATA = { "id": "id001" };
const DATASET_ID_1 = "dataset-1";
const CONCEPT_ID_1 = "lamborghini23_A";
const CONCEPT_ID_2 = "spiderman_a";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"app_pat": PAT,
"data_sources": [
{
"inputs_add_job_id": INPUTS_JOB_ID,
"url": {
"url": CLOUD_STORAGE_URL,
},
"input_template": {
"dataset_ids": [DATASET_ID_1],
"data": {
"metadata": CUSTOM_METADATA,
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 1
}
]
}
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs/data_sources/", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the extraction job.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change these to make your own extraction
const INPUTS_JOB_ID = "";
const CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/";
const CUSTOM_METADATA = { "id": "id001" };
const DATASET_ID_1 = "dataset-1";
const CONCEPT_ID_1 = "lamborghini23_A";
const CONCEPT_ID_2 = "spiderman_a";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputsDataSources(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
"app_pat": PAT,
"data_sources": [
{
"inputs_add_job_id": INPUTS_JOB_ID,
"url": {
"url": CLOUD_STORAGE_URL
},
"input_template": {
"dataset_ids": [DATASET_ID_1],
"data": {
"metadata": CUSTOM_METADATA,
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 1
}
]
}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post inputs failed, status: " + response.status.description);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the extraction job.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to make your own extraction
static final String INPUTS_JOB_ID = "";
static final String CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/";
static final String CUSTOM_METADATA_1 = "id";
static final String CUSTOM_METADATA_2 = "id001";
static final String DATASET_ID_1 = "dataset-1";
static final String CONCEPT_ID_1 = "lamborghini23_A";
static final String CONCEPT_ID_2 = "spiderman_a";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputsAddJobResponse postInputsResponse = stub.postInputsDataSources(
PostInputsDataSourcesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAppPat(PAT)
.addDataSources(InputsDataSource.newBuilder().setInputsAddJobId(INPUTS_JOB_ID)
.setUrl(DataSourceURL.newBuilder()
.setUrl(CLOUD_STORAGE_URL)
)
.setInputTemplate(Input.newBuilder()
.addDatasetIds(DATASET_ID_1)
.setData(Data.newBuilder()
.setMetadata(
Struct.newBuilder()
.putFields(CUSTOM_METADATA_1, Value.newBuilder().setStringValue(CUSTOM_METADATA_2).build())
)
.addConcepts(Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f)
)
.addConcepts(Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(1f)
)
))
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
System.out.println(postInputsResponse);
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the extraction job.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = 'YOUR_PAT_HERE';
$APP_ID = 'YOUR_APP_ID_HERE';
// Change these to make your own extraction
$INPUTS_JOB_ID = '';
$CLOUD_STORAGE_URL = 's3://samples.clarifai.com/storage/';
$CUSTOM_METADATA = '{"id": "id001"}';
$DATASET_ID_1 = 'dataset-1';
$CONCEPT_ID_1 = 'lamborghini23_A';
$CONCEPT_ID_2 = 'spiderman_a';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostInputsDataSourcesRequest;
use Clarifai\Api\InputsDataSource;
use Clarifai\Api\DataSourceURL;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Input;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ['Authorization' => ['Key ' . $PAT]];
$userDataObject = new UserAppIDSet([
'user_id' => $USER_ID,
'app_id' => $APP_ID
]);
// Decode the JSON object into a PHP object
$CUSTOM_METADATA_DECODE = var_dump(json_decode($CUSTOM_METADATA));
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostInputsDataSources(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostInputsDataSourcesRequest([
'user_app_id' => $userDataObject,
'app_pat' => $PAT,
'data_sources' => [
new InputsDataSource([
'inputs_add_job_id' => $INPUTS_JOB_ID,
'url' => new DataSourceURL([
'url' => $CLOUD_STORAGE_URL,
]),
'input_template' => new Input([
'dataset_ids' => [$DATASET_ID_1],
'data' => new Data([
'metadata' => $CUSTOM_METADATA_DECODE,
'concepts' => [
new Concept([
'id' => $CONCEPT_ID_1,
'value' => 1
]),
new Concept([
'id' => $CONCEPT_ID_2,
'value' => 1
])
]
])
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
$response->getStatus()->getDetails());
}
echo $response->serializeToJsonString();
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/data_sources/" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"app_pat": "YOUR_PAT_HERE",
"data_sources": [
{
"inputs_add_job_id": "",
"url": {
"url": "s3://samples.clarifai.com/storage/"
},
"input_template": {
"dataset_ids": ["dataset-1"],
"data": {
"metadata": { "id": "id001" },
"concepts": [
{
"id": "lamborghini23_A",
"value": 1
},
{
"id": "spiderman_a",
"value": 1
}
]
}
}
}
]
}'
Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "32694c6a3ef8fe3f6704502c0b053734"
}
inputs_add_jobs {
id: "66b5ca001e754111a81c4839cdabed10"
progress {
}
created_at {
seconds: 1708500170
nanos: 508992497
}
modified_at {
seconds: 1708500170
nanos: 582792601
}
extraction_jobs {
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
id: "7e9b139f65fb4426a3d273d609758d34"
url: "s3://samples.clarifai.com/storage/"
progress {
}
created_at {
seconds: 1708500170
nanos: 550291872
}
modified_at {
seconds: 1708500170
nanos: 550291872
}
input_template {
data {
concepts {
id: "lamborghini23_A"
value: 1
}
concepts {
id: "spiderman_a"
value: 1
}
metadata {
fields {
key: "id"
value {
string_value: "id001"
}
}
}
}
dataset_ids: "dataset-1"
}
}
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
}
List Inputs
List all Inputs
You can list all the inputs (images) you 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.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###############################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
###############################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_inputs_response = stub.ListInputs(
service_pb2.ListInputsRequest(
user_app_id=userDataObject,
page=1,
per_page=10
),
metadata=metadata
)
if list_inputs_response.status.code != status_code_pb2.SUCCESS:
print(list_inputs_response.status)
raise Exception("List inputs failed, status: " + list_inputs_response.status.description)
for input_object in list_inputs_response.inputs:
print(input_object)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs?page=1&per_page=10`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
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));
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse listInputsResponse = stub.listInputs(
ListInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.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);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListInputsRequest([
"user_app_id" => $userDataObject,
"page" => 1,
"per_page" => 10
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getInputs() as $input_object){
print $input_object->getId() . "<br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs?page=1&per_page=10" \
-H "Authorization: Key YOUR_PAT_HERE"
List Inputs (Streaming)
This is another method for listing inputs, which was built to scalably list an 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.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
###############################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
###############################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
# To start from beginning, do not provide the last_id parameter.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(
user_app_id=userDataObject,
per_page=5,
# descending = True # Set to reverse order
),
metadata=metadata
)
if stream_inputs_response.status.code != status_code_pb2.SUCCESS:
print(stream_inputs_response.status)
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(
user_app_id=userDataObject,
per_page=5,
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)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
}
// We can implement the API call with a Promise
const streamInputs = (reqAddress) => {
return new Promise(async (resolve, reject) => {
fetch(reqAddress, requestOptions)
.then(data => {
return data.json()
}).then(data => {
resolve(data)
}).catch(e => {
console.error('REQUEST -> ', e)
reject(e)
})
})
}
// Async function that will allow us to wait for the first API call
const run = async () => {
const REQ_ADDRESS = `https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/stream?per_page=5`
const req1 = await streamInputs(REQ_ADDRESS)
// Grab the last input_id from the first request to use it in the second request
const lastId = req1['inputs'][req1['inputs'].length - 1].id
const req2 = await streamInputs(REQ_ADDRESS + `&last_id=${lastId}`)
// You're only receiving the inputs from up to the last_id onward
console.log(req2)
}
run()
</script>
//index.js file
//////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.StreamInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
per_page: 10
},
metadata,
(err, firstResponse) => {
if (err) {
throw new Error(err);
}
if (firstResponse.status.code !== 10000) {
throw new Error("Received status: " + firstResponse.status.description + "\n" + firstResponse.status.details);
}
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(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
last_id: lastId,
per_page: 10
},
metadata,
(err, secondResponse) => {
if (err) {
throw new Error(err);
}
if (secondResponse.status.code !== 10000) {
throw new Error("Received status: " + secondResponse.status.description + "\n" + secondResponse.status.details);
}
console.log("Second response (first input is the one following input ID " + lastId + ")");
for (const input of secondResponse.inputs) {
console.log("\t" + input.id);
}
}
);
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
import java.util.List;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
// To start from beginning, do not provide the last ID parameter.
MultiInputResponse firstStreamInputsResponse = stub.streamInputs(
StreamInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.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()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.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());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\StreamInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->StreamInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new StreamInputsRequest([
"user_app_id" => $userDataObject,
"per_page" => 5
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
print "First response (starting from the first input): <br>";
foreach ($response->getInputs() as $input_object){
print $input_object->getId() . "<br>";
}
$last_id = $response->getInputs()[count($response->getInputs())-1]->getId();
// Set last_id to get the next set of inputs. The returned inputs will not include the last_id input
[$response, $status] = $client->StreamInputs(
new StreamInputsRequest([
"user_app_id" => $userDataObject,
"per_page" => 5,
"last_id" => $last_id
]),
$metadata
)->wait();
print "<br>";
print "Second response (first input is the one following input ID $last_id): <br>";
foreach ($response->getInputs() as $input_object){
print $input_object->getId() . "<br>";
}
?>
Get Inputs
Get Input by ID
If you'd like to get the details of a specific input by its id
, you can do that as well.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###############################################################################
# In this section, we set the user authentication, app ID, and the input's ID
# Change these strings to run your own example.
###############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this ID to whatever input you want its details
INPUT_ID = 'eec128fd81974543bafff48702edca4d'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
get_input_response = stub.GetInput(
service_pb2.GetInputRequest(
user_app_id=userDataObject,
input_id=INPUT_ID
),
metadata=metadata
)
if get_input_response.status.code != status_code_pb2.SUCCESS:
print(get_input_response.status)
raise Exception("Get input failed, status: " + get_input_response.status.description)
input_object = get_input_response.input
print(input_object)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this ID to whatever input you want its details
const INPUT_ID = 'ff79664eefe94db1878f51931f9d6fd9';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/${INPUT_ID}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this ID to whatever input you want its details
const INPUT_ID = 'ff79664eefe94db1878f51931f9d6fd9';
////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.GetInput(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_id: 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));
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever input you want its details
static final String INPUT_ID = "ff79664eefe94db1878f51931f9d6fd9";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
SingleInputResponse getInputResponse = stub.getInput(
GetInputRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setInputId(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);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change this ID to whatever input you want its details
$INPUT_ID = 'ff79664eefe94db1878f51931f9d6fd9';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\GetInputRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->GetInput(
// The request object carries the request along with the request status and other metadata related to the request itself
new GetInputRequest([
"user_app_id" => $userDataObject,
"input_id"=> $INPUT_ID
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
$input_object = $response->getInput()->serializeToJsonString();
print $input_object;
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/YOUR_INPUT_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE"
Get Inputs' Status
If you add inputs in bulk, they will be procesed in the background. You can get the status of all your inputs (processed, to_process, and errors) like this:
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################
# In this section, we set the user authentication and the app ID.
# Change these strings to run your own example.
##################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
get_input_count_response = stub.GetInputCount(
service_pb2.GetInputCountRequest(
user_app_id=userDataObject
),
metadata=metadata
)
if get_input_count_response.status.code != status_code_pb2.SUCCESS:
print(get_input_count_response.status)
raise Exception("Get input count failed, status: " + get_input_count_response.status.description)
counts = get_input_count_response.counts
print(counts)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/status`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.GetInputCount(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
}
},
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));
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
SingleInputCountResponse getInputCountResponse = stub.getInputCount(
GetInputCountRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.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);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\GetInputCountRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->GetInputCount(
// The request object carries the request along with the request status and other metadata related to the request itself
new GetInputCountRequest([
"user_app_id" => $userDataObject
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
$input_object = $response->getCounts()->serializeToJsonString();
echo $input_object;
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/status" \
-H "Authorization: Key YOUR_PAT_HERE"
Update Inputs
Update Input With Concepts
To update an input with a new concept, or to change a concept value from true/false, you can do the following:
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##############################################################################
# In this section, we set the user authentication, app ID, and the input and
# concept ID we want to update. Change these strings to run your own example.
##############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the update you want to make
INPUT_ID = 'eec128fd81974543bafff48702edca4d'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="merge", # Supported actions: overwrite, merge, remove
inputs=[
resources_pb2.Input(
id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
)
]
),
metadata=metadata
)
if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID and concept IDs
// we want to update. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the update you want to make
const INPUT_ID = '7c5f489bcafe43fe8a71c68091cb64ce';
const CONCEPT_ID_1 = 'tree';
const CONCEPT_ID_2 = 'water';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"id": INPUT_ID,
"data": {
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 0
}
]
}
}
],
"action": "merge"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID and concept IDs
// we want to update. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the update you want to make
const INPUT_ID = '7c5f489bcafe43fe8a71c68091cb64ce';
const CONCEPT_ID_1 = 'tree';
const CONCEPT_ID_2 = 'water';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "merge", // Supported actions: overwrite, merge, remove
inputs: [
{
id: INPUT_ID,
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: { concepts: [{ id: CONCEPT_ID_1, value: 1 }, { id: CONCEPT_ID_2, value: 0 }] }
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID and concept IDs
// we want to update. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the update you want to make
static final String INPUT_ID = "7c5f489bcafe43fe8a71c68091cb64ce";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse patchInputsResponse = stub.patchInputs(
PatchInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("merge") // Supported actions: overwrite, merge, remove
.addInputs(
Input.newBuilder()
.setId(INPUT_ID)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
)
)
.build()
)
.build()
);
if (patchInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch inputs failed, status: " + patchInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID and concept IDs
// we want to update. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the update you want to make
$INPUT_ID = '7c5f489bcafe43fe8a71c68091cb64ce';
$CONCEPT_ID_1 = 'tree';
$CONCEPT_ID_2 = 'water';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Input;
use Clarifai\Api\Concept;
use Clarifai\Api\PatchInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchInputsRequest([
"user_app_id" => $userDataObject,
"action" => "merge", // Supported actions: overwrite, merge, remove
'inputs' => [
new Input([ // The Input object wraps the id and Data object in order to meet the API specification
"id" => $INPUT_ID,
'data' => new Data([ // The Data object is constructed around the Concept object. It offers a container that has additional concept independent
// metadata
"concepts" => [
new Concept([
"id" => $CONCEPT_ID_1,
"value" => 1 // 1 means true, this concept is present
]),
new Concept([
"id" => $CONCEPT_ID_2,
"value" => 0 // 0 means false, this concept is not present
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
# Supported actions are overwrite, merge, and remove
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"id": "YOUR_INPUT_ID_HERE",
"data": {
"concepts": [
{
"id": "tree",
"value": 1
},
{
"id": "water",
"value": 0
}
]
}
}
],
"action":"merge"
}'
Bulk Update Inputs With Concepts
You can update existing inputs using their ids
. This is useful if you'd like to add concepts to inputs after they have already been added.
Below is an example of how to update multiple inputs with concepts at once.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
################################################################################
# In this section, we set the user authentication, app ID, and the inputs and
# concepts IDs we want to update. Change these strings to run your own example.
################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the updates you want to make
INPUT_ID_1 = '2e9c4a86555d40ffb47c7b045d7e3048'
INPUT_ID_2 = '52b467c2005946cbbbe7a5eec76e29cf'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
CONCEPT_ID_3 = 'animal'
CONCEPT_ID_4 = 'fruit'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="merge", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.),
resources_pb2.Concept(id=CONCEPT_ID_4, value=0.)
]
)
),
]
),
metadata=metadata
)
if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs we want to update. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the updates you want to make
const INPUT_ID_1 = 'c99f1b557d1d43d1916b46f8ce4a0487';
const INPUT_ID_2 = '1be923b967f148dbb4e588cf4a723da1';
const CONCEPT_ID_1 = 'tree';
const CONCEPT_ID_2 = 'water';
const CONCEPT_ID_3 = 'animal';
const CONCEPT_ID_4 = 'fruit';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"id": INPUT_ID_1,
"data": {
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 0
}
]
}
},
{
"id": INPUT_ID_2,
"data": {
"concepts": [
{
"id": CONCEPT_ID_3,
"value": 1
},
{
"id": CONCEPT_ID_4,
"value": 0
}
]
}
}
],
"action": "merge"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs we want to update. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the updates you want to make
const INPUT_ID_1 = 'c99f1b557d1d43d1916b46f8ce4a0487';
const INPUT_ID_2 = '1be923b967f148dbb4e588cf4a723da1';
const CONCEPT_ID_1 = 'tree';
const CONCEPT_ID_2 = 'water';
const CONCEPT_ID_3 = 'animal';
const CONCEPT_ID_4 = 'fruit';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "merge", // Supported actions: overwrite, merge, remove.
inputs: [
{
id: INPUT_ID_1,
data: { concepts: [{ id: CONCEPT_ID_1, value: 1 }, { id: CONCEPT_ID_2, value: 0 }] }
},
{
id: INPUT_ID_2,
data: { concepts: [{ id: CONCEPT_ID_3, value: 1 }, { id: CONCEPT_ID_4, value: 0 }] }
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input ID and concept IDs
// we want to update. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";;
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the updates you want to make
static final String INPUT_ID_1 = "c99f1b557d1d43d1916b46f8ce4a0487";
static final String INPUT_ID_2 = "1be923b967f148dbb4e588cf4a723da1";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "animal";
static final String CONCEPT_ID_4 = "fruit";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse patchInputsResponse = stub.patchInputs(
PatchInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("merge") // Supported actions: overwrite, merge, remove
.addInputs(
Input.newBuilder()
.setId(INPUT_ID_1)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
)
)
.build()
)
.addInputs(
Input.newBuilder()
.setId(INPUT_ID_2)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_4)
.setValue(0f)
)
)
.build()
)
.build()
);
if (patchInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch inputs failed, status: " + patchInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs we want to update. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the updates you want to make
$INPUT_ID_1 = 'c99f1b557d1d43d1916b46f8ce4a0487';
$INPUT_ID_2 = '1be923b967f148dbb4e588cf4a723da1';
$CONCEPT_ID_1 = 'tree';
$CONCEPT_ID_2 = 'water';
$CONCEPT_ID_3 = 'animal';
$CONCEPT_ID_4 = 'fruit';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Input;
use Clarifai\Api\Concept;
use Clarifai\Api\PatchInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchInputsRequest([
"user_app_id" => $userDataObject,
"action" => "merge", // Supported actions: overwrite, merge, remove
'inputs' => [
new Input([ // The Input object wraps the id and Data object in order to meet the API specification
"id" => $INPUT_ID_1,
'data' => new Data([ // The Data object is constructed around the Concept object. It offers a container that has additional concept independent
// metadata
"concepts" => [
new Concept([
"id" => $CONCEPT_ID_1,
"value" => 1 // 1 means true, this concept is present
]),
new Concept([
"id" => $CONCEPT_ID_2,
"value" => 0 // 0 means false, this concept is not present
])
]
])
]),
new Input([
"id" => $INPUT_ID_2,
'data' => new Data([
"concepts" => [
new Concept([
"id" => $CONCEPT_ID_3,
"value" => 1
]),
new Concept([
"id" => $CONCEPT_ID_4,
"value" => 0
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
# Supported actions are overwrite, merge, and remove
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"id": "YOUR_INPUT_ID_1_HERE",
"data": {
"concepts": [
{
"id": "tree",
"value": 1
},
{
"id": "water",
"value": 0
}
]
}
},
{
"id": "YOUR_INPUT_ID_2_HERE",
"data": {
"concepts": [
{
"id": "animal",
"value": 1
},
{
"id": "fruit",
"value": 0
}
]
}
}
],
"action":"merge"
}'
Delete Inputs
Delete Concepts From an Input
To remove concepts that were already added to an input, you can do this:
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##############################################################################
# In this section, we set the user authentication, app ID, and the input and
# concept ID. Change these strings to run your own example.
##############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the concept you want to remove
INPUT_ID = '2e9c4a86555d40ffb47c7b045d7e3048'
CONCEPT_ID = 'water'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="remove", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
# We're removing the concept, so there's no need to specify
# the concept value.
resources_pb2.Concept(id=CONCEPT_ID),
]
)
)
]
),
metadata=metadata
)
if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and
// concept ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the concept you want to remove
const INPUT_ID = 'c99f1b557d1d43d1916b46f8ce4a0487';
const CONCEPT_ID = 'water';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"id": INPUT_ID,
"data": {
"concepts": [
{ "id": CONCEPT_ID }
]
}
}
],
"action": "remove"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and
// concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the concept you want to remove
const INPUT_ID = 'c99f1b557d1d43d1916b46f8ce4a0487';
const CONCEPT_ID = 'tree';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "remove", // Supported actions: overwrite, merge, remove
inputs: [
{
id: INPUT_ID,
// We're removing the concept, so there's no need to specify
// the concept value
data: { concepts: [{ id: CONCEPT_ID }] }
},
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and
// concept ID. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the concept you want to remove
static final String INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
static final String CONCEPT_ID = "tree";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse patchInputsResponse = stub.patchInputs(
PatchInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("remove") // Supported actions: overwrite, merge, remove
.addInputs(
Input.newBuilder()
.setId(INPUT_ID)
.setData(
Data.newBuilder()
.addConcepts(
// We're removing the concept, so there's no need to specify
// the concept value
Concept.newBuilder().setId(CONCEPT_ID)
)
)
.build()
)
.build()
);
if (patchInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch inputs failed, status: " + patchInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input and
// concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the concept you want to remove
$INPUT_ID = 'c99f1b557d1d43d1916b46f8ce4a0487';
$CONCEPT_ID = 'tree';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Input;
use Clarifai\Api\Concept;
use Clarifai\Api\PatchInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchInputsRequest([
"user_app_id" => $userDataObject,
"action" => "remove", // Supported actions: overwrite, merge, remove
'inputs' => [
new Input([ // The Input object wraps the id and Data object in order to meet the API specification
"id" => $INPUT_ID,
'data' => new Data([ // The Data object is constructed around the Concept object. It offers a container that has additional concept independent
// metadata
"concepts" => [
new Concept([
"id" => $CONCEPT_ID // We're removing the concept, so there's no need to specify
// the concept value
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# We're removing the concept, so no need to specify the concept value
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"id":"YOUR_INPUT_ID_HERE",
"data": {
"concepts":[
{"id":"water"}
]
}
}
],
"action":"remove"
}'
Bulk Delete Concepts From a List of Inputs
Below is an example of how to bulk delete multiple concepts from a list of inputs.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##############################################################################
# In this section, we set the user authentication, app ID, and the inputs and
# concepts IDs. Change these strings to run your own example.
##############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the concepts you want to remove
INPUT_ID_1 = '2e9c4a86555d40ffb47c7b045d7e3048'
INPUT_ID_2 = '52b467c2005946cbbbe7a5eec76e29cf'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
CONCEPT_ID_3 = 'animal'
CONCEPT_ID_4 = 'fruit'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="remove", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
concepts=[
# We're removing the concepts, so there's no need to specify
# the concept value.
resources_pb2.Concept(id=CONCEPT_ID_1),
resources_pb2.Concept(id=CONCEPT_ID_2),
]
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3),
resources_pb2.Concept(id=CONCEPT_ID_4),
]
)
),
]
),
metadata=metadata
)
if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the concepts you want to remove
const INPUT_ID_1 = 'ff79664eefe94db1878f51931f9d6fd9';
const INPUT_ID_2 = 'f54b89ef64874888a64f7016cf6f33ad';
const CONCEPT_ID_1 = 'tree';
const CONCEPT_ID_2 = 'water';
const CONCEPT_ID_3 = 'animal';
const CONCEPT_ID_4 = 'fruit';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"inputs": [
{
"id": INPUT_ID_1,
"data": {
"concepts": [
{
"id": CONCEPT_ID_1
},
{
"id": CONCEPT_ID_2
}
]
}
},
{
"id": INPUT_ID_2,
"data": {
"concepts": [
{
"id": CONCEPT_ID_3
},
{
"id": CONCEPT_ID_4
}
]
}
}
],
"action": "remove"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the concepts you want to remove
const INPUT_ID_1 = 'ff79664eefe94db1878f51931f9d6fd9';
const INPUT_ID_2 = 'f54b89ef64874888a64f7016cf6f33ad';
const CONCEPT_ID_1 = 'tree';
const CONCEPT_ID_2 = 'water';
const CONCEPT_ID_3 = 'animal';
const CONCEPT_ID_4 = 'fruit';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "remove", // Supported actions: overwrite, merge, remove
inputs: [
{
id: INPUT_ID_1,
// We're removing the concepts, so there's no need to specify
// the concept value
data: { concepts: [{ id: CONCEPT_ID_1 }, { id: CONCEPT_ID_2 }] }
},
{
id: INPUT_ID_2,
data: { concepts: [{ id: CONCEPT_ID_3 }, { id: CONCEPT_ID_4 }] }
},
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the concepts you want to remove
static final String INPUT_ID_1 = "ff79664eefe94db1878f51931f9d6fd9";
static final String INPUT_ID_2 = "f54b89ef64874888a64f7016cf6f33ad";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "animal";
static final String CONCEPT_ID_4 = "fruit";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse patchInputsResponse = stub.patchInputs(
PatchInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("remove") // Supported actions: overwrite, merge, remove
.addInputs(
Input.newBuilder()
.setId(INPUT_ID_1)
.setData(
Data.newBuilder()
// We're removing the concepts, so there's no need to specify
// the concept value
.addConcepts(
Concept.newBuilder().setId(CONCEPT_ID_1)
)
.addConcepts(
Concept.newBuilder().setId(CONCEPT_ID_2)
)
)
.build()
)
.addInputs(
Input.newBuilder()
.setId(INPUT_ID_2)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder().setId(CONCEPT_ID_3)
)
.addConcepts(
Concept.newBuilder().setId(CONCEPT_ID_4)
)
)
.build()
)
.build()
);
if (patchInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch inputs failed, status: " + patchInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the inputs and
// concepts IDs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the concepts you want to remove
$INPUT_ID_1 = 'ff79664eefe94db1878f51931f9d6fd9';
$INPUT_ID_2 = 'f54b89ef64874888a64f7016cf6f33ad';
$CONCEPT_ID_1 = 'tree';
$CONCEPT_ID_2 = 'water';
$CONCEPT_ID_3 = 'animal';
$CONCEPT_ID_4 = 'fruit';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Input;
use Clarifai\Api\Concept;
use Clarifai\Api\PatchInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchInputsRequest([
"user_app_id" => $userDataObject,
"action" => "remove", // Supported actions: overwrite, merge, remove
'inputs' => [
new Input([ // The Input object wraps the id and Data object in order to meet the API specification
"id" => $INPUT_ID_1,
'data' => new Data([ // The Data object is constructed around the Concept object. It offers a container that has additional concept independent
// metadata
"concepts" => [
new Concept([
"id" => $CONCEPT_ID_1 // We're removing the concepts, so there's no need to specify
// the concept value
]),
new Concept([
"id" => $CONCEPT_ID_2
])
]
])
]),
new Input([
"id" => $INPUT_ID_2,
'data' => new Data([
"concepts" => [
new Concept([
"id" => $CONCEPT_ID_3
]),
new Concept([
"id" => $CONCEPT_ID_4
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# We're removing the concepts, so no need to specify the concept value
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"id": "YOUR_INPUT_ID_1_HERE",
"data": {
"concepts":[
{
"id": "tree"
},
{
"id": "water"
}
]
}
},
{
"id": "YOUR_INPUT_ID_2_HERE",
"data": {
"concepts":[
{
"id": "animal"
},
{
"id": "fruit"
}
]
}
}
],
"action":"remove"
}'
Delete Input by ID
Below is an example of how to delete a single input by its id
.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##############################################################################
# In this section, we set the user authentication, app ID, and the ID of the
# input we want to delete. Change these strings to run your own example.
##############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this based on the input you want to delete
INPUT_ID = '2e9c4a86555d40ffb47c7b045d7e3048'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
delete_input_response = stub.DeleteInput(
service_pb2.DeleteInputRequest(
user_app_id=userDataObject,
input_id=INPUT_ID
),
metadata=metadata
)
if delete_input_response.status.code != status_code_pb2.SUCCESS:
print(delete_input_response.status)
raise Exception("Delete input failed, status: " + delete_input_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// input we want to delete. Change these strings to run your own example
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this based on the input you want to delete
const INPUT_ID = 'c83f332be7274f19950a87bd3e89d766';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/${INPUT_ID}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// input we want to delete. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this based on the input you want to delete
const INPUT_ID = 'ff79664eefe94db1878f51931f9d6fd9';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call+
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.DeleteInput(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_id: 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);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// input we want to delete. Change these strings to run your own example
///////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this based on the input you want to delete
static final String INPUT_ID = "ff79664eefe94db1878f51931f9d6fd9";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
BaseResponse deleteInputResponse = stub.deleteInput(
DeleteInputRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setInputId(INPUT_ID)
.build()
);
if (deleteInputResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete input failed, status: " + deleteInputResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// input we want to delete. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change this based on the input you want to delete
$INPUT_ID = 'ff79664eefe94db1878f51931f9d6fd9';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\DeleteInputRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->DeleteInput(
// The request object carries the request along with the request status and other metadata related to the request itself
new DeleteInputRequest([
"user_app_id" => $userDataObject,
'input_id' => $INPUT_ID
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/YOUR_INPUT_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE"
Delete a List of Inputs
You can also delete multiple inputs in one API call. This will happen asynchronously.
We currently support a batch size of 128 inputs per request. So, you can provide a list of 128 input IDs and delete them in one API call.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##############################################################################
# In this section, we set the user authentication, app ID, and the IDs of the
# inputs we want to delete. Change these strings to run your own example.
##############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the inputs you want to delete
INPUT_ID_1 = '97eb76d22e964c7cbbf06a51532c6fbe'
INPUT_ID_2 = '86b1272feabb45d4bcd2de51eedd729b'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
delete_inputs_response = stub.DeleteInputs(
service_pb2.DeleteInputsRequest(
user_app_id=userDataObject,
ids=[INPUT_ID_1, INPUT_ID_2]
),
metadata=metadata
)
if delete_inputs_response.status.code != status_code_pb2.SUCCESS:
print(delete_inputs_response.status)
raise Exception("Delete input failed, status: " + delete_inputs_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the IDs of the
// inputs we want to delete. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the inputs you want to delete
const INPUT_ID_1 = 'eefbb9fa8f2342d2b4f19b8083098c9e';
const INPUT_ID_2 = '148582f7916e4001b24579b89a6f6a82';
////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"ids": [INPUT_ID_1, INPUT_ID_2]
});
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/inputs", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the IDs of the
// inputs we want to delete. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the inputs you want to delete
const INPUT_ID_1 = 'd4319bb362d9487e812970a3ed9ba028';
const INPUT_ID_2 = 'fc449e98ce3847c788954e3fec871d02';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.DeleteInputs(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
ids: [INPUT_ID_1, INPUT_ID_2]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the IDs of the
// inputs we want to delete. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the inputs you want to delete
static final String INPUT_ID_1 = "d4319bb362d9487e812970a3ed9ba028";
static final String INPUT_ID_2 = "fc449e98ce3847c788954e3fec871d02";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
BaseResponse listInputsResponse = stub.deleteInputs(
DeleteInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addIds(INPUT_ID_1)
.addIds(INPUT_ID_2)
.build()
);
if (listInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete inputs failed, status: " + listInputsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the IDs of the
// inputs we want to delete. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the inputs you want to delete
$INPUT_ID_1 = 'd4319bb362d9487e812970a3ed9ba028';
$INPUT_ID_2 = 'fc449e98ce3847c788954e3fec871d02';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\DeleteInputsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->DeleteInputs(
// The request object carries the request along with the request status and other metadata related to the request itself
new DeleteInputsRequest([
"user_app_id" => $userDataObject,
'ids' => [$INPUT_ID_1, $INPUT_ID_2]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"ids":["YOUR_INPUT_ID_1_HERE","YOUR_INPUT_ID_2_HERE"]
}'