Socket
Book a DemoInstallSign in
Socket

clarifai-node-serverless

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clarifai-node-serverless

![image](https://github.com/user-attachments/assets/3721189c-01c0-4936-a73c-13dcbf808542)

0.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

image

Clarifai Node.js SDK - For Serverless Environments

npm Build Discord

Clarifai Node.js SDK - For Serverless Environments

This is the official Node.js client library for working with Clarifai's API in serverless environments. This library is designed to be lightweight, compatible with modern ESM syntax, and optimized for serverless platforms like AWS Lambda, Vercel, and Netlify.

This library currently includes only a small subset of features from the main Clarifai Node.js SDK package. We are actively working on adding more features and improvements. If you need a specific feature, please let us know by opening an issue or joining our Discord community.

Website | Schedule Demo | Signup for a Free Account | API Docs | Clarifai Community | Discord

Give the repo a star ⭐

Installation

npm install clarifai-node-serverless

Usage

Clarifai uses Personal Access Tokens(PATs) to validate requests. You can create and manage PATs under your Clarifai account security settings.

  • 🔗 Create PAT: Log into Portal → Profile Icon → Security Settings → Create Personal Access Token → Set the scopes → Confirm

Export your PAT as an environment variable. Then, import and initialize the API Client.

Set PAT as environment variable through terminal:

export CLARIFAI_PAT={your personal access token}

or use dotenv to load environment variables via a .env file

Using Workflows

import { Workflow, getInputFromUrl } from "clarifai-node-serverless";

const GENERAL_WORKFLOW =
  "https://clarifai.com/my-org/celebrity-check/workflows/General";

const CELEBRITY_IMAGE = "https://samples.clarifai.com/celebrity.jpeg";

const workflow = new Workflow({
  url: GENERAL_WORKFLOW,
  authConfig: {
    pat: process.env.CLARIFAI_PAT!,
  },
});

const input = getInputFromUrl({
  url: CELEBRITY_IMAGE,
  inputType: "image",
});

const response = await workflow.predict({
  inputs: [input],
});

console.log(response);

Using Clarifai GRPC directly

If you were previously using the clarifai-nodejs-grpc package or you want to access the full range of Clarifai API features, you can use the GRPC client directly.

import {
  PostModelOutputsRequest,
  V2Client,
} from "clarifai-node-serverless/grpc/proto/clarifai/api/service";
import { ChannelCredentials, Metadata } from "@grpc/grpc-js";
import { StatusCode } from "clarifai-node-serverless/grpc/proto/clarifai/api/status/status_code";

const client = new V2Client(
  "api.clarifai.com:443",
  ChannelCredentials.createSsl(),
);

const postModelOutputsRequest = PostModelOutputsRequest.fromPartial({
  modelId: "aaa03c23b3724a16a56b629203edc62c",
  inputs: [
    {
      data: {
        image: {
          url: "https://samples.clarifai.com/dog2.jpeg",
        },
      },
    },
  ],
});

const metadata = new Metadata();
metadata.set("authorization", `key ${process.env.CLARIFAI_PAT}`);

client.postModelOutputs(postModelOutputsRequest, metadata, (err, response) => {
  if (err) {
    console.log("Error: " + err);
    return;
  }

  if (response?.status?.code !== StatusCode.SUCCESS) {
    console.log(
      "Received failed status: " +
        response?.status?.description +
        "\n" +
        response?.status?.details,
    );
    return;
  }

  console.log("results:");
  console.log(response?.outputs);
});

Keywords

clarifai

FAQs

Package last updated on 02 Sep 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.