Manage Inputs via API | Clarifai Docs
GPU Shortage?Make the most out of your GPUs with Compute Orchestration. Learn More
On this page
Learn how to use our API to manage, organize, and process your inputs
You can manage inputs on the Clarifai platform by organizing, updating, deleting, and performing various data processing tasks.
Whether you're working with images, text, or videos, the platform provides powerful capabilities to help you maintain full control over your inputs throughout their lifecycle.
info
Before using the Python SDK, Node.js SDK, or any of our gRPC clients, ensure they are properly installed on your machine. Refer to their respective installation guides for instructions on how to install and initialize them.
List Inputs
List All Inputs
You can retrieve all inputs available in your app. If you added inputs with concepts, they will be returned in the response as well.
Note that this request supports pagination, allowing you to navigate through large sets of inputs efficiently.
- Python SDK
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
from clarifai.client.user import User
# Create the input object
input_obj = User(pat="YOUR_PAT", user_id="user_id").app(app_id="test_app").inputs()
# list the inputs with pagination
all_inputs = list(input_obj.list_inputs(page_no=1,per_page=3))
print(all_inputs)
###############################################################
# 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.
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
// 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";
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";
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"
Output
[id: "demo1"\
data {\
image {\
url: "https://samples.clarifai.com/metro-north.jpg"\
hosted {\
prefix: "https://data.clarifai.com"\
suffix: "users/8tzpjy1a841y/apps/test_app/inputs/image/140c856dc82565d2c4d6ea720fceff78"\
sizes: "orig"\
sizes: "tiny"\
sizes: "small"\
sizes: "large"\
crossorigin: "use-credentials"\
}\
image_info {\
width: 512\
height: 384\
format: "JPEG"\
color_mode: "YUV"\
}\
}\
}\
created_at {\
seconds: 1705917660\
nanos: 789409000\
}\
...\
code: INPUT_DOWNLOAD_SUCCESS\
description: "Download complete"\
}\
]
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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
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)
```javascript
<!--index.html file-->
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
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 {
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";
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();
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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- 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'
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.
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// 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;
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";
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';
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();
$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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
##################################################################
# In this section, we set the user authentication and the app ID.
# Change these strings to run your own example.
##################################################################
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 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
/////////////////////////////////////////////////////////////////////////////
// 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;
public class ClarifaiExample {
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";
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();
$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"
Download Inputs
Below is an example of how to download inputs from your app.
- Python SDK
from clarifai.client.input import Inputs
# Initialize the Inputs object with user and app IDs
input_object = Inputs(user_id="YOUR_USER_ID_HERE", app_id="YOUR_APP_ID_HERE", pat="YOUR_PAT_HERE")
# Download inputs
input_object.download_inputs(list(input_object.list_inputs()))
Patch Inputs
You can apply patch operations to an input, allowing for the merging or removal of items. By default, these actions overwrite existing data, but they behave differently when handling lists of objects.
The
mergeaction replaces akey:valuepair with akey:new_value, or appends new values to an existing list. When dealing with dictionaries, it merges entries that share the sameidfield.The
removeaction replaces akey:valuepair with akey:new_value, or removes any items from a list that match the IDs of the provided values.The
overwriteaction fully replaces an existing object with a new one.
Patch Metadata
Here is an example of how to patch the metadata of an input.
- Python SDK
from clarifai.client.input import Inputs
from google.protobuf.struct_pb2 import Struct
# Metadata structure should be of Struct, so we create it, add the necessary details and provide it to input proto
metadata = Struct()
metadata.update({"split": "test"})
# Initialize the Inputs object with user and app IDs
input_object = Inputs(user_id="YOUR_USER_ID_HERE", app_id="YOUR_APP_ID_HERE", pat="YOUR_PAT_HERE")
new_input = input_object._get_proto(input_id="YOUR_INPUT_ID_HERE", metadata= metadata)
# Update the metadata
input_object.patch_inputs([new_input],action="merge")
# Overwrite the metadata
input_object.patch_inputs([new_input],action='overwrite')
Patch Bounding Box Annotation
Here is an example of how to patch a bounding box annotation on an input.
- Python SDK
from clarifai.client.input import Inputs
# Initialize the Inputs object with user and app IDs
input_object = Inputs(user_id="YOUR_USER_ID_HERE", app_id="YOUR_APP_ID_HERE", pat="YOUR_PAT_HERE")
# Upload the image with a specific input ID
input_object.upload_from_url(input_id="bbox", image_url="https://samples.clarifai.com/BarackObama.jpg")
# Upload initial bounding box annotations
bbox_points = [.1, .1, .8, .9] # Coordinates of the bounding box
annotation = input_object.get_bbox_proto(input_id="bbox", label="face", bbox=bbox_points, label_id="id-face", annot_id="demo")
input_object.upload_annotations([annotation])
# Update existing bounding box annotations with new coordinates
bbox_points = [.35, .45, .6, .7] # New coordinates of the bounding box
annotation = input_object.get_bbox_proto(input_id="bbox", label="face", bbox=bbox_points, label_id="id-face", annot_id="demo")
input_object.patch_annotations([annotation], action='merge')
# Remove the bounding box annotations
bbox_points = [.3, .3, .6, .7] # Coordinates of the bounding box to be removed
annotation = input_object.get_bbox_proto(input_id="bbox", label="face", bbox=bbox_points, label_id="id-face", annot_id="demo")
input_object.patch_annotations([annotation], action='remove')
Patch Polygon Annotation
Here is an example of how to patch a polygon annotation on an input.
- Python SDK
from clarifai.client.input import Inputs
# Initialize the Inputs object with user and app IDs
input_object = Inputs(user_id="YOUR_USER_ID_HERE", app_id="YOUR_APP_ID_HERE", pat="YOUR_PAT_HERE")
# Upload the image with a specific input ID
input_object.upload_from_url(input_id="polygon", image_url="https://samples.clarifai.com/BarackObama.jpg")
# Upload initial polygon annotations
polygon_pts = [[.1,.1],[.1,.9],[.9,.9],[.9,.1]] # Coordinates of the polygon
annotation = input_object.get_mask_proto(input_id="polygon", label="label", polygons=polygon_pts, annot_id="annotation_id")
input_object.upload_annotations([annotation])
# Update existing polygon annotations with new coordinates
polygon_pts = [[.15,.15],[.15,.95],[.95,.95],[.95,.15]] # New coordinates of the polygon
annotation = input_object.get_mask_proto(input_id="polygon", label="label", polygons=polygon_pts, annot_id="annotation_id")
input_object.patch_annotations([annotation],action='merge')
# Remove the polygon annotations
polygon_pts = [[.3,.3],[.3,.7],[.8,.8],[.7,.3]] # Coordinates of the polygon to be removed
annotation = input_object.get_mask_proto(input_id="polygon", label="label", polygons=polygon_pts, annot_id="annotation_id")
input_object.patch_annotations([annotation],action='remove')
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 SDK
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
from clarifai.client.input import Inputs
# Initialize the Inputs object with user and app IDs
input_object = Inputs(user_id="YOUR_USER_ID_HERE", app_id="YOUR_APP_ID_HERE", pat="YOUR_PAT_HERE")
# This example changes the existing concept label "id-face" to "obama_face"
input_object.patch_concepts(
concept_ids=["id-face"], # The ID of the concept you want to update
labels=["obama_face"], # The new label name to overwrite the existing one
values=[],
action='overwrite' # Currently, only the `overwrite` action is supported
)
##############################################################################
# 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'
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';
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 { 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;
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";
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';
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();
?>
# 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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- 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'
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
)
```javascript
<!--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';
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
};
</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 { 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;
public class ClarifaiExample {
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";
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()
);
}
}
<?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';
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
?>
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"
}'
## Bulk Delete Input Annotations [](https://docs.clarifai.com/create/inputs/manage/\#bulk-delete-input-annotations "Direct link to Bulk Delete Input Annotations")
Below is an example of how to delete all the annotations associated with a given input by setting the input ID(s).
The `annotation_ids` parameter is optional. However, if provided, the number and order of `annotation_ids` must match the corresponding `input_ids`.
- Python SDK
```python
from clarifai.client.input import Inputs
# Initialize the Inputs object with user and app IDs
input_object = Inputs(user_id="YOUR_USER_ID_HERE", app_id="YOUR_APP_ID_HERE", pat="YOUR_PAT_HERE")
# Bulk delete annotations
input_object.delete_annotations(input_ids=["input_id1", "input_id1", "input_id2"], annotation_ids=["annot_id11", "annot_id12", "annot_id21"])
Delete Inputs
caution
Be certain that you want to delete a particular input as the operation cannot be undone.
Delete Concepts From an Input
To remove concepts that were already added to an input, you can do this:
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- 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'
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
)
```javascript
<!--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';
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
};
</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';
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;
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";
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()
);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
$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';
$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();
?>
# 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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- 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'
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
)
```javascript
<!--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';
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
};
</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 { 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;
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";
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()
);
}
}
<?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';
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
?>
# 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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- 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'
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';
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';
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;
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";
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';
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();
?>
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.
info
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 (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- 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'
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';
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
};
</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';
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;
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";
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';
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();
?>
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"]
}'
Delete All Inputs
Below is an example of how to delete all inputs from your app.
- Python SDK
from clarifai.client.user import User
input_obj = User(user_id="user_id", pat="YOUR_PAT").app(app_id="test_app").inputs()
# You can also provide the inputs ids as parameters in delete_inputs function
input_obj.delete_inputs(list(input_obj.list_inputs()))
Output
2024-01-16 14:44:28 INFO clarifai.client.input: input.py:732
Inputs Deleted
code: SUCCESS
description: "Ok"
req_id: "4ae26cd15c7da98a1c2d3647b03d2768"
Build your next AI app, test and tune popular LLMs models, and much more.