Skip to main content

Manage Models

Learn how to get, update, search, and delete models


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.

Get

List Model Types

Learn about the available model types and their hyperparameters. This endpoint lets you list all the possible models that are creatable (when creatable=true) or generally in the platform (the other ones have creatable=false).

################################################################
# 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)

response = stub.ListModelTypes(
service_pb2.ListModelTypesRequest(
user_app_id=userDataObject
),
metadata=metadata
)

if response.status.code != status_code_pb2.SUCCESS:
print(response.status)
raise Exception("List models failed, status: " + response.status.description)

for model_type in response.model_types:
print(model_type)

List Models

Below is an example of how to get a list of all the models you've created in your app.

info

The ListModels endpoint will return details of all the models in your app, alongside the details of their latest versions.

tip

If you want to get a list of the models not within the scope of your app, you need to use your PAT while specifying the user_id of their owner and the app_id of the application that you’re accessing. For example, to get Clarifai's models in the main app, you need to use your PAT while specifying Clarifai's user_id as "clarifai" and app_id as "main" in the request.

#################################################################
# 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_models_response = stub.ListModels(
service_pb2.ListModelsRequest(
user_app_id=userDataObject
),
metadata=metadata
)

if list_models_response.status.code != status_code_pb2.SUCCESS:
print(list_models_response.status)
raise Exception("List models failed, status: " + list_models_response.status.description)

for model in list_models_response.models:
print(model)

Get Model by ID

All models have unique IDs. You can get a specific model by its ID.

################################################################################
# In this section, we set the user authentication, app ID, and the model ID we
# want to get its details. 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 to your own model ID
MODEL_ID = 'petsID'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

get_model_response = stub.GetModel(
service_pb2.GetModelRequest(
user_app_id=userDataObject,
model_id=MODEL_ID
),
metadata=metadata
)

if get_model_response.status.code != status_code_pb2.SUCCESS:
print(get_model_response.status)
raise Exception("Get model failed, status: " + get_model_response.status.description)

model = get_model_response.model
print(model)

Get Model Output Info by ID

The output info of a model lists the concepts contained in the latest version of the model—unless a particular version is specified.

note

The GetModelOutputInfo endpoint does not support pagination. If you want to split your results into pages, use the below-described ListModelConcepts endpoint.

###############################################################################
# In this section, we set the user authentication, app ID, and the model ID we
# want to get its output info. 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 to your own model ID
MODEL_ID = 'petsID'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

get_model_response = stub.GetModelOutputInfo(
service_pb2.GetModelRequest(
user_app_id=userDataObject,
model_id=MODEL_ID
),
metadata=metadata
)

if get_model_response.status.code != status_code_pb2.SUCCESS:
print(get_model_response.status)
raise Exception("Get model failed, status: " + get_model_response.status.description)

model = get_model_response.model
print(model)

List Model Concepts

Apart from the GetModelOutputInfo endpoint, you can also use the ListModelConcepts endpoint to list the concepts in your model.

A major difference between the two is that the ListModelConcepts endpoint supports pagination, which lets you easily list concepts instead of displaying all of them at once.

info

If you are using any of the Clarifai gRPC clients, the ListModelConcepts endpoint is only available from release 8.10.0.

###########################################################################
# In this section, we set the user authentication and model 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 to whatever model you want to retrieve its concepts
MODEL_ID = 'YOUR_MODEL_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_model_concepts_response = stub.ListModelConcepts(
service_pb2.ListModelConceptsRequest(
user_app_id=userDataObject,
model_id=MODEL_ID
),
metadata=metadata
)

if list_model_concepts_response.status.code != status_code_pb2.SUCCESS:
print(list_model_concepts_response.status)
raise Exception("List model concept failed, status: " + list_model_concepts_response.status.description)

print(list_model_concepts_response)

List Model Versions

Every time you train a model, it creates a new version. You can list all the versions created.

###############################################################################
# In this section, we set the user authentication, app ID, and the model ID we
# want to list its versions. 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 to your own model ID
MODEL_ID = 'petsID'

##########################################################################
# 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_model_versions_response = stub.ListModelVersions(
service_pb2.ListModelVersionsRequest(
user_app_id=userDataObject,
model_id=MODEL_ID
),
metadata=metadata
)

if list_model_versions_response.status.code != status_code_pb2.SUCCESS:
print(list_model_versions_response.status)
raise Exception("List model versions failed, status: " + list_model_versions_response.status.description)

for model_version in list_model_versions_response.model_versions:
print(model_version)

Get Model Version by ID

To get the details of a specific model version, you must provide the model_id as well as the version_id parameters. You can inspect the model version status to determine if your model is trained or still training.

#########################################################################################
# In this section, we set the user authentication, app ID, and the ID and version
# of the model we want to get its details. Change these strings to run your own example.
#########################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to your own model ID and version
MODEL_ID = 'petsID'
MODEL_VERSION_ID = 'daf51b311c8644a486bbbe57c0680bc2'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

get_model_version_response = stub.GetModelVersion(
service_pb2.GetModelVersionRequest(
user_app_id=userDataObject,
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID
),
metadata=metadata
)

if get_model_version_response.status.code != status_code_pb2.SUCCESS:
print(get_model_version_response.status)
raise Exception("Get model version failed, status: " + get_model_version_response.status.description)

model_version = get_model_version_response.model_version
print(model_version)

Update

After creating a model, you can perform patch operations on it by merging, removing, or overwriting data. By default, all actions support overwriting, but they handle lists of objects in specific ways.

  • The merge action updates a key:value pair with key:new_value or appends to an existing list. For dictionaries, it merges entries that share the same id field.
  • The remove action is only used to delete the model's cover image on the platform UI.
  • The overwrite action completely replaces an existing object with a new one.
info
  • The PatchModels endpoint allows you to patch only the model level fields, and nothing in the model version. It only updates things like name, description, notes, and other metadata type information field you may have.
  • The PatchModelVersions endpoint allows you to change most of the model version fields like gettable, metadata, license, description, notes, and output_info (not including concepts).

Update Model Name

Let's use the PatchModels endpoint to change the model name to newname.

#####################################################################################################
# In this section, we set the user authentication, app ID, and how we want to update the model.
# Change these strings to run your own example.
#####################################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to update your own model
MODEL_ID = 'petsID'
MODEL_NAME = 'newname'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_models_response = stub.PatchModels(
service_pb2.PatchModelsRequest(
user_app_id=userDataObject,
action="overwrite",
models=[
resources_pb2.Model(
id=MODEL_ID,
name=MODEL_NAME
)
]
),
metadata=metadata
)

if patch_models_response.status.code != status_code_pb2.SUCCESS:
print(patch_models_response.status)
raise Exception("Patch models failed, status: " + patch_models_response.status.description)

Update Model Configuration

Let's use the PatchModelVersions endpoint to configure the minimum probability threshold for the outputs we want to view from the model. We can modify the min_value parameter available for this model type to filter the outputs to see only the concepts with a probability score of 0.95 or higher.

tip

For embedding-classifiers, the min_value parameter falls within the range of 0 to 1, with a step size of 0.01. For most of the other model types, it falls within the range of 0 to 100, with a step size of 0.1.

#####################################################################################################
# In this section, we set the user authentication, app ID, and how we want to update the model.
# Change these strings to run your own example.
#####################################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to update your own model
MODEL_ID = 'petsID'
MODEL_VERSION_ID = 'b0b89c973e5d4b6d9599ce13da04b894'
MINIMUM_VALUE = 0.95

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
from google.protobuf.struct_pb2 import Struct

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

params = Struct()
params.update({
"min_value": MINIMUM_VALUE
})

patch_models_response = stub.PatchModelVersions(
service_pb2.PatchModelVersionsRequest(
user_app_id=userDataObject,
action="overwrite",
model_id=MODEL_ID,
model_versions=[
resources_pb2.ModelVersion(
id=MODEL_VERSION_ID,
output_info=resources_pb2.OutputInfo(
params=params
)
)
]

),
metadata=metadata
)

if patch_models_response.status.code != status_code_pb2.SUCCESS:
print(patch_models_response.status)
raise Exception("Patch models failed, status: " + patch_models_response.status.description)

Other Patch Operations

Below is an example of performing other patch operations on a model, such as updating its description and notes.

from clarifai.client.app import App

app = App(app_id="YOUR_APP_ID_HERE", user_id="YOUR_USER_ID_HERE", pat="YOUR_PAT_HERE")

# Update the details of the model
app.patch_model(model_id="model_clusterer", action="merge", description="description", notes="notes", toolkits=["OpenAI"], use_cases=["llm"], languages=["en"], image_url="https://samples.clarifai.com/metro-north.jpg")

# Update the model's image by specifying the 'remove' action
app.patch_model(model_id='model_clusterer', action='remove', image_url='https://samples.clarifai.com/metro-north.jpg')

Search Models by Name and Type

You can search all your models by name and type of model.

################################################################
# 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)

post_models_searches_response = stub.PostModelsSearches(
service_pb2.PostModelsSearchesRequest(
user_app_id=userDataObject,
model_query=resources_pb2.ModelQuery(
name="gen*", # This supports wild card queries like "gen*" to match "general" as an example
model_type_id="concept"
)
),
metadata=metadata
)

if post_models_searches_response.status.code != status_code_pb2.SUCCESS:
print(post_models_searches_response.status)
raise Exception("Post models searches failed, status: " + post_models_searches_response.status.description)

for model in post_models_searches_response.models:
print(model)

Delete

Delete a Model

You can delete a model by using the model_id parameter.

##########################################################################
# In this section, we set the user authentication, app ID, and model 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 to your own model ID
MODEL_ID = 'petsID'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_model_response = stub.DeleteModel(
service_pb2.DeleteModelRequest(
user_app_id=userDataObject,
model_id=MODEL_ID
),
metadata=metadata
)

if delete_model_response.status.code != status_code_pb2.SUCCESS:
print(delete_model_response.status)
raise Exception("Delete model inputs failed, status: " + delete_model_response.status.description)

Delete a Model Version

You can also delete a specific version of a model with the model_id and version_id parameters.

##################################################################################
# In this section, we set the user authentication, app ID, and the ID and version
# of the model 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 to your own model ID and version
MODEL_ID = 'petsID'
MODEL_VERSION_ID = '9641cbbb019b424db17e593b48ebc7ff'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_model_version_response = stub.DeleteModelVersion(
service_pb2.DeleteModelVersionRequest(
user_app_id=userDataObject,
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID
),
metadata=metadata
)

if delete_model_version_response.status.code != status_code_pb2.SUCCESS:
print(delete_model_version_response.status)
raise Exception("Delete model version failed, status: " + delete_model_version_response.status.description)

Delete all Models

If you would like to delete all models associated with an application, you can also do that.

caution

Please proceed with extreme caution as deleted models cannot be recovered.

################################################################
# 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)

delete_models_response = stub.DeleteModels(
service_pb2.DeleteModelsRequest(
user_app_id=userDataObject,
delete_all=True
),
metadata=metadata
)

if delete_models_response.status.code != status_code_pb2.SUCCESS:
print(delete_models_response.status)
raise Exception("Delete models failed, status: " + delete_models_response.status.description)