Skip to content

Wasted spend and failure insights

Last updated: 2026-11-26T03:21:52-03:00 (UTC-3)

Usage → Insights answers two questions about a time range: what did we pay for nothing, and what keeps failing. Both are queries over what the gateway already records (the valuation ledger and the stored spans), never a model’s guess, so the numbers add up exactly.

Flag What it turns on
failure_insights Usage → Insights, GET /insights/wasted-spend, GET /insights/failures and the triage status of failure groups. Off by default. A tenant read: with plan entitlements a team’s plan must include it. Needs usage_valuation and span_store

Reading needs analytics:read (wasted spend) and logs:read (failures), within your teams; changing a group’s status needs insights:manage (team administrators of their teams, administrators everywhere).

GET /api/v1/admin/insights/wasted-spend?from=&to=&team= (default the last 7 days, at most 31; team narrows it to one team you read) adds up three kinds, which never count one amount twice:

Kind What it is
retried_sends Every earlier send of a retried or fallen-back request: the request’s non-final charge lines, by provider, model, outcome, reason and status
failed_requests The final send of a request that ended in an error status, an answer an output guardrail blocked after a billed generation included, by provider, model, problem code (or guardrail_blocked:<guardrail>) and status
failed_evaluations The final send of a request that answered but failed an evaluation, by evaluation

Amounts are exact decimals of what the ledger knows. A send whose cost is not known (a provider that answered 502 may or may not have generated) is counted in unknown and never as zero; when any is unknown the total’s state is partial and the console shows “at least”. Each group carries up to five evidence traces that open in the trace view. The wasted spend reads the ledger in the database (it has no analytics-store copy); with the analytics store as span engine, the failing evaluation results it keeps are read there (at most 5,000 requests per read, truncated past it).

GET /api/v1/admin/insights/failures?from=&to=&q=&status= groups the range’s failures by team and kind, most frequent first:

Kind Grouped by
provider_send A failed provider send: provider, alias, provider model, outcome (provider_error, transport_failure) and HTTP status
tool_call A failed tool call: server and tool
gateway_error A request that failed with no failed send under it (a guardrail that could not check, a quota, a timeout): the problem code and status

The query parameters are from and to (RFC 3339; the last 7 days by default, at most 31), q (a spans-scope query), status (one of the four triage states, to list only those groups) and scope (only spans is accepted).

Each group has its count, distinct traces, first and last time seen, up to five evidence traces and a fingerprint. q narrows the spans with the query language (spans scope), so model:support-chat or provider:openai work. gateway_version is the build of the gateway that answered. The failures read the span engine the trace explorer reads.

A group’s status is open until someone with insights:manage sets it:

PUT /api/v1/admin/insights/failures/{fingerprint}
{"team_id": "support", "status": "acknowledged", "note": "provider incident", "expected_version": 0}

Send it with PUT /api/v1/admin/insights/failures/{fingerprint}, the group’s fingerprint in the path. Statuses are open, acknowledged, resolved and ignored; the note is at most 500 characters; expected_version is the group’s status_version (0 when none was recorded), and a stale one answers 409 version_conflict. Every change is audited (insight.status.<status>) and logged (insight_status_changed). A resolved group that fails again after it was resolved reads open again.

Each group in the console has Copy fix prompt: a plain-text prompt for a coding agent built only from the group’s recorded facts (kind, provider, model, outcome, problem code, tool, counts, first and last seen, gateway version, evidence trace IDs), inside an explicit data block that the prompt tells the agent to treat as data, not instructions. It never contains request or answer content.

The Traces toolbar has a Failure insights link that opens Usage → Insights on the same time range.

Migration 291 adds the triage table. Nothing changes with the flag off.

Usage valuation · Trace explorer · Alert rules · Topics (clusters of traces into named topics with a model, when you want failures grouped by meaning rather than by provider and code)

m7gtw[email protected]