---
title: Calculate usage costs in batch
slug: reference/calculate-usage-costs-in-batch
docTags: 
createdAt: 2025-03-18T18:28:03.938Z
---

{
  "id": "rSG0NJKoM0f8nFSPC7RKs",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://app.amberflo.io/payments/cost/usage-cost/batch",
    "servers": [
      {
        "url": "https://app.amberflo.io/payments/cost/usage-cost/batch"
      }
    ],
    "name": "Calculate usage costs in batch",
    "description": "<p>Calculates usage costs for multiple customers or time periods in a single batch operation.\nUse this endpoint for efficient bulk cost calculations and large-scale billing analysis.</p>\n<p>Use this endpoint to:</p>\n<ul>\n<li>Process multiple usage cost calculations efficiently</li>\n<li>Generate bulk billing reports across customers</li>\n<li>Perform batch cost analysis for multiple time periods</li>\n<li>Optimize API usage for large-scale cost calculations</li>\n</ul>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "optional",
          "name": "body",
          "type": "array",
          "description": "Array of usage cost calculation requests for batch processing across multiple customers or time periods",
          "customType": "payment.cost.UsageCostsKey.in[]",
          "schema": [
            {
              "name": "productId",
              "kind": "optional",
              "type": "string",
              "description": "Unique identifier of the product for which usage costs should be calculated.",
              "example": ""
            },
            {
              "name": "timeRange",
              "kind": "optional",
              "type": "object",
              "description": "Start and end timestamps defining the period for usage cost analysis.",
              "modelRef": "#/components/schemas/payment.common.TimeRange.in",
              "customType": "payment.common.TimeRange.in",
              "schema": [
                {
                  "name": "startTimeInSeconds",
                  "kind": "optional",
                  "type": "integer<int64>",
                  "description": "Unix timestamp marking the beginning of the time range in seconds",
                  "example": 0
                },
                {
                  "name": "endTimeInSeconds",
                  "kind": "optional",
                  "type": "integer<int64>",
                  "description": "Unix timestamp marking the end of time range or null for open-ended ranges",
                  "example": 0
                }
              ]
            },
            {
              "name": "timeGroupingInterval",
              "kind": "optional",
              "type": "string",
              "description": "Time interval for grouping usage data in the cost calculation results.",
              "modelRef": "#/components/schemas/common.aggregation.AggregationInterval.in",
              "customType": "common.aggregation.AggregationInterval.in",
              "schema": []
            },
            {
              "name": "filters",
              "kind": "optional",
              "type": "map",
              "description": "Dimensional filters to apply to the usage data. Keys are dimension names, values are arrays of allowed values.",
              "example": "",
              "customType": "map<string, string[]>",
              "schema": []
            },
            {
              "name": "groupBy",
              "kind": "optional",
              "type": "array",
              "description": "Dimensions to group results by, such as customerId or custom dimensions.",
              "example": "",
              "itemType": "string",
              "customType": "string[]",
              "itemExample": "",
              "itemDefault": ""
            },
            {
              "name": "page",
              "kind": "optional",
              "type": "object",
              "description": "Pagination configuration for handling large result sets.",
              "modelRef": "#/components/schemas/payment.common.Page.in",
              "customType": "payment.common.Page.in",
              "schema": [
                {
                  "name": "number",
                  "kind": "optional",
                  "type": "integer<int32>",
                  "description": "One-indexed page number to retrieve with token required for pages beyond first",
                  "example": 0
                },
                {
                  "name": "size",
                  "kind": "optional",
                  "type": "integer<int32>",
                  "description": "Number of items per page with valid range between 1 and 1000 inclusive",
                  "example": 0
                },
                {
                  "name": "token",
                  "kind": "optional",
                  "type": "string",
                  "description": "Pagination token required for navigating to pages beyond the first page",
                  "example": ""
                }
              ]
            },
            {
              "name": "take",
              "kind": "optional",
              "type": "object",
              "description": "Limit configuration for the number of cost records to return.",
              "modelRef": "#/components/schemas/payment.common.Take.in",
              "customType": "payment.common.Take.in",
              "schema": [
                {
                  "name": "limit",
                  "kind": "optional",
                  "type": "integer<int32>",
                  "description": "Maximum number of results to return for query with minimum value of 1",
                  "example": 0
                },
                {
                  "name": "isAscending",
                  "kind": "optional",
                  "type": "boolean",
                  "description": "Sort order direction with true for ascending and false for descending order",
                  "example": ""
                }
              ]
            }
          ],
          "modelRef": "#/components/schemas/payment.cost.UsageCostsKey.in",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "apiKey",
          "name": "X-API-KEY",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        }
      ]
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Returns array of usage cost results corresponding to each batch request with detailed breakdowns",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "array",
            "description": "Usage cost calculation results with time-series data and grouped cost breakdowns for the requested analysis period.",
            "customType": "payment.cost.UsageCosts.out[]",
            "schema": [
              {
                "name": "key",
                "kind": "optional",
                "type": "object",
                "description": "Request parameters that were used to generate this usage cost calculation.",
                "modelRef": "#/components/schemas/payment.cost.UsageCostsKey.out",
                "customType": "payment.cost.UsageCostsKey.out",
                "schema": [
                  {
                    "name": "productId",
                    "kind": "optional",
                    "type": "string",
                    "description": "Unique identifier of the product for which usage costs should be calculated",
                    "example": ""
                  },
                  {
                    "name": "timeRange",
                    "kind": "optional",
                    "type": "object",
                    "description": "Start and end timestamps defining the period for usage cost analysis",
                    "modelRef": "#/components/schemas/payment.common.TimeRange.in",
                    "customType": "payment.common.TimeRange.in",
                    "schema": [
                      {
                        "name": "startTimeInSeconds",
                        "kind": "optional",
                        "type": "integer<int64>",
                        "description": "Unix timestamp marking the beginning of the time range in seconds",
                        "example": 0
                      },
                      {
                        "name": "endTimeInSeconds",
                        "kind": "optional",
                        "type": "integer<int64>",
                        "description": "Unix timestamp marking the end of time range or null for open-ended ranges",
                        "example": 0
                      }
                    ]
                  },
                  {
                    "name": "timeGroupingInterval",
                    "kind": "optional",
                    "type": "string",
                    "description": "Time interval for grouping usage data in the cost calculation results",
                    "modelRef": "#/components/schemas/common.aggregation.AggregationInterval.in",
                    "customType": "common.aggregation.AggregationInterval.in",
                    "schema": []
                  },
                  {
                    "name": "filters",
                    "kind": "optional",
                    "type": "map",
                    "description": "Additional filtering criteria applied to usage data before cost calculation",
                    "example": "",
                    "customType": "map<string, string[]>",
                    "schema": []
                  },
                  {
                    "name": "groupBy",
                    "kind": "optional",
                    "type": "array",
                    "description": "Field names for grouping and aggregating usage costs in the response",
                    "example": "",
                    "itemType": "string",
                    "customType": "string[]",
                    "itemExample": "",
                    "itemDefault": ""
                  },
                  {
                    "name": "page",
                    "kind": "optional",
                    "type": "object",
                    "description": "Pagination configuration for handling large result sets",
                    "modelRef": "#/components/schemas/payment.common.Page.in",
                    "customType": "payment.common.Page.in",
                    "schema": [
                      {
                        "name": "number",
                        "kind": "optional",
                        "type": "integer<int32>",
                        "description": "One-indexed page number to retrieve with token required for pages beyond first",
                        "example": 0
                      },
                      {
                        "name": "size",
                        "kind": "optional",
                        "type": "integer<int32>",
                        "description": "Number of items per page with valid range between 1 and 1000 inclusive",
                        "example": 0
                      },
                      {
                        "name": "token",
                        "kind": "optional",
                        "type": "string",
                        "description": "Pagination token required for navigating to pages beyond the first page",
                        "example": ""
                      }
                    ]
                  },
                  {
                    "name": "take",
                    "kind": "optional",
                    "type": "object",
                    "description": "Limit configuration for the number of cost records to return",
                    "modelRef": "#/components/schemas/payment.common.Take.in",
                    "customType": "payment.common.Take.in",
                    "schema": [
                      {
                        "name": "limit",
                        "kind": "optional",
                        "type": "integer<int32>",
                        "description": "Maximum number of results to return for query with minimum value of 1",
                        "example": 0
                      },
                      {
                        "name": "isAscending",
                        "kind": "optional",
                        "type": "boolean",
                        "description": "Sort order direction with true for ascending and false for descending order",
                        "example": ""
                      }
                    ]
                  }
                ]
              },
              {
                "name": "secondsSinceEpochIntervals",
                "kind": "optional",
                "type": "array",
                "description": "Unix timestamp intervals representing the time periods covered in the cost analysis.",
                "example": "",
                "itemType": "integer",
                "customType": "integer[]",
                "itemExample": "",
                "itemDefault": ""
              },
              {
                "name": "costList",
                "kind": "optional",
                "type": "array",
                "description": "Grouped usage cost results broken down by the specified grouping criteria.",
                "modelRef": "#/components/schemas/payment.cost.UsageGroupCosts.out",
                "customType": "payment.cost.UsageGroupCosts.out[]",
                "schema": [
                  {
                    "name": "groupInfos",
                    "kind": "optional",
                    "type": "map",
                    "description": "Grouping criteria key-value pairs used to aggregate these usage costs together",
                    "example": "",
                    "customType": "map<string, string>",
                    "schema": []
                  },
                  {
                    "name": "meteredUnits",
                    "kind": "optional",
                    "type": "number",
                    "description": "Total metered usage units consumed across all time periods for this group",
                    "example": ""
                  },
                  {
                    "name": "price",
                    "kind": "optional",
                    "type": "number",
                    "description": "Final aggregated price after applying all discounts and promotional adjustments for group",
                    "example": ""
                  },
                  {
                    "name": "priceBeforeDiscounts",
                    "kind": "optional",
                    "type": "number",
                    "description": "Original calculated price before applying any prepaid credits or promotional discounts",
                    "example": ""
                  },
                  {
                    "name": "prepaidUsed",
                    "kind": "optional",
                    "type": "number",
                    "description": "Total amount of prepaid credits consumed to reduce charges for this group",
                    "example": ""
                  },
                  {
                    "name": "priceMinusPrepaid",
                    "kind": "optional",
                    "type": "number",
                    "description": "Price after subtracting prepaid credits but before applying promotional discounts",
                    "example": ""
                  },
                  {
                    "name": "payAsYouGoPromotionUsed",
                    "kind": "optional",
                    "type": "number",
                    "description": "Total value of pay-as-you-go promotional discounts applied to reduce charges",
                    "example": ""
                  },
                  {
                    "name": "nonPayAsYouGoPromotionUsed",
                    "kind": "optional",
                    "type": "number",
                    "description": "Total value of non-pay-as-you-go promotional discounts applied to reduce charges",
                    "example": ""
                  },
                  {
                    "name": "priceAfterPayAsYouGoPromotion",
                    "kind": "optional",
                    "type": "number",
                    "description": "Price after applying pay-as-you-go promotions but before other discount types",
                    "example": ""
                  },
                  {
                    "name": "priceAfterNonPayAsYouGoPromotion",
                    "kind": "optional",
                    "type": "number",
                    "description": "Price after applying non-pay-as-you-go promotions showing final promotional impact",
                    "example": ""
                  },
                  {
                    "name": "costs",
                    "kind": "optional",
                    "type": "array",
                    "description": "Time-series cost values showing usage and pricing statistics for each time interval",
                    "modelRef": "#/components/schemas/payment.cost.UsageGroupCostValue.out",
                    "customType": "payment.cost.UsageGroupCostValue.out[]",
                    "schema": [
                      {
                        "name": "startTimeInSeconds",
                        "kind": "optional",
                        "type": "integer<int64>",
                        "description": "Unix timestamp marking the beginning of this cost calculation time period",
                        "example": 0
                      },
                      {
                        "name": "meteredUnits",
                        "kind": "optional",
                        "type": "number",
                        "description": "Total metered usage units consumed during this time period for billing calculations",
                        "example": ""
                      },
                      {
                        "name": "price",
                        "kind": "optional",
                        "type": "number",
                        "description": "Final calculated price after applying all discounts and promotional adjustments",
                        "example": ""
                      },
                      {
                        "name": "pricePercentageDiff",
                        "kind": "optional",
                        "type": "number",
                        "description": "Percentage change in price compared to previous time period for trend analysis",
                        "example": ""
                      },
                      {
                        "name": "meterUnitsPercentageDiff",
                        "kind": "optional",
                        "type": "number",
                        "description": "Percentage change in metered units compared to previous time period for usage trends",
                        "example": ""
                      },
                      {
                        "name": "priceBeforeDiscounts",
                        "kind": "optional",
                        "type": "number",
                        "description": "Original calculated price before applying prepaid credits and promotional discounts",
                        "example": ""
                      },
                      {
                        "name": "prepaidUsed",
                        "kind": "optional",
                        "type": "number",
                        "description": "Amount of prepaid credits consumed to reduce customer charges for this period",
                        "example": ""
                      },
                      {
                        "name": "payAsYouGoPromotionUsed",
                        "kind": "optional",
                        "type": "number",
                        "description": "Value of pay-as-you-go promotional discounts applied to reduce customer charges",
                        "example": ""
                      }
                    ]
                  }
                ]
              },
              {
                "name": "pageInfo",
                "kind": "optional",
                "type": "object",
                "description": "Pagination metadata for navigating through large cost calculation result sets.",
                "modelRef": "#/components/schemas/payment.common.PageInfo.out",
                "customType": "payment.common.PageInfo.out",
                "schema": [
                  {
                    "name": "pageNumber",
                    "kind": "optional",
                    "type": "integer<int32>",
                    "description": "Current page number being returned in this response using one-indexed numbering",
                    "example": 0
                  },
                  {
                    "name": "pageSize",
                    "kind": "optional",
                    "type": "integer<int32>",
                    "description": "Number of items per page configured for this paginated query response",
                    "example": 0
                  },
                  {
                    "name": "pageToken",
                    "kind": "optional",
                    "type": "string",
                    "description": "Token for accessing the next page of results in subsequent pagination requests",
                    "example": ""
                  },
                  {
                    "name": "totalPages",
                    "kind": "optional",
                    "type": "integer<int32>",
                    "description": "Total number of pages available for this query across all results",
                    "example": 0
                  },
                  {
                    "name": "totalResults",
                    "kind": "optional",
                    "type": "integer<int32>",
                    "description": "Total count of all items available across all pages for this query",
                    "example": 0
                  }
                ]
              }
            ],
            "modelRef": "#/components/schemas/payment.cost.UsageCosts.out",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Invalid batch parameters or malformed request array provided",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "Authentication required or invalid API key provided",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "403",
        "description": "Insufficient permissions to perform batch usage cost calculations",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "404",
        "description": "Some customers or usage data not found in batch request",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "500",
        "description": "Internal server error occurred during batch usage cost processing",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "_w69fTBoytpqe-cqGjU48",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://app.amberflo.io/payments/cost/usage-cost/batch \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '[\n     {}\n     ]'"
        },
        {
          "id": "jua5XT4kX9nKdqS6On7J_",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify([\n   {}\n]);\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://app.amberflo.io/payments/cost/usage-cost/batch\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "qAedvyJ6txN7oFVLotP6V",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://app.amberflo.io/payments/cost/usage-cost/batch\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump([\n   {}\n])\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "Fm8ckfBSUlwU-loRr3zNz",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://app.amberflo.io/payments/cost/usage-cost/batch\"\n\npayload = json.dumps([\n   {}\n])\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "_w69fTBoytpqe-cqGjU48"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Returns array of usage cost results corresponding to each batch request with detailed breakdowns\n[\n  {\n    \"key\": {\n      \"productId\": \"\",\n      \"timeRange\": {\n        \"startTimeInSeconds\": \"\",\n        \"endTimeInSeconds\": \"\"\n      },\n      \"timeGroupingInterval\": \"\",\n      \"filters\": \"\",\n      \"groupBy\": [\n        \"\"\n      ],\n      \"page\": {\n        \"number\": \"\",\n        \"size\": \"\",\n        \"token\": \"\"\n      },\n      \"take\": {\n        \"limit\": \"\",\n        \"isAscending\": false\n      }\n    },\n    \"secondsSinceEpochIntervals\": [\n      0\n    ],\n    \"costList\": [\n      {\n        \"groupInfos\": \"\",\n        \"meteredUnits\": 0,\n        \"price\": 0,\n        \"priceBeforeDiscounts\": 0,\n        \"prepaidUsed\": 0,\n        \"priceMinusPrepaid\": 0,\n        \"payAsYouGoPromotionUsed\": 0,\n        \"nonPayAsYouGoPromotionUsed\": 0,\n        \"priceAfterPayAsYouGoPromotion\": 0,\n        \"priceAfterNonPayAsYouGoPromotion\": 0,\n        \"costs\": [\n          {\n            \"startTimeInSeconds\": \"\",\n            \"meteredUnits\": 0,\n            \"price\": 0,\n            \"pricePercentageDiff\": 0,\n            \"meterUnitsPercentageDiff\": 0,\n            \"priceBeforeDiscounts\": 0,\n            \"prepaidUsed\": 0,\n            \"payAsYouGoPromotionUsed\": 0\n          }\n        ]\n      }\n    ],\n    \"pageInfo\": {\n      \"pageNumber\": \"\",\n      \"pageSize\": \"\",\n      \"pageToken\": \"\",\n      \"totalPages\": \"\",\n      \"totalResults\": \"\"\n    }\n  }\n]"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Invalid batch parameters or malformed request array provided\n"
        },
        {
          "id": "response-2-401",
          "language": "401",
          "code": "// Authentication required or invalid API key provided\n"
        },
        {
          "id": "response-3-403",
          "language": "403",
          "code": "// Insufficient permissions to perform batch usage cost calculations\n"
        },
        {
          "id": "response-4-404",
          "language": "404",
          "code": "// Some customers or usage data not found in batch request\n"
        },
        {
          "id": "response-5-500",
          "language": "500",
          "code": "// Internal server error occurred during batch usage cost processing\n"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}