Summarize Image

API Host & Base path

Currently for this API the URL prefix is: https://ai-03.contentfabric.io/summary/

This may be subject to change in the future as different environments are created, and API endpoints are standardized across services.

Authorization token

This API requires an authorization token. There are many types of tokens, and generating the token is beyond the scope of this particular document.

Sample code for this API which generates a token locally using client.GenerateStateChannelToken({ objectId: iq })

#!/usr/bin/env node

const Fetch = typeof fetch !== "undefined" ? fetch : require("node-fetch").default;

const util = require('./util')
const BASE_SUMMARY_PATH = util.BASE_SUMMARY_PATH

async function getAssetSummary(token, iq, assetPath) {
  const url = `${BASE_SUMMARY_PATH}/q/${iq}/rep/image_summarize`

  const params = new URLSearchParams({
    path: assetPath,
    authorization: token
  });

  const response = await Fetch(url + "?" + params.toString(), {})

  if (response.status != 200 || response?.headers?.get("content-type") !== "application/json") return null

  return response.json()
}

async function main() {
  try {
    // content object and asset path to fetch
    const iq = "iq__2g4MHjXgoM2r14YJZfyVJzo6cwtW"
    const asset = "/assets/19313048.jpg"

    // get client
    console.debug("Getting client...")
    const client = await util.getConfiguredClient()

    // get token
    console.debug("Getting token...")
    const token = await util.getFabricToken(client, iq)

    // fetch asset tags
    console.debug("Generating summary...")
    const tags = await getAssetSummary(token, iq, asset)
    console.dir(tags, { depth: null} )
  }
  catch (err) {
    console.error(err)
    console.error(JSON.stringify(err, null, 2));
  }

}

main()

API

The endpoint is: <base>/q/{iq}/rep/image_summarize

The HTTP operation is GET

Where:

  • <base> is the API Host Base path
  • {iq} is the id of the content object containing the image assets

The call takes the following query parameters:

  • path a URL encoded path to the asset, typically %2Fassets%2F<filename>
  • authorization Authorization token for this request. Note: As of this writing, the API does not support authorization being passed as a header.

API Return

The API returns a JSON object with three keys:

  • summary The summary of the image
  • title A short title for the summary
  • hashtags A list of (usually three) hashtags for the image
{
  "summary": "Jessica Berman participates in an interview or press conference, sitting at a table with a black backdrop featuring various logos including Mastercard, Nike, and Delta.",
  "title": "Jessica Berman Speaks at Official Event",
  "hashtags": ["#Interview", "#PressConference", "#BusinessEvent"]
}