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

# Get API key analytics

> Get analytics data for API key usage



## OpenAPI

````yaml get /analytics/api_keys
openapi: 3.1.0
info:
  title: Prem API
  description: Full description of private and dev-availble API endpoints
  version: 1.0.0
  termsOfService: https://prem.io/terms
  contact:
    name: API Support
    url: https://help.prem.io
    email: support@premai.io
servers:
  - url: https://gateway.prem.io
    description: Production API server
security: []
paths:
  /analytics/api_keys:
    get:
      tags:
        - API Keys
        - dev-api
      summary: Get API key analytics
      description: Get analytics data for API key usage
      operationId: getApiKeyAnalytics
      responses:
        '200':
          $ref: '#/components/responses/apiKeyAnalyticsResponse'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
      security:
        - BearerAuth: []
          ApiKeyAuth: []
components:
  responses:
    '401':
      description: Access token is missing or invalid
      content:
        application/json:
          schema:
            allOf:
              - type: object
                properties:
                  status:
                    type: integer
                    enum:
                      - 400
                      - 401
                      - 403
                      - 404
                    description: Status code of the response
                  data:
                    type:
                      - object
                      - 'null'
                    description: Response data containing the requested object
                  error:
                    type:
                      - string
                      - 'null'
                    examples:
                      - Some error message
                    description: Error message of the response, human readable
                  message:
                    type: 'null'
                  env:
                    type: string
                    enum:
                      - development
                      - production
                    description: API environment
                  log:
                    type:
                      - string
                      - object
                      - 'null'
                    examples:
                      - request_id: req_1234567890
                      - Some pertinent log message
                    description: >-
                      Useful informaiton, not always present, to debug the
                      response
                  validator:
                    type:
                      - object
                      - array
                      - 'null'
                    examples:
                      - email: Invalid email address
                        password: Password is required
                    description: >-
                      Validator response object, each key is the field name and
                      value is the error message
                  support_id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    examples:
                      - support_uuidv7-something-else
                    description: >-
                      Support ID linked to the response, used to identify it
                      when talking with our team
                required:
                  - status
                  - error
                  - message
                  - env
                  - log
                  - support_id
                additionalProperties: false
              - properties:
                  status:
                    type: integer
                    enum:
                      - 401
    '403':
      description: You do not have the required permissions to access this resource
      content:
        application/json:
          schema:
            allOf:
              - type: object
                properties:
                  status:
                    type: integer
                    enum:
                      - 400
                      - 401
                      - 403
                      - 404
                    description: Status code of the response
                  data:
                    type:
                      - object
                      - 'null'
                    description: Response data containing the requested object
                  error:
                    type:
                      - string
                      - 'null'
                    examples:
                      - Some error message
                    description: Error message of the response, human readable
                  message:
                    type: 'null'
                  env:
                    type: string
                    enum:
                      - development
                      - production
                    description: API environment
                  log:
                    type:
                      - string
                      - object
                      - 'null'
                    examples:
                      - request_id: req_1234567890
                      - Some pertinent log message
                    description: >-
                      Useful informaiton, not always present, to debug the
                      response
                  validator:
                    type:
                      - object
                      - array
                      - 'null'
                    examples:
                      - email: Invalid email address
                        password: Password is required
                    description: >-
                      Validator response object, each key is the field name and
                      value is the error message
                  support_id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    examples:
                      - support_uuidv7-something-else
                    description: >-
                      Support ID linked to the response, used to identify it
                      when talking with our team
                required:
                  - status
                  - error
                  - message
                  - env
                  - log
                  - support_id
                additionalProperties: false
              - properties:
                  status:
                    type: integer
                    enum:
                      - 403
    apiKeyAnalyticsResponse:
      description: Successful API key analytics response
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Response200'
              - $ref: '#/components/schemas/apiKeyAnalyticsResponse'
  schemas:
    Response200:
      type: object
      properties:
        status:
          type: integer
          enum:
            - 200
            - 201
            - 202
          description: Status code of the response
        data:
          type:
            - object
            - array
            - 'null'
          description: Response data containing the requested object
        error:
          type:
            - string
            - 'null'
          examples:
            - Invalid email address
          description: Error message of the response, human readable
        message:
          type:
            - string
            - 'null'
          examples:
            - Resource created successfully
          description: Message of the response, human readable
        env:
          type: string
          enum:
            - development
            - production
          description: API environment
        log:
          type:
            - string
            - object
            - 'null'
          examples:
            - request_id: req_1234567890
            - Some pertinent log message
          description: Useful informaiton, not always present, to debug the response
        validator:
          type:
            - object
            - array
            - 'null'
          examples:
            - email: Invalid email address
              password: Password is required
          description: >-
            Validator response object, each key is the field name and value is
            the error message
        support_id:
          type:
            - string
            - 'null'
          format: uuid
          examples:
            - support_uuidv7-something-else
          description: >-
            Support ID linked to the response, used to identify it when talking
            with our team
      required:
        - status
        - data
        - message
        - env
      examples:
        - status: 200
          data:
            id: '123'
          error: null
          log: null
          validator: null
          support_id: null
          message: Resource created successfully
          env: development
    apiKeyAnalyticsResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            core_metrics:
              type: object
              properties:
                total_requests:
                  type:
                    - integer
                    - 'null'
                  description: Total number of API requests
                requests_per_second:
                  type:
                    - number
                    - 'null'
                  description: Average requests per second
                total_success:
                  type:
                    - integer
                    - 'null'
                  description: Number of successful API requests
                total_errors:
                  type:
                    - integer
                    - 'null'
                  description: Number of failed API requests
                success_rate_pct:
                  type:
                    - number
                    - 'null'
                  description: Percentage of successful API requests
                avg_latency_ms:
                  type:
                    - number
                    - 'null'
                  description: Average latency in milliseconds
                pct_under_100ms:
                  type:
                    - number
                    - 'null'
                  description: Percentage of requests under 100ms
                pct_under_500ms:
                  type:
                    - number
                    - 'null'
                  description: Percentage of requests under 500ms
                pct_under_1s:
                  type:
                    - number
                    - 'null'
                  description: Percentage of requests under 1 second
                unique_endpoints:
                  type:
                    - integer
                    - 'null'
                  description: Number of unique endpoints called
                distinct_api_keys:
                  type:
                    - integer
                    - 'null'
                  description: Number of distinct API keys used
              additionalProperties: false
            prev_core_metrics:
              type: object
              properties:
                total_requests:
                  type:
                    - integer
                    - 'null'
                  description: Total number of API requests
                requests_per_second:
                  type:
                    - number
                    - 'null'
                  description: Average requests per second
                total_success:
                  type:
                    - integer
                    - 'null'
                  description: Number of successful API requests
                total_errors:
                  type:
                    - integer
                    - 'null'
                  description: Number of failed API requests
                success_rate_pct:
                  type:
                    - number
                    - 'null'
                  description: Percentage of successful API requests
                avg_latency_ms:
                  type:
                    - number
                    - 'null'
                  description: Average latency in milliseconds
                pct_under_100ms:
                  type:
                    - number
                    - 'null'
                  description: Percentage of requests under 100ms
                pct_under_500ms:
                  type:
                    - number
                    - 'null'
                  description: Percentage of requests under 500ms
                pct_under_1s:
                  type:
                    - number
                    - 'null'
                  description: Percentage of requests under 1 second
                unique_endpoints:
                  type:
                    - integer
                    - 'null'
                  description: Number of unique endpoints called
                distinct_api_keys:
                  type:
                    - integer
                    - 'null'
                  description: Number of distinct API keys used
              additionalProperties: false
            most_used_api_keys:
              type:
                - array
                - 'null'
              items:
                type: object
                properties:
                  auth:
                    type:
                      - string
                      - 'null'
                    description: First 20 characters of the API key
                  usage_count:
                    type: integer
                    description: Number of times this API key was used
            ip_metrics:
              type:
                - array
                - object
              description: Metrics by IP address
              items:
                type: object
                properties:
                  ip:
                    type:
                      - string
                      - 'null'
                    description: IP address
                  total_requests:
                    type: integer
                    description: Total number of requests from this IP
                  total_errors:
                    type: integer
                    description: Number of errors from this IP
                  error_rate:
                    type: number
                    description: Error rate percentage for this IP
                additionalProperties: false
            hourly_metrics:
              type:
                - array
                - object
              description: Hourly metrics for the last 24 hours
              items:
                type: object
                properties:
                  hour:
                    type: string
                    description: Hour in format YYYY-MM-DD HH:00:00
                  total_requests:
                    type: integer
                    description: Total number of requests in this hour
                  error_count:
                    type: integer
                    description: Number of errors in this hour
                  error_rate_pct:
                    type: number
                    description: Error rate percentage for this hour
                  avg_latency_ms:
                    type: number
                    description: Average latency in milliseconds for this hour
                additionalProperties: false
            api_key_metrics_30d:
              type:
                - array
                - 'null'
              description: API key metrics for the last 30 days
              items:
                type: object
                properties:
                  api_key_id:
                    type:
                      - string
                      - 'null'
                    description: API key ID
                  total_requests:
                    type: integer
                    description: Total number of requests made with this API key
                  last_used_at:
                    type:
                      - string
                      - 'null'
                    format: mysql-date-time
                    description: Timestamp of the last request made with this API key
                additionalProperties: false
            latency_breakdown:
              description: API keys latency breakdown metrics
              type:
                - object
                - 'null'
              properties:
                total_requests:
                  type: integer
                  description: Total number of requests
                less_than_100ms:
                  type: integer
                  description: Number of requests with latency under 100ms
                less_than_500ms:
                  type: integer
                  description: Number of requests with latency under 500ms
                less_than_1s:
                  type: integer
                  description: Number of requests with latency under 1 second
                more_than_1s:
                  type: integer
                  description: Number of requests with latency over 1 second
            latency:
              description: API Keys latency metrics
              type:
                - object
                - 'null'
              properties:
                min:
                  type: number
                  format: float
                  description: Minimum latency in milliseconds for API Request deliveries
                max:
                  type: number
                  format: float
                  description: Maximum latency in milliseconds for API Request deliveries
                avg:
                  type: number
                  format: float
                  description: Average latency in milliseconds for API Request deliveries
                p50:
                  type: number
                  format: float
                  description: >-
                    50th percentile latency in milliseconds for API Request
                    deliveries
                p90:
                  type: number
                  format: float
                  description: >-
                    90th percentile latency in milliseconds for API Request
                    deliveries
                p95:
                  type: number
                  format: float
                  description: >-
                    95th percentile latency in milliseconds for webhook
                    deliveries
                p99:
                  type: number
                  format: float
                  description: >-
                    99th percentile latency in milliseconds for webhook
                    deliveries
              additionalProperties: false
          required:
            - core_metrics
            - prev_core_metrics
            - most_used_api_keys
            - ip_metrics
            - hourly_metrics
            - api_key_metrics_30d
            - latency_breakdown
            - latency
          additionalProperties: false
      required:
        - data
      examples:
        - data:
            core_metrics:
              total_requests: 4
              requests_per_second: 0
              total_success: 3
              total_errors: 1
              success_rate_pct: 75
              avg_latency_ms: 67.5
              pct_under_100ms: 100
              pct_under_500ms: 100
              pct_under_1s: 100
              unique_endpoints: 1
              distinct_api_keys: 2
            prev_core_metrics:
              total_requests: 10
              requests_per_second: 2
              total_success: 8
              total_errors: 2
              success_rate_pct: 80
              avg_latency_ms: 120
              pct_under_100ms: 70
              pct_under_500ms: 90
              pct_under_1s: 95
              unique_endpoints: 3
              distinct_api_keys: 4
            most_used_api_keys:
              - auth: Test auth
                usage_count: 3
            ip_metrics:
              - ip: 343.221.232.123
                total_requests: 3
                total_errors: 1
                error_rate: 33.33
              - ip: 234.122.99.012
                total_requests: 1
                total_errors: 0
                error_rate: 0
            hourly_metrics:
              - hour: '2025-07-30 15:00:00'
                total_requests: 3
                error_count: 1
                error_rate_pct: 33.33
                avg_latency_ms: 71.33
              - hour: '2025-07-31 15:00:00'
                total_requests: 1
                error_count: 0
                error_rate_pct: 0
                avg_latency_ms: 56
            api_key_metrics_30d:
              - api_key_id: null
                total_requests: 4
            latency_breakdown:
              total_requests: 500
              less_than_100ms: 233
              less_than_500ms: 100
              less_than_1s: 50
              more_than_1s: 2
            latency:
              min: 0
              max: 0
              avg: 0
              p50: 0
              p90: 0
              p95: 0
              p99: 0
          message: null
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Send your access token as header Authorization: Bearer {accessToken}'
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Your API key that starts with sk_live or sk_test. You can create yours
        at go.prem.io/api-keys.

````