Skip to main content
POST
Aggregate spans
Aggregates the spans in a time window into one row per bucket and group. Use it for latency breakdowns per turn or per span, error rates per function or per error type, and trends over hours, days, weeks or months. See the overview for the span, measure and error-type vocabulary.

Request

Headers

string
required
Account API key with read access to conversations.

Body

datetime
required
Inclusive window start, ISO 8601.
datetime
required
Exclusive window end. The window may span at most 30 days.
string[]
required
Aggregations to compute, one column each: p50, p95, p99, avg, min, max (over measure), count, error_count, error_rate (errors divided by count, null when count is 0), conversation_count.
string
default:"duration_ms"
Per-span value the timing aggregations run over: duration_ms, time_to_first_token_ms (set on polyai.llm_gateway.provider_call spans) or time_to_first_byte_ms (set on TTS spans). Filter on span_name for the last two: where no span carries the measure, percentiles return 0 and avg/min/max return null.
string[]
Dimensions to group by, one column each: span_name, service, layer, project_id, client_env, turn_index, function_name, flow_name, step_name, deployment_version, error_type.
string
Time bucket: hourly, daily, weekly or monthly. Adds a leading bucket column. Omit for one unbucketed result per group.
string
IANA timezone (for example Europe/London) applied to the buckets. Defaults to UTC.
string
Restrict to one agent. Omit to aggregate the whole account.
string
Exact span name, for example polyai.turn.
string
Ok, Error or Unset.
string
Restrict to the spans of one GenAI function.
string
Restrict to spans that failed for this reason, for example LLM_PROVIDER_UNAVAILABLE or function_error.
string
Restrict to one conversation.
string[]
Restrict to environments: test, sandbox, pre-release, live, scenarios. pre-release is the Staging environment.
object
{ "field": "<a group_by or aggs value>", "order": "asc" | "desc" }. Applied after the ascending bucket sort.
integer
default:"20"
Rows per page, 1–100.
integer
default:"0"
Rows to skip, 0–1000.

Response

string[]
Column names in row order: bucket (when interval is set), then each group_by dimension, then each aggregation.
array[]
One array per bucket and group, values in columns order. Timing values are milliseconds.
integer
integer
boolean
true when another page exists.

Examples

Latency and error rate per span

Time to first token per turn, hourly

Request

Why LLM calls failed

Request
Response

Errors

Last modified on November 10, 2026