package module
Version: v1.2.1-0...-11d887c Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2017 License: Apache-2.0 Imports: 9 Imported by: 0


Clarifai Golang Library

Library for our v1 API.



This API client only supports Clarifai v1 API. Stay tuned for the v2 support.


go get

package main

import (


func main() {
	client := clarifai.NewClient("<client_id>", "<client_secret>")
	// Get the current status of things
	info, err := client.Info()
	if err != nil {
	} else {
		fmt.Printf("%+v\n", info)
	// Let's get some context about these images
	urls := []string{"", ""}
	// Give it to Clarifai to run their magic
	tag_data, err := client.Tag(clarifai.TagRequest{URLs: urls})

	if err != nil {
	} else {
		fmt.Printf("%+v\n", tag_data) // See what we got!

	feedback_data, err := client.Feedback(clarifai.FeedbackForm{
		URLs:    urls,
		AddTags: []string{"cat", "animal"},

	if err != nil {
	} else {
		fmt.Printf("%+v\n", feedback_data)


Run go test

##Special Thanks

Thanks so much to Sam Couch for his amazing contribution to the Clarifai client libraries by starting this one and graciously handing it off to us. Follow him on Twitter @SamuelCouch.



Package clarifai provides a client interface to the Clarifai public API



This section is empty.


This section is empty.


This section is empty.


type Client

type Client struct {
	ClientID     string
	ClientSecret string
	AccessToken  string
	APIRoot      string
	Throttled    bool

Client contains scoped variables forindividual clients

func NewClient

func NewClient(clientID, clientSecret string) *Client

NewClient initializes a new Clarifai client

func (*Client) Feedback

func (client *Client) Feedback(form FeedbackForm) (*FeedbackResp, error)

Feedback allows the user to provide contextual feedback to Clarifai in order to improve their results

func (*Client) Info

func (client *Client) Info() (*InfoResp, error)

Info will return the current status info for the given client

func (*Client) Tag

func (client *Client) Tag(req TagRequest) (*TagResp, error)

Tag allows the client to request tag data on a single, or multiple photos

type FeedbackForm

type FeedbackForm struct {
	DocIDs           []string `json:"docids,omitempty"`
	URLs             []string `json:"url,omitempty"`
	AddTags          []string `json:"add_tags,omitempty"`
	RemoveTags       []string `json:"remove_tags,omitempty"`
	DissimilarDocIDs []string `json:"dissimilar_docids,omitempty"`
	SimilarDocIDs    []string `json:"similar_docids,omitempty"`
	SearchClick      []string `json:"search_click,omitempty"`

FeedbackForm is used to send feedback back to Clarifai

type FeedbackResp

type FeedbackResp struct {
	StatusCode    string `json:"status_code"`
	StatusMessage string `json:"status_msg"`

FeedbackResp is the expected response from /feedback/

type InfoResp

type InfoResp struct {
	StatusCode    string `json:"status_code"`
	StatusMessage string `json:"status_msg"`
	Results       struct {
		MaxImageSize      int     `json:"max_image_size"`
		DefaultLanguage   string  `json:"default_language"`
		MaxVideoSize      int     `json:"max_video_size"`
		MaxImageBytes     int     `json:"max_image_bytes"`
		DefaultModel      string  `json:"default_model"`
		MaxVideoBytes     int     `json:"max_video_bytes"`
		MaxVideoDuration  int     `json:"max_video_duration"`
		MaxVideoBatchSize int     `json:"max_video_batch_size"`
		MinVideoSize      int     `json:"min_video_size"`
		MinImageSize      int     `json:"min_image_size"`
		MaxBatchSize      int     `json:"max_batch_size"`
		APIVersion        float32 `json:"api_version"`

InfoResp represents the expected JSON response from /info/

type TagRequest

type TagRequest struct {
	URLs     []string `json:"url"`
	LocalIDs []string `json:"local_ids,omitempty"`
	Model    string   `json:"model,omitempty"`

TagRequest represents a JSON request for /tag/

type TagResp

type TagResp struct {
	StatusCode    string `json:"status_code"`
	StatusMessage string `json:"status_msg"`
	Meta          struct {
		Tag struct {
			Timestamp json.Number `json:"timestamp"`
			Model     string      `json:"model"`
			Config    string      `json:"config"`
	Results []TagResult

TagResp represents the expected JSON response from /tag/

type TagResult

type TagResult struct {
	DocID         *big.Int `json:"docid"`
	URL           string   `json:"url"`
	StatusCode    string   `json:"status_code"`
	StatusMessage string   `json:"status_msg"`
	LocalID       string   `json:"local_id"`
	Result        struct {
		Tag struct {
			Classes []string  `json:"classes"`
			CatIDs  []string  `json:"catids"`
			Probs   []float32 `json:"probs"`
	DocIDString string `json:"docid_str"`

TagResult represents the expected data for a single tag result

type TokenResp

type TokenResp struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
	TokenType   string `json:"token_type"`

TokenResp is the expected response from /token/

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL