To use the Clariafi API, we recommend either using HTTP+JSON directly, or one of the new Clarifai API clients that are build using gRPC. These clients offer increased performance compared to both HTTP+JSON and the legacy clients, since networking and data serialization are optimized.
Here are installation instructions for three of our most commonly used clients. For information on installing our other clients, please follow the links above.
Authorization keys
The key to be used as authorization can be either:
An API key, which is tied to a certain application, or
A Personal Access Token (PAT), which is tied to a user.
Since a user can own multiple applications, using a PAT is more powerful. However, using a PAT also means that you need to specify the application ID to which the request should be applied.
With most endpoints you can freely choose whether to use an API key or a PAT. In this documentation, some code examples use one and some the other. But certain endpoints support only PAT (e.g. creating a new application or a new API key).
############################################################################### Installation##############################################################################pip install clarifai-grpc############################################################################### Initialize client##############################################################################from clarifai_grpc.channel.clarifai_channel import ClarifaiChannelfrom clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpcfrom clarifai_grpc.grpc.api.status import status_pb2, status_code_pb2channel = ClarifaiChannel.get_grpc_channel()# Note: You can also use a secure (encrypted) ClarifaiChannel.get_grpc_channel() however# it is currently not possible to use it with the latest gRPC versionstub = service_pb2_grpc.V2Stub(channel)# This will be used by every Clarifai endpoint call.metadata = (('authorization','Key {YOUR_CLARIFAI_API_KEY}'),)
///////////////////////////////////////////////////////////////////////////////// Installation (build.gradle)///////////////////////////////////////////////////////////////////////////////repositories {jcenter()}dependencies { implementation 'com.clarifai:clarifai-grpc:LATEST_VERSION'}///////////////////////////////////////////////////////////////////////////////// Initialize client///////////////////////////////////////////////////////////////////////////////importcom.clarifai.channel.ClarifaiChannel;importcom.clarifai.credentials.ClarifaiCallCredentials;importcom.clarifai.grpc.api.*;importio.grpc.Channel;Channel channel =ClarifaiChannel.INSTANCE.getGrpcChannel();// Note: You can also use a secure (encrypted) ClarifaiChannel.INSTANCE.getGrpcChannel() however// it is currently not supported in the latest gRPC version.V2Grpc.V2BlockingStub stub =V2Grpc.newBlockingStub(channel).withCallCredentials(newClarifaiCallCredentials("{YOUR_CLARIFAI_API_KEY}"));
///////////////////////////////////////////////////////////////////////////////// Installation///////////////////////////////////////////////////////////////////////////////npm install clarifai-nodejs-grpc///////////////////////////////////////////////////////////////////////////////// Initialize client///////////////////////////////////////////////////////////////////////////////const {ClarifaiStub} =require("clarifai-nodejs-grpc");constgrpc=require("@grpc/grpc-js");conststub=ClarifaiStub.grpc();// This will be used by every Clarifai endpoint call.constmetadata=newgrpc.Metadata();metadata.set("authorization","Key {YOUR_CLARIFAI_API_KEY}");