Search code examples
autodesk-forgeautodesk-designautomation

Trouble estimating design automation token usage


I'm following this article's method to calculate the token usage and then the cost. I run the following calculation on the workitem oncomplete callback and store them in a db.

function getJobMetrics(jobDetails) {
  const { stats } = jobDetails.jobStatus;
  const timeQueued = Date.parse(stats.timeQueued);
  const timeDownloadStarted = Date.parse(stats.timeDownloadStarted);
  const timeUploadEnded = Date.parse(stats.timeUploadEnded);
  const timeInstructionsStarted = Date.parse(stats.timeInstructionsStarted);
  const timeInstructionsEnded = Date.parse(stats.timeInstructionsEnded);
  const queueDelay = timeDownloadStarted - timeQueued;
  const downloadDelay = timeInstructionsStarted - timeDownloadStarted;
  const instructionsRunDuration = timeInstructionsEnded - timeInstructionsStarted;

  const totalDuration = timeInstructionsEnded - timeQueued;
  // https://aps.autodesk.com/blog/estimate-design-automation-costs
  // in case of failure, timeUploadEnded is null
  const adskCalculatedTimeTaken = (timeUploadEnded || timeInstructionsEnded) - timeDownloadStarted;
  const adskTokenUsageInCloudCredits = (adskCalculatedTimeTaken / 1000 / 60 / 60) * 6;
  return {
    adskDasQueueDelay: queueDelay, 
    adskDasDownloadDelay: downloadDelay, 
    adskDasInstructionsRunDuration: instructionsRunDuration,
    adskDasTotalDuration: totalDuration, 
    adskDasTotalBytesDownloaded: stats.bytesDownloaded, 
    adskCalculatedTimeTaken,
    adskTokenUsageInCloudCredits, 
  };
}

When I aggregate adskTokenUsageInCloudCredits over time for all the workitems I have in a month, it doesn't match the numbers that I see on the analytics dashboard on APS. My numbers seem an order of magnitude higher. I didn't find any APIs that I can query for individual events that consumed tokens. What am I doing wrong?


Solution

  • DA API charges 2 cloud credits per processing hour/

    const adskTokenUsageInCloudCredits = (adskCalculatedTimeTaken / 1000 / 60 / 60) * 2
    

    Refer https://aps.autodesk.com/pricing

    APS Pricing