docs: function getMediaByAPI (uri, cert, mode, user, safe, bufferURI) {
    return new Promise(function (resolve, reject) {
      balance(user).then((ret) => {
        return ret
      }).then(function (ret) {
        if (ret >= algos.getRandomUnseenImage.cost) {
          qpm_media.getRandomUnseenImage().then(function (row) {
            row.conn.close()
            resolve(row.ret[0][0])
  
            // pay
            var credit = {}
            credit['https://w3id.org/cc#source'] = user
            credit['https://w3id.org/cc#amount'] = algos.getRandomUnseenImage.cost
            credit['https://w3id.org/cc#currency'] = 'https://w3id.org/cc#bit'
            credit['https://w3id.org/cc#destination'] = algos.getRandomUnseenImage.counterparty
            pay(credit)
          }).catch(function (err) {
            row.conn.close()
            reject(err)
          })
        } else {
          reject(new Error('not enough funds'))
        }
      })
    })
  }