curl --request POST \
--url https://us.api.flexprice.io/v1/costs/analytics \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"end_time": "2023-11-07T05:31:56Z",
"expand": [
"<string>"
],
"external_customer_id": "<string>",
"feature_ids": [
"<string>"
],
"include_children": true,
"limit": 123,
"offset": 123,
"property_filters": {},
"start_time": "2023-11-07T05:31:56Z"
}
'from flexprice import Flexprice
with Flexprice(
api_key_auth="<YOUR_API_KEY_HERE>",
) as f_client:
res = f_client.costs.get_detailed_cost_analytics()
# Handle response
print(res)import { Flexprice } from "@flexprice/sdk";
const flexprice = new Flexprice({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await flexprice.costs.getDetailedCostAnalytics({});
console.log(result);
}
run();package main
import(
"context"
flexprice "github.com/flexprice/go-sdk/v2"
"github.com/flexprice/go-sdk/v2/models/types"
"log"
)
func main() {
ctx := context.Background()
s := flexprice.New(
flexprice.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Costs.GetDetailedCostAnalytics(ctx, types.GetCostAnalyticsRequest{})
if err != nil {
log.Fatal(err)
}
if res.GetDetailedCostAnalyticsResponse != nil {
// handle response
}
}{
"cost_analytics": [
{
"cost_by_period": [
{
"cost": "<string>",
"event_count": 123,
"quantity": "<string>",
"timestamp": "<string>"
}
],
"costsheet_id": "<string>",
"currency": "<string>",
"customer_id": "<string>",
"external_customer_id": "<string>",
"meter": {
"aggregation": {
"bucket_size": "MINUTE",
"expression": "<string>",
"field": "<string>",
"group_by": "<string>",
"multiplier": "<string>",
"type": "COUNT"
},
"created_at": "2023-11-07T05:31:56Z",
"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": "2023-11-07T05:31:56Z",
"updated_by": "<string>"
},
"meter_id": "<string>",
"meter_name": "<string>",
"price": {
"amount": "<string>",
"billing_cadence": "RECURRING",
"billing_model": "FLAT_FEE",
"billing_period": "MONTHLY",
"billing_period_count": 123,
"bucket_size": "MINUTE",
"conversion_rate": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"created_by": "<string>",
"currency": "<string>",
"description": "<string>",
"display_amount": "<string>",
"display_name": "<string>",
"display_price_unit_amount": "<string>",
"end_date": "2023-11-07T05:31:56Z",
"entity_id": "<string>",
"entity_type": "PLAN",
"environment_id": "<string>",
"group_id": "<string>",
"id": "<string>",
"invoice_cadence": "ARREAR",
"lookup_key": "<string>",
"metadata": {},
"meter_id": "<string>",
"min_quantity": "<string>",
"parent_price_id": "<string>",
"price_unit": "<string>",
"price_unit_amount": "<string>",
"price_unit_id": "<string>",
"price_unit_tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"price_unit_type": "FIAT",
"sequence": 123,
"start_date": "2023-11-07T05:31:56Z",
"status": "published",
"tenant_id": "<string>",
"tier_mode": "VOLUME",
"tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"transform_quantity": {
"divide_by": 123,
"round": "up"
},
"trial_period_days": 123,
"type": "USAGE",
"updated_at": "2023-11-07T05:31:56Z",
"updated_by": "<string>"
},
"price_id": "<string>",
"properties": {},
"source": "<string>",
"total_cost": "<string>",
"total_events": 123,
"total_quantity": "<string>"
}
],
"currency": "<string>",
"end_time": "2023-11-07T05:31:56Z",
"margin": "<string>",
"margin_percent": "<string>",
"roi": "<string>",
"roi_percent": "<string>",
"start_time": "2023-11-07T05:31:56Z",
"total_cost": "<string>",
"total_revenue": "<string>"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}Get combined revenue and cost analytics
Use when building dashboards or reports that need revenue vs cost, ROI, and margin over a time period (e.g. finance views or executive summaries).
curl --request POST \
--url https://us.api.flexprice.io/v1/costs/analytics \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"end_time": "2023-11-07T05:31:56Z",
"expand": [
"<string>"
],
"external_customer_id": "<string>",
"feature_ids": [
"<string>"
],
"include_children": true,
"limit": 123,
"offset": 123,
"property_filters": {},
"start_time": "2023-11-07T05:31:56Z"
}
'from flexprice import Flexprice
with Flexprice(
api_key_auth="<YOUR_API_KEY_HERE>",
) as f_client:
res = f_client.costs.get_detailed_cost_analytics()
# Handle response
print(res)import { Flexprice } from "@flexprice/sdk";
const flexprice = new Flexprice({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await flexprice.costs.getDetailedCostAnalytics({});
console.log(result);
}
run();package main
import(
"context"
flexprice "github.com/flexprice/go-sdk/v2"
"github.com/flexprice/go-sdk/v2/models/types"
"log"
)
func main() {
ctx := context.Background()
s := flexprice.New(
flexprice.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Costs.GetDetailedCostAnalytics(ctx, types.GetCostAnalyticsRequest{})
if err != nil {
log.Fatal(err)
}
if res.GetDetailedCostAnalyticsResponse != nil {
// handle response
}
}{
"cost_analytics": [
{
"cost_by_period": [
{
"cost": "<string>",
"event_count": 123,
"quantity": "<string>",
"timestamp": "<string>"
}
],
"costsheet_id": "<string>",
"currency": "<string>",
"customer_id": "<string>",
"external_customer_id": "<string>",
"meter": {
"aggregation": {
"bucket_size": "MINUTE",
"expression": "<string>",
"field": "<string>",
"group_by": "<string>",
"multiplier": "<string>",
"type": "COUNT"
},
"created_at": "2023-11-07T05:31:56Z",
"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": "2023-11-07T05:31:56Z",
"updated_by": "<string>"
},
"meter_id": "<string>",
"meter_name": "<string>",
"price": {
"amount": "<string>",
"billing_cadence": "RECURRING",
"billing_model": "FLAT_FEE",
"billing_period": "MONTHLY",
"billing_period_count": 123,
"bucket_size": "MINUTE",
"conversion_rate": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"created_by": "<string>",
"currency": "<string>",
"description": "<string>",
"display_amount": "<string>",
"display_name": "<string>",
"display_price_unit_amount": "<string>",
"end_date": "2023-11-07T05:31:56Z",
"entity_id": "<string>",
"entity_type": "PLAN",
"environment_id": "<string>",
"group_id": "<string>",
"id": "<string>",
"invoice_cadence": "ARREAR",
"lookup_key": "<string>",
"metadata": {},
"meter_id": "<string>",
"min_quantity": "<string>",
"parent_price_id": "<string>",
"price_unit": "<string>",
"price_unit_amount": "<string>",
"price_unit_id": "<string>",
"price_unit_tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"price_unit_type": "FIAT",
"sequence": 123,
"start_date": "2023-11-07T05:31:56Z",
"status": "published",
"tenant_id": "<string>",
"tier_mode": "VOLUME",
"tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"transform_quantity": {
"divide_by": 123,
"round": "up"
},
"trial_period_days": 123,
"type": "USAGE",
"updated_at": "2023-11-07T05:31:56Z",
"updated_by": "<string>"
},
"price_id": "<string>",
"properties": {},
"source": "<string>",
"total_cost": "<string>",
"total_events": 123,
"total_quantity": "<string>"
}
],
"currency": "<string>",
"end_time": "2023-11-07T05:31:56Z",
"margin": "<string>",
"margin_percent": "<string>",
"roi": "<string>",
"roi_percent": "<string>",
"start_time": "2023-11-07T05:31:56Z",
"total_cost": "<string>",
"total_revenue": "<string>"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}Authorizations
Enter your API key in the format x-api-key <api-key>*
Body
Combined analytics request (start_time/end_time optional - defaults to last 7 days)
Expand options - specify which entities to expand
Optional - for specific customer
Additional filters
IncludeChildren, when true and ExternalCustomerID belongs to a parent customer, aggregates every inherited-child customer's usage into the revenue and cost totals. Default (false) restricts the query to the customer's own usage — mirrors the meter-usage analytics contract.
Pagination
Property filters to filter the events by the keys in properties field of the event
Show child attributes
Show child attributes
Time range fields (optional - defaults to last 7 days if not provided)
Response
OK
Cost analytics array (flattened from nested structure)
Show child attributes
Show child attributes
Revenue - Cost
(Margin / Revenue) * 100
(Revenue - Cost) / Cost
ROI * 100
Derived metrics

