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

# Get API Key Statistics

> Get usage statistics for an API key

Retrieves usage statistics and analytics for a specific API key.

## Path Parameters

<ParamField path="key_id" type="string" required>
  The unique identifier of the API key
</ParamField>

## Query Parameters

<ParamField query="period" type="string" default="30d">
  The time period for statistics. Options: `24h`, `7d`, `30d`, `90d`
</ParamField>

<ParamField query="granularity" type="string" default="day">
  The granularity of the data. Options: `hour`, `day`, `week`
</ParamField>

## Response

<ResponseField name="key_id" type="string">
  The unique identifier of the API key
</ResponseField>

<ResponseField name="period" type="string">
  The time period of the statistics
</ResponseField>

<ResponseField name="total_requests" type="number">
  Total number of requests made with this key
</ResponseField>

<ResponseField name="successful_requests" type="number">
  Number of successful requests (2xx status codes)
</ResponseField>

<ResponseField name="failed_requests" type="number">
  Number of failed requests (4xx and 5xx status codes)
</ResponseField>

<ResponseField name="usage_by_endpoint" type="object">
  Breakdown of usage by API endpoint
</ResponseField>

<ResponseField name="daily_usage" type="array">
  Array of daily usage statistics
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET \
    "https://api.buena.ai/api/v2/keys/key_123/stats?period=7d&granularity=day" \
    -H "x-api-key: YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.buena.ai/api/v2/keys/key_123/stats?period=7d&granularity=day', {
    headers: {
      'x-api-key': 'YOUR_API_KEY'
    }
  });
  const stats = await response.json();
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "key_id": "key_123",
    "period": "7d",
    "total_requests": 1250,
    "successful_requests": 1180,
    "failed_requests": 70,
    "usage_by_endpoint": {
      "/api/v2/leads": 450,
      "/api/v2/enrich": 380,
      "/api/v2/linkedin": 420
    },
    "daily_usage": [
      {
        "date": "2024-01-01",
        "requests": 180,
        "successful": 175,
        "failed": 5
      }
    ]
  }
  ```
</ResponseExample>
