Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clarifai

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clarifai

Official Clarifai Javascript SDK

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
475
decreased by-23.01%
Maintainers
2
Weekly downloads
 
Created
Source

Clarifai JavaScript Client

The official JavaScript client for interacting with the Clarifai API.

Basic Use

To start, install the SDK via NPM: npm install clarifai and initialize with your clientId and clientSecret:

This will work in node.js and browsers via Browserify

var Clarifai = require('clarifai');

Clarifai.initialize({
  'clientId': '{clientId}',
  'clientSecret': '{clientSecret}'
});

You can also use the SDK by adding this script to your HTML:

<script type="text/javascript" src="https://sdk.clarifai.com/js/clarifai-1.2.0.js"></script>
<script>
  Clarifai.initialize({
    'clientId': '{clientId}',
    'clientSecret': '{clientSecret}'
  });
</script>

Table of Contents

Tag
Info
Languages
Color
Usage
Feedback
Token
Promises and Callbacks

Examples

Tag

Get tags for an image via url
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg').then(
  handleResponse,
  handleError
);
Get tags for multiple images via url
Clarifai.getTagsByUrl([
  'https://samples.clarifai.com/wedding.jpg',
  'https://samples.clarifai.com/cookies.jpeg'
]).then(
  handleResponse,
  handleError
);
Get tags for an image via image bytes
Clarifai.getTagsByImageBytes('R0lGODlhZAHIAPcAAKeno6Oinc3Do6iVeMe7o1ZEM...').then(
  handleResponse,
  handleError
);
Get tags for an image via url passing in a model
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg', {
  'model': 'nsfw-v0.1'
}).then(
  handleResponse,
  handleError
);
Get tags for an image via url passing in a language
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg', {
  'language': 'es'
}).then(
  handleResponse,
  handleError
);
Get tags for an image via url and set a localId
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg', {
  'localId': 'myLocalId'
}).then(
  handleResponse,
  handleError
);
Get tags for an image via url and restrict the tags returned
Clarifai.getTagsByUrl(
  'https://samples.clarifai.com/wedding.jpg',
  {
    'selectClasses': ['people', 'dress', 'wedding']
  }
).then(
  handleResponse,
  handleError
);

Info

Get API info
Clarifai.getInfo().then(
  handleResponse,
  handleError
);

Languages

Get supported languages
Clarifai.getLanguages().then(
  handleResponse,
  handleError
);

Color

Get colors for an image via url
Clarifai.getColorsByUrl('https://samples.clarifai.com/wedding.jpg').then(
  handleResponse,
  handleError
);
Get colors for an image via image bytes
Clarifai.getColorsByImageBytes('R0lGODlhZAHIAPcAAKeno6Oinc3Do6iVeMe7o1ZEM...').then(
  handleResponse,
  handleError
);

Usage

Get API usage
Clarifai.getUsage().then(
  handleResponse,
  handleError
);

Feedback

Send feedback to the API
Clarifai.createFeedback('https://samples.clarifai.com/wedding.jpg', {
  'addTags': ['family', 'friends',],
  'removeTags': ['military', 'protest'],
}).then(
  handleResponse,
  handleError
);

Token

Get a token

Note: You should not have to call this directly in most cases. Any method that needs a token will call it for you.

Clarifai.getToken().then(
  function(response) {
    console.log(response);
  },
  function(err){
    console.log(err);
  }
);
Set a token
var tokenSetBoolean = Clarifai.setToken('some-token-string');
Delete a token
Clarifai.deleteToken();

Promises and Callbacks

All methods return promises. If you'd rather user callbacks, just pass in a callback function as the last param to any method. If there are multiple params and some are optional, you'll need to pass in null for those.

FAQs

Package last updated on 16 Jun 2016

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc