Create, Get, Update, Delete

Create Model

To create a model, you need to specify the model's name and other required fields (which depend on the model). Specifying the ID is optional.

Below, we create a classifier model with one initial concept. You can always add and remove concepts later.

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
SingleModelResponse postModelsResponse = stub.postModels(
PostModelsRequest.newBuilder().addModels(
Model.newBuilder()
.setId("petsID")
.setOutputInfo(
OutputInfo.newBuilder().setData(
Data.newBuilder().addConcepts(Concept.newBuilder().setId("boscoe"))
)
)
).build()
);
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus());
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PostModels(
{
models: [
{
id: "petsID",
output_info: {
data: {concepts: [{id: "boscoe"}]},
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post models failed, status: " + response.status.description);
}
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
post_models_response = stub.PostModels(
service_pb2.PostModelsRequest(
models=[
resources_pb2.Model(
id="petsID",
output_info=resources_pb2.OutputInfo(
data=resources_pb2.Data(
concepts=[resources_pb2.Concept(id="boscoe", value=1)]
),
)
)
]
),
metadata=metadata
)
if post_models_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post models failed, status: " + post_models_response.status.description)
js
app.models.create(
"petsID",
[
{ "id": "boscoe" }
]
).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
model = app.models.create('petsID', concepts=['boscoe'])
java
client.createModel("petsID")
.withOutputInfo(ConceptOutputInfo.forConcepts(
Concept.forID("boscoe")
))
.executeSync();
csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.CreateModel(
"petsID",
concepts: new List<Concept> {new Concept("boscoe")})
.ExecuteAsync();
}
}
}
objective-c
[_app createModel:@[@"cat", @"dog"] name:@"petsModel" modelID:@"petsID" conceptsMutuallyExclusive:NO closedEnvironment:NO completion:^(ClarifaiModel *model, NSError *error) {
NSLog(@"model: %@", model);
}];
php
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Predictions\Concept;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->createModel('MODEL_ID')
->withConcepts([new Concept('CONCEPT1')])
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
cURL
curl -X POST \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"model": {
"id": "petsID",
"output_info": {
"data": {
"concepts": [
{
"id": "boscoe",
"value": 1
}
]
}
}
}
}'\
https://api.clarifai.com/v2/models

Add Concepts To A Model

You can add concepts to a model at any point. As you add concepts to inputs, you may want to add them to your model.

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
...
MultiModelResponse patchModelsResponse = stub.patchModels(
PatchModelsRequest.newBuilder()
.setAction("merge") // Supported actions: overwrite, merge, remove
.addModels(
Model.newBuilder()
.setId("petsID")
.setOutputInfo(
OutputInfo.newBuilder().setData(
Data.newBuilder().addConcepts(Concept.newBuilder().setId("charlie"))
)
)
)
.build()
);
if (patchModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch models failed, status: " + patchModelsResponse.getStatus());
}
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PatchModels(
{
action: "merge", // Supported actions: overwrite, merge, remove
models: [
{
id: "petsID",
output_info: {data: {concepts: [{id: "charlie"}]}}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch models failed, status: " + response.status.description);
}
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
patch_models_response = stub.PatchModels(
service_pb2.PatchModelsRequest(
action="merge", # Supported actions: overwrite, merge, remove
models=[
resources_pb2.Model(
id="petsID",
output_info=resources_pb2.OutputInfo(
data=resources_pb2.Data(
concepts=[resources_pb2.Concept(id="charlie")]
),
)
)
]
),
metadata=metadata
)
if patch_models_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Patch models failed, status: " + patch_models_response.status.description)
js
app.models.initModel({model_id}).then(function(model) {
updateModel,
function(err) {
// there was an error
}
});
function updateModel(model) {
model.mergeConcepts({"id": "charlie"}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
}
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
model = app.models.get('{model_id}')
model.add_concepts(['charlie'])
java
client.modifyModel("{{model_id}}")
.withConcepts(Action.MERGE, Concept.forID("dogs"))
.executeSync();
// Or, if you have a ConceptModel object, you can do it in an OO fashion
final ConceptModel model = client.getModelByID("{model_id}").executeSync().get().asConceptModel();
model.modify()
.withConcepts(Action.MERGE, Concept.forID("dogs"))
.executeSync();
csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.API.Requests.Models;
using Clarifai.DTOs.Models;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.ModifyModel(
"petsID",
ModifyAction.Merge,
concepts: new List<Concept> {new Concept("dogs")})
.ExecuteAsync();
// Or, if you have a ConceptModel object, you can do it in an OO fashion
ConceptModel model = (ConceptModel) (
await client.GetModel<Concept>("petsID")
.ExecuteAsync()).Get();
await model.Modify(
ModifyAction.Merge,
concepts: new List<Concept> {new Concept("dogs")})
.ExecuteAsync();
}
}
}
objective-c
ClarifaiConcept *concept = [[ClarifaiConcept alloc] initWithConceptName:@"dress"];
[app addConcepts:@[concept] toModelWithID:@"{model_id}" completion:^(ClarifaiModel *model, NSError *error) {
NSLog(@"model: %@", model);
}];
php
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Inputs\ModifyAction;
use Clarifai\DTOs\Predictions\Concept;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->modifyModel('MODEL_ID')
->withModifyAction(ModifyAction::merge())
->withConcepts([new Concept('CONCEPT')])
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
cURL
curl -X PATCH \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"models": [
{
"id": "petsID",
"output_info": {
"data": {
"concepts": [
{
"id": "charlie"
}
]
}
}
}
],
"action": "merge"
}'\
https://api.clarifai.com/v2/models/

Remove Concepts From A Model

Conversely, if you'd like to remove concepts from a model, you can also do that.

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiModelResponse patchModelsResponse = stub.patchModels(
PatchModelsRequest.newBuilder()
.setAction("remove") // Supported actions: overwrite, merge, remove
.addModels(
Model.newBuilder()
.setId("petsID")
.setOutputInfo(
OutputInfo.newBuilder().setData(
Data.newBuilder().addConcepts(Concept.newBuilder().setId("charlie"))
)
)
)
.build()
);
if (patchModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch models failed, status: " + patchModelsResponse.getStatus());
}
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PatchModels(
{
action: "remove", // Supported actions: overwrite, merge, remove
models: [
{
id: "petsID",
output_info: {data: {concepts: [{id: "charlie"}]}}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch models failed, status: " + response.status.description);
}
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
patch_models_response = stub.PatchModels(
service_pb2.PatchModelsRequest(
action="remove", # Supported actions: overwrite, merge, remove
models=[
resources_pb2.Model(
id="petsID",
output_info=resources_pb2.OutputInfo(
data=resources_pb2.Data(
concepts=[resources_pb2.Concept(id="charlie")]
),
)
)
]
),
metadata=metadata
)
if patch_models_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Patch models failed, status: " + patch_models_response.status.description)
js
app.models.initModel({model_id}).then(function(model) {
updateModel,
function(err) {
// there was an error
}
});
function updateModel(model) {
model.deleteConcepts({"id": "charlie"}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
}
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
model = app.models.get('{model_id}')
model.delete_concepts(['charlie'])
java
client.modifyModel("{{model_id}}")
.withConcepts(Action.REMOVE, Concept.forID("dogs"))
.executeSync();
// Or, if you have a ConceptModel object, you can do it in an OO fashion
final ConceptModel model = client.getModelByID("{{model_id}}").executeSync().get().asConceptModel();
model.modify()
.withConcepts(Action.REMOVE, Concept.forID("dogs"))
.executeSync();
csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.API.Requests.Models;
using Clarifai.DTOs.Models;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.ModifyModel(
"petsID",
ModifyAction.Remove,
concepts: new List<Concept> {new Concept("dogs")})
.ExecuteAsync();
// Or, if you have a ConceptModel object, you can do it in an OO fashion
ConceptModel model = (ConceptModel) (
await client.GetModel<Concept>("petsID")
.ExecuteAsync())
.Get();
await model.Modify(
ModifyAction.Remove,
concepts: new List<Concept> {new Concept("dogs")})
.ExecuteAsync();
}
}
}
objective-c
ClarifaiConcept *concept = [[ClarifaiConcept alloc] initWithConceptName:@"dress"];
[app deleteConcepts:@[concept] fromModelWithID:@"{model_id}" completion:^(ClarifaiModel *model, NSError *error) {
NSLog(@"model: %@", model);
}];
php
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Inputs\ModifyAction;
use Clarifai\DTOs\Predictions\Concept;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->modifyModel('MODEL_ID')
->withModifyAction(ModifyAction::remove())
->withConcepts([new Concept('CONCEPT')])
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
cURL
curl -X PATCH \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"models": [
{
"id": "petsID",
"output_info": {
"data": {
"concepts": [
{
"id": "charlie"
}
]
}
}
}
],
"action": "remove"
}'\
https://api.clarifai.com/v2/models/

Update Model Name and Configuration

Here we will change the model name to 'newname' and the model's configuration to have concepts_mutually_exclusive=true and closed_environment=true.

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiModelResponse patchModelsResponse = stub.patchModels(
PatchModelsRequest.newBuilder()
.setAction("overwrite")
.addModels(
Model.newBuilder()
.setId("petsID")
.setName("newname")
.setOutputInfo(
OutputInfo.newBuilder()
.setData(
Data.newBuilder()
.addConcepts(Concept.newBuilder().setId("birds"))
.addConcepts(Concept.newBuilder().setId("hurd"))
)
.setOutputConfig(
OutputConfig.newBuilder()
.setConceptsMutuallyExclusive(true)
.setClosedEnvironment(true)
)
)
).build()
);
if (patchModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch models failed, status: " + patchModelsResponse.getStatus());
}
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PatchModels(
{
action: "overwrite",
models: [
{
id: "petsID",
name: "newname",
output_info: {
data: {concepts: [{id: "birds"}, {id: "hurd"}]},
output_config: {concepts_mutually_exclusive: true, closed_environment: true}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch models failed, status: " + response.status.description);
}
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
patch_models_response = stub.PatchModels(
service_pb2.PatchModelsRequest(
action="overwrite",
models=[
resources_pb2.Model(
id="petsID",
name="newname",
output_info=resources_pb2.OutputInfo(
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id="birds"),
resources_pb2.Concept(id="hurd")
]
),
output_config=resources_pb2.OutputConfig(
concepts_mutually_exclusive=True,
closed_environment=True,
)
)
)
]
),
metadata=metadata
)
if patch_models_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Patch models failed, status: " + patch_models_response.status.description)
js
app.models.initModel({model_id}).then(
updateModel,
function(err) {
// there was an error
}
);
function updateModel(model) {
model.update({
name: 'newname',
conceptsMutuallyExclusive: true,
closedEnvironment: true,
concepts: ['birds', 'hurd']
}).then(
}
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
model = app.models.get('{model_id}')
# only update the name
model.update(model_name="newname")
# update the model attributes
model.update(concepts_mutually_exclusive=True, closed_environment=True)
# update more together
model.update(model_name="newname",
concepts_mutually_exclusive=True, closed_environment=True)
# update attributes together with concepts
model.update(model_name="newname",
concepts_mutually_exclusive=True,
concepts=["birds", "hurd"])
java
client.modifyModel("{{model_id}}")
.withName("newname")
.withConceptsMutuallyExclusive(true)
.withClosedEnvironment(true)
.executeSync();
csharp
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.ModifyModel(
"someModel",
name: "{newName}",
areConceptsMutuallyExclusive: true,
isEnvironmentClosed: false)
.ExecuteAsync();
}
}
}
objective-c
[_app updateModel:@"{model_id}" name:@"newName" conceptsMutuallyExclusive:NO closedEnvironment:NO completion:^(ClarifaiModel *model, NSError *error) {
NSLog(@"model: %@", model);
}];
php
use Clarifai\API\ClarifaiClient;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->modifyModel('MODEL_ID')
->withName('NEW_MODEL_NAME')
->withAreConceptsMutuallyExclusive(false)
->withIsEnvironmentClosed(false)
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
cURL
curl -X PATCH \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"models": [
{
"id": "petsID",
"name": "newname",
"output_info": {
"data": {"concepts": [{"id": "birds"}, {"id": "hurd"}]},
"output_config": {
"concepts_mutually_exclusive": true,
"closed_environment": true
}
}
}
],
"action": "overwrite"
}'\
https://api.clarifai.com/v2/models/

Get

List Model Types

Learn about available model types and their hyperparameters. This endpoint lists all the possible models that are creatable (when creatable=true), or in general in the platform (the others ones have creatable=false).

gRPC Java
gRPC NodeJS
gRPC Python
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiModelTypeResponse listModelTypesResponse = stub.listModelTypes(ListModelTypesRequest.newBuilder().build());
for (ModelType modelType : listModelTypesResponse.getModelTypesList()) {
System.out.println(modelType);
}
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.ListModelTypes(
{
page: 1,
per_page: 500
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Received status: " + response.status.description + "\n" + response.status.details);
}
for (const model_type of response.model_types) {
console.log(model_type)
}
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
response = stub.ListModelTypes(service_pb2.ListModelTypesRequest(), metadata=metadata)
for model_type in response.model_types:
print(model_type)
cURL
curl -X GET 'https://api.clarifai.com/v2/models/types?per_page=20&page=1' \
-H 'Authorization: Key YOUR_API_KEY'

Get Models

To get a list of all models including models you've created as well as Clarifai models:

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
import java.util.List;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiModelResponse listModelsResponse = stub.listModels(
ListModelsRequest.newBuilder().build()
);
if (listModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List models failed, status: " + listModelsResponse.getStatus());
}
List<Model> models = listModelsResponse.getModelsList();
for (Model model : models) {
System.out.println(model);
}
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.ListModels(
{},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List models failed, status: " + response.status.description);
}
for (const model of response.models) {
console.log(JSON.stringify(model, null, 2));
}
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
list_models_response = stub.ListModels(
service_pb2.ListModelsRequest(),
metadata=metadata
)
if list_models_response.status.code != status_code_pb2.SUCCESS:
raise Exception("List models failed, status: " + list_models_response.status.description)
for model in list_models_response.models:
print(model)
js
app.models.list().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
# this is a generator
app.models.get_all()
java
client.getModels().getPage(1).executeSync();
csharp
using System.Threading.Tasks;
using Clarifai.API;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.GetModels()
.Page(1)
.ExecuteAsync();
}
}
}
objective-c
[_app getModels:1 resultsPerPage:30 completion:^(NSArray<ClarifaiModel *> *models, NSError *error) {
NSLog(@"models: %@", models);
}];
php
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Models\Model;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->getModels()
->executeSync();
if ($response->isSuccessful()) {
$models = $response->get();
foreach ($models as $model) {
echo $model->modelID() . ' ' . $model->type() . "\n";
}
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
cURL
curl -X GET \
-H "Authorization: Key YOUR_API_KEY" \
https://api.clarifai.com/v2/models

Get Model By Id

All models have unique Ids. You can get a specific model by its id:

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
SingleModelResponse getModelResponse = stub.getModel(
GetModelRequest.newBuilder()
.setModelId("petsID")
.build()
);
if (getModelResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get model failed, status: " + getModelResponse.getStatus());
}
Model model = getModelResponse.getModel();
System.out.println(model);
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.GetModel(
{model_id: "petsID"},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List models failed, status: " + response.status.description);
}
const model = response.model;
console.log(JSON.stringify(model, null, 2));
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
get_model_response = stub.GetModel(
service_pb2.GetModelRequest(model_id="petsID"),
metadata=metadata
)
if get_model_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Get model failed, status: " + get_model_response.status.description)
model = get_model_response.model
print(model)
js
app.models.get({model_id}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key='YOUR_API_KEY')
# get model by id
model = app.models.get(model_id')
# get model by name
model = app.models.get('my_model1')
java
client.getModelByID("{model_id}").executeSync();
csharp
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Predictions;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
// Change Concept to whatever the model's type is.
await client.GetModel<Concept>("{model_id}")
.ExecuteAsync();
}
}
}
objective-c
[_app getModel:@"model_id" completion:^(ClarifaiModel *model, NSError *error) {
NSLog(@"model: %@", model);
}];
php
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Models\Model;
use Clarifai\DTOs\Models\ModelType;
$client = new ClarifaiClient('YOUR_API_KEY');
$response = $client->getModel(ModelType::concept(), 'MODEL_ID')
->executeSync();
if ($response->isSuccessful()) {
echo "Response is successful.\n";
$model = $response->get();
echo $model->modelID() . ' ' . $model->type() . "\n";
} else {
echo "Response is not successful. Reason: \n";
echo $response->status()->description() . "\n";
echo $response->status()->errorDetails() . "\n";
echo "Status code: " . $response->status()->statusCode();
}
cURL
curl -X GET \
-H "Authorization: Key YOUR_API_KEY" \
https://api.clarifai.com/v2/models/petsID

Get Model Output Info By Id

The output info of a model lists what concepts it contains.

gRPC Java
gRPC NodeJS
gRPC Python
js
python
java
csharp
objective-c
php
cURL
gRPC Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
SingleModelResponse getModelOutputInfoResponse = stub.getModelOutputInfo(
GetModelRequest.newBuilder()
.setModelId("petsID")
.build()
);
if (getModelOutputInfoResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get model output info failed, status: " + getModelOutputInfoResponse.getStatus());
}
Model model = getModelOutputInfoResponse.getModel();
System.out.println(model);
gRPC NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.GetModelOutputInfo(
{model_id: "petsID"},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List models failed, status: " + response.status.description);
}
const model = response.model;
console.log(JSON.stringify(model, null, 2));
}
);
gRPC Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
get_model_response = stub.GetModelOutputInfo(
service_pb2.GetModelRequest(model_id="petsID"),
metadata=metadata
)
if get_model_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Get model failed, status: " + get_model_response.status.description)
model = get_model_response.model
print(model)
js
app.models.initModel({model_id}).then(
getModelOutputInfo,
handleError
);
function getModelOutputInfo(model) {
model.getOutputInfo().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
}
python
from clarifai.rest import ClarifaiApp
app = ClarifaiApp(api_key