API Clients
gRPC Clients
For new projects, we recommend using one of the auto-generated clients built using gRPC. These clients may offer better performance since they use a gRPC channel where the network transfer of the data is optimized. The data is serialized with Protocol Buffers.
Since the gRPC clients are auto-generated, they will always have the latest available Clarifai API feature-set.
It's possible to make these clients using the standard HTTP+JSON channel, while enjoying a better auto-completion support in most IDEs (compared to building and parsing JSON directly), and easily being able to switch to using a gRPC channel when/if desired.
The gRPC clients below are currently available and we'll be adding more as time goes on.
Manually-built Clients
Client Installation Instructions
///////////////////////////////////////////////////////////////////////////////
// Installation (build.gradle)
///////////////////////////////////////////////////////////////////////////////
repositories {
jcenter()
}
dependencies {
implementation 'com.clarifai:clarifai-grpc:LATEST_VERSION'
}
///////////////////////////////////////////////////////////////////////////////
// Initialize client
///////////////////////////////////////////////////////////////////////////////
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import io.grpc.Channel;
// Construct one of the channels you want to use
Channel channel = ClarifaiChannel.INSTANCE.getJsonChannel();
Channel channel = ClarifaiChannel.INSTANCE.getInsecureGrpcChannel();
// 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(new ClarifaiCallCredentials("{YOUR_CLARIFAI_API_KEY}"));
Last updated
Was this helpful?