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

# Metrics

> Retrieve analytics and performance metrics for your API traffic

## Get Summary Metrics

<api-endpoint method="GET" url="https://api.apitraffic.io/v1/accounts/{accountSid}/metrics/summary" />

Retrieve summary metrics for an account, with optional filtering capabilities.

### Path Parameters

<ParamField path="accountSid" type="string" required>
  Account identifier (format: `acc_` followed by 27 alphanumeric characters)
</ParamField>

### Query Parameters

<ParamField query="bucketSid" type="string">
  Filter metrics by specific bucket
</ParamField>

<ParamField query="startDate" type="string">
  Start date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="endDate" type="string">
  End date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="environmentSid" type="string">
  Filter by environment identifier
</ParamField>

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Response

<ResponseField name="totalRequests" type="number">
  Total number of requests in the time period
</ResponseField>

<ResponseField name="totalErrors" type="number">
  Total number of error responses (4xx/5xx status codes)
</ResponseField>

<ResponseField name="averageResponseTime" type="number">
  Average response time in milliseconds
</ResponseField>

<ResponseField name="totalDataTransferred" type="number">
  Total bytes transferred (request + response)
</ResponseField>

<ResponseField name="requestsByMethod" type="object">
  Breakdown of requests by HTTP method
</ResponseField>

<ResponseField name="requestsByStatus" type="object">
  Breakdown of requests by HTTP status code ranges
</ResponseField>

<ResponseField name="topEndpoints" type="array">
  Most frequently accessed endpoints
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/summary?startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z" \
    -H "Authorization: Bearer your-jwt-token"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/summary?startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z', {
    headers: {
      'Authorization': 'Bearer your-jwt-token'
    }
  });

  const metrics = await response.json();
  console.log(metrics);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/summary',
      params={
          'startDate': '2023-12-01T00:00:00Z',
          'endDate': '2023-12-02T00:00:00Z'
      },
      headers={'Authorization': 'Bearer your-jwt-token'}
  )

  metrics = response.json()
  print(metrics)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "totalRequests": 15420,
    "totalErrors": 234,
    "averageResponseTime": 145.6,
    "totalDataTransferred": 2048576,
    "requestsByMethod": {
      "GET": 12340,
      "POST": 2100,
      "PUT": 680,
      "DELETE": 300
    },
    "requestsByStatus": {
      "2xx": 14186,
      "3xx": 1000,
      "4xx": 200,
      "5xx": 34
    },
    "topEndpoints": [
      {
        "path": "/api/users",
        "count": 3420,
        "averageResponseTime": 120.5
      },
      {
        "path": "/api/orders",
        "count": 2100,
        "averageResponseTime": 180.2
      }
    ]
  }
  ```
</ResponseExample>

***

## Get Throughput Metrics

<api-endpoint method="GET" url="https://api.apitraffic.io/v1/accounts/{accountSid}/metrics/throughput" />

Retrieve request throughput metrics over time.

### Path Parameters

<ParamField path="accountSid" type="string" required>
  Account identifier
</ParamField>

### Query Parameters

<ParamField query="bucketSid" type="string">
  Filter metrics by specific bucket
</ParamField>

<ParamField query="startDate" type="string">
  Start date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="endDate" type="string">
  End date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="interval" type="string">
  Time interval for grouping: `hour`, `day`, `week`, `month`
</ParamField>

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Response

<ResponseField name="interval" type="string">
  Time interval used for grouping
</ResponseField>

<ResponseField name="data" type="array">
  <Expandable title="Throughput Data Points">
    <ResponseField name="timestamp" type="string">
      ISO 8601 timestamp for the data point
    </ResponseField>

    <ResponseField name="requestCount" type="number">
      Number of requests in this time interval
    </ResponseField>

    <ResponseField name="errorCount" type="number">
      Number of errors in this time interval
    </ResponseField>

    <ResponseField name="averageResponseTime" type="number">
      Average response time for this interval
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/throughput?interval=hour&startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z" \
    -H "Authorization: Bearer your-jwt-token"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/throughput?interval=hour&startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z', {
    headers: {
      'Authorization': 'Bearer your-jwt-token'
    }
  });

  const throughput = await response.json();
  console.log(throughput);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "interval": "hour",
    "data": [
      {
        "timestamp": "2023-12-01T00:00:00Z",
        "requestCount": 450,
        "errorCount": 12,
        "averageResponseTime": 142.3
      },
      {
        "timestamp": "2023-12-01T01:00:00Z",
        "requestCount": 523,
        "errorCount": 8,
        "averageResponseTime": 138.7
      }
    ]
  }
  ```
</ResponseExample>

***

## Get Performance Metrics

<api-endpoint method="GET" url="https://api.apitraffic.io/v1/accounts/{accountSid}/metrics/performance" />

Retrieve detailed performance metrics including response times, error rates, and endpoint analytics.

### Path Parameters

<ParamField path="accountSid" type="string" required>
  Account identifier
</ParamField>

### Query Parameters

<ParamField query="bucketSid" type="string">
  Filter metrics by specific bucket
</ParamField>

<ParamField query="startDate" type="string">
  Start date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="endDate" type="string">
  End date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="groupBy" type="string">
  Group metrics by: `endpoint`, `method`, `status`, `environment`
</ParamField>

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Response

<ResponseField name="groupBy" type="string">
  The grouping method used
</ResponseField>

<ResponseField name="metrics" type="array">
  <Expandable title="Performance Metrics">
    <ResponseField name="group" type="string">
      The group identifier (endpoint, method, etc.)
    </ResponseField>

    <ResponseField name="requestCount" type="number">
      Total requests for this group
    </ResponseField>

    <ResponseField name="errorRate" type="number">
      Error rate as a percentage (0-100)
    </ResponseField>

    <ResponseField name="averageResponseTime" type="number">
      Average response time in milliseconds
    </ResponseField>

    <ResponseField name="p50ResponseTime" type="number">
      50th percentile response time
    </ResponseField>

    <ResponseField name="p95ResponseTime" type="number">
      95th percentile response time
    </ResponseField>

    <ResponseField name="p99ResponseTime" type="number">
      99th percentile response time
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/performance?groupBy=endpoint&startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z" \
    -H "Authorization: Bearer your-jwt-token"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/performance?groupBy=endpoint&startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z', {
    headers: {
      'Authorization': 'Bearer your-jwt-token'
    }
  });

  const performance = await response.json();
  console.log(performance);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "groupBy": "endpoint",
    "metrics": [
      {
        "group": "/api/users",
        "requestCount": 3420,
        "errorRate": 1.2,
        "averageResponseTime": 120.5,
        "p50ResponseTime": 95.0,
        "p95ResponseTime": 280.0,
        "p99ResponseTime": 450.0
      },
      {
        "group": "/api/orders",
        "requestCount": 2100,
        "errorRate": 2.8,
        "averageResponseTime": 180.2,
        "p50ResponseTime": 145.0,
        "p95ResponseTime": 420.0,
        "p99ResponseTime": 650.0
      }
    ]
  }
  ```
</ResponseExample>

***

## Get Error Metrics

<api-endpoint method="GET" url="https://api.apitraffic.io/v1/accounts/{accountSid}/metrics/errors" />

Retrieve detailed error analysis and patterns.

### Path Parameters

<ParamField path="accountSid" type="string" required>
  Account identifier
</ParamField>

### Query Parameters

<ParamField query="bucketSid" type="string">
  Filter metrics by specific bucket
</ParamField>

<ParamField query="startDate" type="string">
  Start date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="endDate" type="string">
  End date for metrics (ISO 8601 format)
</ParamField>

<ParamField query="statusCode" type="number">
  Filter by specific HTTP status code
</ParamField>

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Response

<ResponseField name="totalErrors" type="number">
  Total number of errors in the time period
</ResponseField>

<ResponseField name="errorRate" type="number">
  Overall error rate as a percentage
</ResponseField>

<ResponseField name="errorsByStatus" type="object">
  Breakdown of errors by HTTP status code
</ResponseField>

<ResponseField name="errorsByEndpoint" type="array">
  <Expandable title="Endpoint Error Analysis">
    <ResponseField name="endpoint" type="string">
      API endpoint path
    </ResponseField>

    <ResponseField name="errorCount" type="number">
      Number of errors for this endpoint
    </ResponseField>

    <ResponseField name="errorRate" type="number">
      Error rate percentage for this endpoint
    </ResponseField>

    <ResponseField name="mostCommonErrors" type="array">
      Most frequent error status codes
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/errors?startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z" \
    -H "Authorization: Bearer your-jwt-token"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/metrics/errors?startDate=2023-12-01T00:00:00Z&endDate=2023-12-02T00:00:00Z', {
    headers: {
      'Authorization': 'Bearer your-jwt-token'
    }
  });

  const errors = await response.json();
  console.log(errors);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "totalErrors": 234,
    "errorRate": 1.52,
    "errorsByStatus": {
      "400": 120,
      "401": 45,
      "404": 35,
      "500": 25,
      "503": 9
    },
    "errorsByEndpoint": [
      {
        "endpoint": "/api/auth/login",
        "errorCount": 45,
        "errorRate": 3.2,
        "mostCommonErrors": [401, 400]
      },
      {
        "endpoint": "/api/users/profile",
        "errorCount": 35,
        "errorRate": 2.1,
        "mostCommonErrors": [404, 403]
      }
    ]
  }
  ```
</ResponseExample>
