Insights API
Get insights summary
Returns period-over-period totals, population distributions, top movers with z-scores, margin outliers, and cross-metric correlations. Call it with a GET request to /insights/summary, authenticated with a restricted API key and the "costs:read", "revenue:read" scopes.
Returns period-over-period totals, population distributions, top movers with z-scores, margin outliers, and cross-metric correlations. Designed for AI agent consumption: pure statistical data, no narrative. Use this endpoint when you need distributions, z-scored top movers, margin outliers, and correlations; use /cost-data/summary for a simple cost rollup with period comparison. All monetary values are USD. Totals (cost, revenue), top-mover costs, and distribution statistics are expressed in dollars; unmappedSpend fields are integer cents. Requests count toward your per-API-key rate limit; sustained overruns return 429 with the standard error envelope.
Authentication and scopes
Authenticate with a restricted API key in the Authorization: Bearer <key> header. This endpoint requires the costs:read, revenue:read scopes.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start | query | string | Yes | Start of date range (ISO 8601, inclusive). Filters on event invocation time, evaluated in UTC. The requested range must not exceed 365 days; longer ranges return 400. |
end | query | string | Yes | End of date range (ISO 8601, exclusive). Filters on event invocation time, evaluated in UTC. The requested range must not exceed 365 days; longer ranges return 400. |
include | query | string | No | Optional sections to compute. Supported value: distributions. Unrecognized values are ignored. When omitted, the distributions field is null. |
limit | query | number (double) | No | Maximum number of top movers per category. Default 5. Values outside 1-50 are clamped to the nearest bound, not rejected; non-integer values are accepted. |
prior_start | query | string | No | Explicit prior period start (ISO 8601). Must be provided together with prior_end; if either is omitted, the prior period defaults to the window of equal length immediately preceding start. |
prior_end | query | string | No | Explicit prior period end (ISO 8601, exclusive). Must be provided together with prior_start; if either is omitted, the prior period defaults to the window of equal length immediately preceding start. |
Response fields
Fields returned in the 200 response body. Nested objects are listed under their parent. A field marked optional may be absent from the body; one marked nullable is always present but its value may be null.
| Field | Type | Description |
|---|---|---|
period | object | Analysis period metadata. |
current | object | Current analysis period. |
start | string | ISO 8601 date string. |
end | string | ISO 8601 date string. |
prior | object | Prior comparison period. Auto-derived as the window of equal length immediately preceding start, or taken from prior_start and prior_end when both are provided. |
start | string | ISO 8601 date string. |
end | string | ISO 8601 date string. |
totals | object | Period-over-period totals with change metrics. |
cost | object | Total cost comparison. Values are USD dollars. |
current | number (double) | Current period value. |
prior | number (double) | Prior period value. |
change_percent | number (double) nullable | Percent change from prior to current. Null when prior is 0 and current > 0 (new entry). |
revenue | object | Total revenue comparison. Values are USD dollars. |
current | number (double) | Current period value. |
prior | number (double) | Prior period value. |
change_percent | number (double) nullable | Percent change from prior to current. Null when prior is 0 and current > 0 (new entry). |
margin | object | Overall margin comparison (percentage points). |
current | number (double) | Current period margin percentage. |
prior | number (double) | Prior period margin percentage. |
change_points | number (double) | Percentage point change (current - prior). |
request_count | object | Total request count comparison. |
current | number (double) | Current period value. |
prior | number (double) | Prior period value. |
change_percent | number (double) nullable | Percent change from prior to current. Null when prior is 0 and current > 0 (new entry). |
active_end_users | object | Active end user count comparison. |
current | number (double) | Current period value. |
prior | number (double) | Prior period value. |
change_percent | number (double) nullable | Percent change from prior to current. Null when prior is 0 and current > 0 (new entry). |
distributions | object nullable | Population distributions. Null when not requested via include parameter. |
cost_per_end_user | object nullable | Cost distribution across end users, in USD dollars. Null when the period contains no qualifying data. |
mean | number (double) | Arithmetic mean. |
median | number (double) | Median (50th percentile). |
std_dev | number (double) | Population standard deviation. |
p25 | number (double) | 25th percentile. |
p75 | number (double) | 75th percentile. |
p90 | number (double) | 90th percentile. |
p99 | number (double) | 99th percentile. |
skewness | number (double) nullable | Fisher-Pearson skewness. Null if fewer than 3 users or zero variance. |
gini | number (double) nullable | Gini coefficient (0 = perfect equality, 1 = maximum inequality). Null if fewer than 2 users. |
top_decile_share | number (double) nullable | Percentage of total cost from the top 10% of users. Null if insufficient data. |
cost_per_request | object nullable | Cost-per-request distribution across end users, in USD dollars. Null when the period contains no qualifying data. |
mean | number (double) | Arithmetic mean. |
median | number (double) | Median (50th percentile). |
std_dev | number (double) | Population standard deviation. |
p25 | number (double) | 25th percentile. |
p75 | number (double) | 75th percentile. |
p90 | number (double) | 90th percentile. |
p99 | number (double) | 99th percentile. |
margin_per_end_user | object nullable | Margin percentage distribution across end users. Null when the period contains no qualifying data. |
mean | number (double) | Arithmetic mean. |
median | number (double) | Median (50th percentile). |
std_dev | number (double) | Population standard deviation. |
p25 | number (double) | 25th percentile. |
p75 | number (double) | 75th percentile. |
p90 | number (double) | 90th percentile. |
p99 | number (double) | 99th percentile. |
skewness | number (double) nullable | Fisher-Pearson skewness. Null if fewer than 3 users or zero variance. |
below_zero_count | number (double) | Number of end users with negative margin. |
daily_cost | object nullable | Daily cost distribution with trend, in USD dollars. Null when the period contains no qualifying data. |
mean | number (double) | Arithmetic mean of daily costs. |
median | number (double) | Median daily cost. |
std_dev | number (double) | Population standard deviation. |
min | number (double) | Minimum daily cost. |
max | number (double) | Maximum daily cost. |
cv | number (double) | Coefficient of variation (std_dev / mean). |
trend | object nullable | Linear regression trend. Null if fewer than 2 data points. |
r2 | number (double) | |
direction | increasing | decreasing | stable | |
slope | number (double) | |
requests_per_end_user | object nullable | Request count distribution across end users. Null when the period contains no qualifying data. |
mean | number (double) | Arithmetic mean. |
median | number (double) | Median (50th percentile). |
std_dev | number (double) | Population standard deviation. |
p25 | number (double) | 25th percentile. |
p75 | number (double) | 75th percentile. |
p90 | number (double) | 90th percentile. |
p99 | number (double) | 99th percentile. |
top_movers | object | Top movers by model, provider, end user, and custom dimensions. |
by_model | object[] | Top movers by model. |
value | string | Model slug. |
cost | number (double) | Current period cost (USD dollars). |
prior | number (double) | Prior period cost (USD dollars). |
change_percent | number (double) nullable | Percent change. Null when prior is 0 and current > 0 (new entry). |
share_percent | number (double) | Current period cost share (%). |
prior_share_percent | number (double) | Prior period cost share (%). |
z_score | number (double) nullable | Z-score of change relative to population. Null if all changes identical. |
request_count | number (double) | Request count in current period. |
avg_cost_per_request | number (double) | Average cost per request (USD dollars). |
by_provider | object[] | Top movers by provider. |
value | string | Provider slug. |
cost | number (double) | Current period cost (USD dollars). |
prior | number (double) | Prior period cost (USD dollars). |
change_percent | number (double) nullable | Percent change. Null when prior is 0 and current > 0 (new entry). |
share_percent | number (double) | Current period cost share (%). |
prior_share_percent | number (double) | Prior period cost share (%). |
z_score | number (double) nullable | Z-score of change relative to population. Null if all changes identical. |
by_end_user | object[] | Top movers by end user. |
value | string | End user external ID (the ID supplied on your usage events). |
cost | number (double) | Current period cost (USD dollars). |
prior | number (double) | Prior period cost (USD dollars). |
change_percent | number (double) nullable | Percent change. Null when prior is 0 and current > 0 (new entry). |
share_percent | number (double) | Current period cost share (%). |
z_score | number (double) nullable | Z-score of change relative to population. Null if all changes identical. |
percentile | number (double) nullable | Percentile rank by cost. Null if no data. |
margin | number (double) nullable | Current period margin percentage. Null if no revenue data. |
margin_percentile | number (double) nullable | Percentile rank by margin. Null if no margin data. |
model_mix | map of string to number (double) | Model mix: model slug to cost share percentage. |
by_custom_dimension | map of string to object[] | Top movers by custom dimension, keyed by dimension key. |
value | string | Dimension value. |
cost | number (double) | Current period cost (USD dollars). |
prior | number (double) | Prior period cost (USD dollars). |
change_percent | number (double) nullable | Percent change. Null when prior is 0 and current > 0 (new entry). |
share_percent | number (double) | Current period cost share (%). |
z_score | number (double) nullable | Z-score of change relative to population. Null if all changes identical. |
end_user_count | number (double) | Number of distinct end users. |
request_count | number (double) | Total request count. |
margin_outliers | object[] | End users whose margin z-score is below -1.5. Empty when no outliers are found, when fewer than 2 end users have margin data, or when all margins are identical (zero variance). |
end_user | string | End user external ID (the ID supplied on your usage events). |
margin | number (double) | Margin percentage. |
deviation_from_mean | number (double) | Deviation from population mean (percentage points). |
z_score | number (double) nullable | Z-score (how many std devs below mean). Null if zero variance. |
cost | number (double) | Total cost for this end user (USD dollars). |
model_mix | map of string to number (double) | Model mix: model slug to cost share percentage. |
correlations | object | Cross-metric Pearson correlations. |
cost_vs_request_volume | number (double) nullable | Pearson correlation between cost and request volume per end user. Null if insufficient data. |
margin_vs_model_mix | number (double) nullable | Pearson correlation between margin and model mix concentration (HHI). Null if insufficient data. |
unmapped_spend | object | Aggregated unmapped-spend breakdown. |
instrumentation_gap_cents | number (double) | Spend recorded without an end user ID, in integer USD cents. Close this gap by passing an end user ID in your usage events. |
instrumentation_gap_percent | number (double) | instrumentation_gap_cents as a percent of total spend. A real 0, not null, when there is no spend. |
connect_billing_gap_cents | number (double) | Spend for end users with no connected Stripe revenue data, in integer USD cents. Close this gap by connecting Stripe. |
connect_billing_gap_percent | number (double) | connect_billing_gap_cents as a percent of total spend. A real 0, not null, when there is no spend. |
Error codes
Errors return the standard error envelope with a code, message, and a correlationId you can quote to support.
| Status | When it happens |
|---|---|
400 | Invalid request parameters. Check that start and end are valid ISO 8601 dates and that the requested range does not exceed 365 days. |
401 | Missing or invalid API key. Send your key as Authorization: Bearer YOUR_API_KEY. |
403 | Forbidden. The API key is missing the costs:read or revenue:read scope; OR the current plan does not include the summary-ai capability. |
429 | Rate limit or plan quota exceeded. Slow down and retry after the current window resets. |
503 | Service unavailable. The summary could not be computed due to a temporary database issue; retry the request. |
Rate limits and retries
Rate limit or plan quota exceeded. Slow down and retry after the current window resets.