Skip to main content

Clarifai API Clients

Clarifai API provides clients in the most popular languages


You can access the Clarifai API through clients in many of the most popular programming languages. Our clients are built on gRPC and are accessible through HTTP+JSON channels as well as gRPC channels.

Official Clients

Available Clients
Clarifai Python
Clarifai Java
Clarifai NodeJS
Clarifai C#
Clarifai PHP
Clarifai Swift
Clarifai Rust
Clarifai Go
Clarifai C++

Manually-built Clients (deprecated)

Deprecated Clients
C#
Java
JavaScript (Reference Docs)
PHP

Client Installation Instructions

Here are the installation instructions and the initialization code for some of our most commonly used clients.

For information on installing our other clients, please follow the links above.

authorization

Learn how to set up authorization with the various API clients here.

CORS Policy Error

Learn how to resolve CORS errors in your JavaScript application(s) here.

##############################################################################################
# Installation
##############################################################################################

python -m pip install clarifai-grpc

##############################################################################################
# Initialize the gRPC-based client to communicate with the Clarifai platform.
##############################################################################################

# Import the Clarifai gRPC-based objects needed
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_pb2, status_code_pb2

# Construct the communications channel
channel = ClarifaiChannel.get_grpc_channel()
# Construct the V2Stub object for accessing all the Clarifai API functionality
stub = service_pb2_grpc.V2Stub(channel)

##############################################################################################
# This is where you set up the metadata object that's used to authenticate.
# This authorization will be used by every Clarifai API call.
# Change the following authorization key to your own credentials
# Example: metadata = (('authorization', 'Key ' + 'a123457612345678'),)
##############################################################################################

metadata = (('authorization', 'Key ' + 'YOUR_CLARIFAI_PAT_HERE'),)
# Or, if you were to use an API Key:
# metadata = (('authorization', 'Key ' + 'YOUR_CLARIFAI_API_KEY_HERE'),)
# Yes, the word 'Key' appears in addition to the alphanumeric PAT or API Key

##############################################################################################
# A UserAppIDSet object is needed when using a PAT. It contains two pieces of information:
# user_id (your user id) and app_id (app id that contains the model of interest).
# Both of them are specified as string values.
##############################################################################################

userDataObject = resources_pb2.UserAppIDSet(user_id='YOUR_USER_ID_HERE', app_id='YOUR_APPLICATION_ID_HERE')