
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
clarifai-nodejs-grpc
Advanced tools
This is the official Clarifai gRPC Node.js client for interacting with our powerful recognition API. Clarifai provides a platform for data scientists, developers, researchers and enterprises to master the entire artificial intelligence lifecycle. Gather valuable business insights from images, video and text using computer vision and natural language processing.
npm install clarifai-nodejs-grpc
This library doesn't use semantic versioning. The first two version numbers (X.Y
out of X.Y.Z
) follow the API (backend) versioning, and
whenever the API gets updated, this library follows it.
The third version number (Z
out of X.Y.Z
) is used by this library for any independent releases of library-specific improvements and bug fixes.
There are two approaches to using this library: the dynamic and the static. The former has been around for a longer time, but latter provides type annotations via TypeScript declaration files which improves the IDE auto-completion experience to be more developer-friendly. Both approaches provide the exact same API capabilities.
Construct the Clarifai stub, which contains all the methods available in the Clarifai API, and the Metadata
object that's used to authenticate:
const {ClarifaiStub, grpc} = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key YOUR_CLARIFAI_API_KEY");
Predict concepts in an image:
stub.PostModelOutputs(
{
// This is the model ID of a publicly available General model. You may use any other public or custom model ID.
model_id: "aaa03c23b3724a16a56b629203edc62c",
inputs: [{data: {image: {url: "https://samples.clarifai.com/dog2.jpeg"}}}]
},
metadata,
(err, response) => {
if (err) {
console.log("Error: " + err);
return;
}
if (response.status.code !== 10000) {
console.log("Received failed status: " + response.status.description + "\n" + response.status.details);
return;
}
console.log("Predicted concepts, with confidence values:")
for (const c of response.outputs[0].data.concepts) {
console.log(c.name + ": " + c.value);
}
}
);
See more in the Clarifai API Guide docs. Also see the integration tests.
Note: Do not require the
grpc
library directly viaconst grpc = require("@grpc/grpc-js");
. This produces authentication issues (viagrpc.Metadata
) whenever any other co-installed libraries have the@grpc/grpc-js
dependency (of a different version). Instead, requiregrpc
as shown above.
Create the V2Client
object with which you access all the Clarifai API functionality, and the Metadata
object that's used to authenticate:
const {grpc} = require("clarifai-nodejs-grpc");
const service = require("clarifai-nodejs-grpc/proto/clarifai/api/service_pb");
const resources = require("clarifai-nodejs-grpc/proto/clarifai/api/resources_pb");
const {StatusCode} = require("clarifai-nodejs-grpc/proto/clarifai/api/status/status_code_pb");
const {V2Client} = require("clarifai-nodejs-grpc/proto/clarifai/api/service_grpc_pb");
const clarifai = new V2Client("api.clarifai.com", grpc.ChannelCredentials.createSsl());
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key YOUR_CLARIFAI_API_KEY");
Predict concepts in an image:
const request = new service.PostModelOutputsRequest();
// This is the model ID of a publicly available General model. You may use any other public or custom model ID.
request.setModelId("aaa03c23b3724a16a56b629203edc62c");
request.addInputs(
new resources.Input()
.setData(
new resources.Data()
.setImage(
new resources.Image()
.setUrl("https://samples.clarifai.com/dog2.jpeg")
)
)
)
clarifai.postModelOutputs(
request,
metadata,
(error, response) => {
if (error) {
throw error;
}
if (response.getStatus().getCode() !== StatusCode.SUCCESS) {
throw "Error: " + response.getStatus();
}
console.log("Predicted concepts, with confidence values:")
for (const concept of response.getOutputsList()[0].getData().getConceptsList()) {
console.log(concept.getName() + " " + concept.getValue());
}
}
)
See more in the Clarifai API Guide docs. Also see the integration tests.
Note: Currently, the NodeJS gRPC code examples in the Clarifai documentation show only the dynamic approach. These code examples can easily be translated to the static approach, since the structure is the same for both of them. The difference is only in the syntax.
FAQs
The official Clarifai Node.js gRPC client
The npm package clarifai-nodejs-grpc receives a total of 1,642 weekly downloads. As such, clarifai-nodejs-grpc popularity was classified as popular.
We found that clarifai-nodejs-grpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.