> ## 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.

# Routing Metrics: Distribution Examples

> Distribution query examples for Gateway routing metrics API

## Distribution queries

Aggregated snapshots of routing rule applications over a time window. Every 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-routing-metrics#quick-start).

<AccordionGroup>
  <Accordion title="Routing volume by config type and status">
    Rely on the implicit `total` count; group by `configType` and `status` to see the breakdown of rule applications:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "groupBy": ["configType", "status"]
    }
    ```
  </Accordion>

  <Accordion title="Attempts distribution per loadbalance rule">
    Min, average, and p99 of attempts per loadbalance rule, useful when tuning rule fan-out:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "aggregations": [
            {"type": "min", "column": "loadbalanceTargetAttemptCount"},
            {"type": "avg", "column": "loadbalanceTargetAttemptCount"},
            {"type": "p99", "column": "loadbalanceTargetAttemptCount"}
        ],
        "groupBy": ["loadbalanceRuleId"]
    }
    ```
  </Accordion>

  <Accordion title="Where a specific requested model ends up">
    Fix `requestedModel` and see which `targetModel`s the request lands on, with outcome:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "aggregations": [
            {"type": "sum", "column": "loadbalanceTargetAttemptCount"}
        ],
        "groupBy": ["targetModel", "status"],
        "filters": [
            {"fieldName": "requestedModel", "operator": "IN", "value": ["gpt-4"]}
        ]
    }
    ```
  </Accordion>

  <Accordion title="Activity for a specific ratelimit rule">
    Filter to a single `ratelimitRuleId` and group by `status` to see allowed vs blocked counts for that rule:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "groupBy": ["status"],
        "filters": [
            {"fieldName": "ratelimitRuleId", "operator": "IN", "value": ["<rule-id>"]}
        ]
    }
    ```
  </Accordion>

  <Accordion title="Failed routings only">
    Restrict to failed outcomes, broken down by rule:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "aggregations": [],
        "groupBy": ["loadbalanceRuleId", "configType"],
        "filters": [
            {"fieldName": "loadbalanceRuleId", "operator": "NOT_IN", "value": [""]}
        ]
    }
    ```
  </Accordion>

  <Accordion title="Distinct target models per rule">
    How many distinct target models a rule is fanning into:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "aggregations": [
            {"type": "countDistinct", "column": "loadbalanceTargetAttemptCount"}
        ],
        "groupBy": ["loadbalanceRuleId"]
    }
    ```
  </Accordion>

  <Accordion title="Group by team">
    Routing volume per team:

    ```python theme={"dark"}
    json={
        "startTs": "2026-04-21T00:00:00.000Z",
        "endTs": "2026-04-22T00:00:00.000Z",
        "datasource": "configMetrics",
        "type": "distribution",
        "aggregations": [
            {"type": "sum", "column": "loadbalanceTargetAttemptCount"}
        ],
        "groupBy": ["team", "configType"],
        "filters": [
            {"fieldName": "team", "operator": "ARRAY_HAS_ANY", "value": ["team-alpha"]}
        ]
    }
    ```
  </Accordion>
</AccordionGroup>
