Flexreport to get AI token usage details across AWS, Azure and GCP
search cancel

Flexreport to get AI token usage details across AWS, Azure and GCP

book

Article ID: 429970

calendar_today

Updated On:

Products

CloudHealth

Issue/Introduction

You can utilize below FlexReport query to retrieve AI token usage details across AWS, Azure and GCP

Resolution

{
  "sqlStatement": "SELECT 'AWS' AS Cloud, timeInterval_Month AS Month, lineItem_UsageAccountId AS Account_ID, product_ProductName AS Service, CASE WHEN lineItem_LegalEntity LIKE '%Amazon%' THEN lineItem_UsageType ELSE product_ProductName END AS Model_or_UsageType, SUM(lineItem_NetUnblendedCost) AS BilledCost, SUM(lineItem_UsageAmount) AS Usage_Quantity, pricing_unit AS Unit FROM AWS_CUR WHERE ( lineItem_ProductCode IN ( 'AmazonBedrock', 'AmazonSageMaker', 'AmazonRekognition', 'AmazonPolly', 'AmazonTranscribe', 'AmazonTranslate', 'AmazonComprehend', 'AmazonPersonalize', 'AmazonForecast', 'AmazonKendra', 'AmazonTextract', 'AmazonQ' ) OR product_ProductName LIKE '%Bedrock%' OR product_ProductName LIKE '%SageMaker%' OR product_ProductName LIKE '%Machine Learning%' OR LOWER(lineItem_UsageType) LIKE '%token%' ) GROUP BY 1, 2, 3, 4, 5, 8 UNION ALL SELECT 'Azure' AS Cloud, timeInterval_Month AS Month, SubscriptionId AS Account_ID, ConsumedService AS Service, CASE WHEN PublisherType = 'Azure' THEN MeterName WHEN PublisherType = 'Marketplace' THEN PlanName ELSE ProductName END AS Model_or_UsageType, SUM(AmortizedCostInBillingCurrency) AS BilledCost, SUM(Quantity) AS Usage_Quantity, UnitOfMeasure AS Unit FROM AZURE_COST_USAGE WHERE ( ConsumedService IN ( 'Microsoft.CognitiveServices', 'Microsoft.MachineLearningServices', 'Microsoft.Search', 'Microsoft.BotService' ) OR ProductName LIKE '%OpenAI%' OR ProductName LIKE '%Foundry%' OR ProductName LIKE '%Cognitive%' OR LOWER(ProductName) LIKE '%token%' ) GROUP BY 1, 2, 3, 4, 5, 8 UNION ALL SELECT 'GCP' AS Cloud, timeInterval_Month AS Month, Project_Id AS Account_ID, Service_Description AS Service, Sku_Description AS Model_or_UsageType, SUM(Cost) AS BilledCost, SUM(Consumption) AS Usage_Quantity, Units AS Unit FROM GCP_BILLING_EXPORT WHERE ( LOWER(Service_Description) LIKE '%vertex%' OR LOWER(Service_Description) LIKE '%ai%' OR LOWER(Service_Description) LIKE '%gemini%' OR LOWER(Service_Description) LIKE '%machine learning%' OR LOWER(Service_Description) LIKE '%vision%' OR LOWER(Service_Description) LIKE '%speech%' OR LOWER(Service_Description) LIKE '%dialogflow%' OR LOWER(Service_Description) LIKE '%translation%' OR LOWER(Service_Description) LIKE '%natural language%' OR LOWER(Sku_Description) LIKE '%token%' ) GROUP BY 1, 2, 3, 4, 5, 8",
  "dataGranularity": "MONTHLY",
  "timeRange": {
    "last": 12
  },
  "limit": -1
}