Skip to main content
POST
/
costs
/
analytics
Get combined revenue and cost analytics
curl --request POST \
  --url https://api.cloud.flexprice.io/v1/costs/analytics \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "end_time": "<string>",
  "expand": [
    "<string>"
  ],
  "external_customer_id": "<string>",
  "limit": 123,
  "meter_ids": [
    "<string>"
  ],
  "offset": 123,
  "start_time": "<string>"
}'
{
  "cost_analytics": [
    {
      "cost_by_period": [
        {
          "cost": 123,
          "event_count": 123,
          "quantity": 123,
          "timestamp": "<string>"
        }
      ],
      "costsheet_id": "<string>",
      "currency": "<string>",
      "customer_id": "<string>",
      "external_customer_id": "<string>",
      "meter": {
        "aggregation": {
          "bucket_size": "MINUTE",
          "field": "<string>",
          "multiplier": 123,
          "type": "COUNT"
        },
        "created_at": "<string>",
        "created_by": "<string>",
        "environment_id": "<string>",
        "event_name": "<string>",
        "filters": [
          {
            "key": "<string>",
            "values": [
              "<string>"
            ]
          }
        ],
        "id": "<string>",
        "name": "<string>",
        "reset_usage": "BILLING_PERIOD",
        "status": "published",
        "tenant_id": "<string>",
        "updated_at": "<string>",
        "updated_by": "<string>"
      },
      "meter_id": "<string>",
      "meter_name": "<string>",
      "price": {
        "amount": 123,
        "billing_cadence": "RECURRING",
        "billing_model": "FLAT_FEE",
        "billing_period": "MONTHLY",
        "billing_period_count": 123,
        "conversion_rate": 123,
        "created_at": "<string>",
        "created_by": "<string>",
        "currency": "<string>",
        "description": "<string>",
        "display_amount": "<string>",
        "display_price_unit_amount": "<string>",
        "end_date": "<string>",
        "entity_id": "<string>",
        "entity_type": "PLAN",
        "environment_id": "<string>",
        "group_id": "<string>",
        "id": "<string>",
        "invoice_cadence": "ARREAR",
        "lookup_key": "<string>",
        "metadata": {},
        "meter_id": "<string>",
        "parent_price_id": "<string>",
        "price_unit": "<string>",
        "price_unit_amount": 123,
        "price_unit_id": "<string>",
        "price_unit_tiers": [
          {
            "flat_amount": 123,
            "unit_amount": 123,
            "up_to": 123
          }
        ],
        "price_unit_type": "FIAT",
        "start_date": "<string>",
        "status": "published",
        "tenant_id": "<string>",
        "tier_mode": "VOLUME",
        "tiers": [
          {
            "flat_amount": 123,
            "unit_amount": 123,
            "up_to": 123
          }
        ],
        "transform_quantity": {
          "divide_by": 123,
          "round": "<string>"
        },
        "trial_period": 123,
        "type": "USAGE",
        "updated_at": "<string>",
        "updated_by": "<string>"
      },
      "price_id": "<string>",
      "properties": {},
      "source": "<string>",
      "total_cost": 123,
      "total_events": 123,
      "total_quantity": 123
    }
  ],
  "currency": "<string>",
  "end_time": "<string>",
  "margin": 123,
  "margin_percent": 123,
  "roi": 123,
  "roi_percent": 123,
  "start_time": "<string>",
  "total_cost": 123,
  "total_revenue": 123
}

Authorizations

x-api-key
string
header
required

Enter your API key in the format x-api-key <api-key>*

Body

application/json

Combined analytics request (start_time/end_time optional - defaults to last 7 days)

end_time
string
expand
string[]

Expand options - specify which entities to expand

external_customer_id
string

Optional - for specific customer

limit
integer

Pagination

meter_ids
string[]

Additional filters

offset
integer
start_time
string

Time range fields (optional - defaults to last 7 days if not provided)

Response

OK

cost_analytics
object[]

Cost analytics array (flattened from nested structure)

currency
string
end_time
string
margin
number

Revenue - Cost

margin_percent
number

(Margin / Revenue) * 100

roi
number

(Revenue - Cost) / Cost

roi_percent
number

ROI * 100

start_time
string
total_cost
number
total_revenue
number

Derived metrics