> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Metrics: Timeseries Examples

> Timeseries query examples for Gateway agent metrics API

## Timeseries queries

Time-bucketed agent metrics over a window. Every timeseries query must include `interval` (or the deprecated `intervalInSeconds`). Each example below posts JSON to:

```
POST https://{your_control_plane_url}/api/svc/v1/llm-gateway/metrics/query
```

with `Authorization: Bearer <your_api_key>` and `Content-Type: application/json`. To keep the snippets short, only the JSON body is shown; the wrapper is identical to the [Overview Quick Start](/docs/ai-gateway/fetch-agent-metrics#quick-start).

<Note>
  Agent metrics include every Gateway request by default. Rows that didn't go through an agent will have `agentName`, `agentFramework`, and `agentServerType` set to `null` and show up as null buckets in `groupBy` output. `IS_NULL` is **not** supported on these three fields; to scope to specific known agents, use `agentName IN [...]` or one of the `STRING_*` operators.
</Note>

<AccordionGroup>
  <Accordion title="Hourly volume per agent">
    Per-agent invocation count over time:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 hour",
        "groupBy": ["agentName"]
    }
    ```
  </Accordion>

  <Accordion title="Hourly p99 latency per agent">
    Watch latency regressions per agent:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 hour",
        "aggregations": [
            {"type": "p99", "column": "latencyMs"}
        ],
        "groupBy": ["agentName"]
    }
    ```
  </Accordion>

  <Accordion title="Hourly failures over time">
    Track failures per agent bucket-by-bucket:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 hour",
        "aggregations": [
            {"type": "count", "column": "agentName"}
        ],
        "groupBy": ["agentName"],
        "filters": [
            {"fieldName": "isFailure", "operator": "EQUAL", "value": true}
        ]
    }
    ```
  </Accordion>

  <Accordion title="Hourly framework mix">
    Per-framework volume over time:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 hour",
        "groupBy": ["agentFramework"]
    }
    ```
  </Accordion>

  <Accordion title="5-minute latency in an incident window">
    Fine-grained breakdown to investigate a regression:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T14:00:00.000Z",
        "endTs": "2026-04-21T16:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "5 minute",
        "aggregations": [
            {"type": "p99", "column": "latencyMs"}
        ],
        "groupBy": ["agentName"]
    }
    ```
  </Accordion>

  <Accordion title="Daily invocations over a week">
    Daily agent traffic across a 7-day window:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-14T00:00:00.000Z",
        "endTs": "2026-04-21T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 day",
        "groupBy": ["agentName"]
    }
    ```
  </Accordion>

  <Accordion title="Hourly per-team activity">
    Per-team agent usage over time:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 hour",
        "groupBy": ["team"],
        "filters": [
            {"fieldName": "team", "operator": "ARRAY_HAS_ANY", "value": ["team-alpha", "team-beta"]}
        ]
    }
    ```
  </Accordion>

  <Accordion title="Hourly p99 latency for a known set of agents">
    Use `agentName IN [...]` to scope the timeseries to specific agents:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "agentMetrics",
        "type": "timeseries",
        "interval": "1 hour",
        "aggregations": [
            {"type": "p99", "column": "latencyMs"}
        ],
        "groupBy": ["agentName"],
        "filters": [
            {"fieldName": "agentName", "operator": "IN", "value": ["support-bot", "research-agent"]}
        ]
    }
    ```
  </Accordion>
</AccordionGroup>
