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

# Get AI gateway metrics

> Returns time-series per model for one AI gateway connection that CostGraph scrapes, sourced from the metrics store: end-to-end request latency quantiles (signal end_to_end, kind quantile, in the unit the gateway reports), requests per second (end_to_end, request_rate), tokens per second by usage kind such as input and output (tokens_per_second, token_rate), spend per hour in USD (spend_per_hour, spend_rate) and tokens per request (tokens_per_request, ratio). Spend per hour prices each model's token rate at the rate CostGraph charges for this connection's usage on the latest usage day, so it agrees with the bill; models with no rate are listed in unpriced_models and get no spend series. last_traffic_at is the last point at which the gateway reported any tokens or requests in the window, so a gateway that went quiet or stopped being scraped can be told apart from one that is serving. Signals the gateway does not publish are named in missing_signals rather than returned as zero.



## OpenAPI

````yaml /api-reference/costgraph/openapi.json get /api/v1/tenant/ai/gateways/{id}/metrics
openapi: 3.0.0
info:
  description: Read and manage your CostGraph organization, spend, alerts, and settings.
  title: CostGraph API
  contact: {}
  version: '1.0'
servers:
  - url: https://api.costgraph.ai
security: []
tags:
  - name: ai
    x-group: AI
  - name: ai-serving
    x-group: AI serving
  - name: anomalies
    x-group: Anomalies
  - name: auth
    x-group: Auth
  - name: billing
    x-group: Billing
  - name: billing-export
    x-group: Billing export
  - name: budgets
    x-group: Budgets
  - name: ci
    x-group: CI
  - name: compute-recommendations
    x-group: Compute recommendations
  - name: config
    x-group: Config
  - name: context-graph
    x-group: Context graph
  - name: cost
    x-group: Cost
  - name: gpus
    x-group: GPUs
  - name: graphai
    x-group: Graph AI
  - name: integrations
    x-group: Integrations
  - name: invitations
    x-group: Invitations
  - name: kubernetes-clusters
    x-group: Kubernetes clusters
  - name: marketplace
    x-group: Marketplace
  - name: network
    x-group: Network
  - name: network-requests
    x-group: Network requests
  - name: notifications
    x-group: Notifications
  - name: oauth
    x-group: OAuth
  - name: oauth-clients
    x-group: OAuth clients
  - name: opencost
    x-group: OpenCost
  - name: operator
    x-group: Operator
  - name: organization
    x-group: Audit log
  - name: organizations
    x-group: Organizations
  - name: placement-alternatives
    x-group: Placement alternatives
  - name: reports
    x-group: Reports
  - name: sandboxes
    x-group: Sandboxes
  - name: settings
    x-group: Settings
  - name: sso
    x-group: Single sign-on
  - name: tenants
    x-group: Tenants
  - name: ticketing
    x-group: Ticketing
  - name: user
    x-group: Users
  - name: virtual-machines
    x-group: Virtual machines
  - name: virtual-tags
    x-group: Virtual tags
  - name: workflows
    x-group: Workflows
paths:
  /api/v1/tenant/ai/gateways/{id}/metrics:
    get:
      tags:
        - ai-serving
      summary: Get AI gateway metrics
      description: >-
        Returns time-series per model for one AI gateway connection that
        CostGraph scrapes, sourced from the metrics store: end-to-end request
        latency quantiles (signal end_to_end, kind quantile, in the unit the
        gateway reports), requests per second (end_to_end, request_rate), tokens
        per second by usage kind such as input and output (tokens_per_second,
        token_rate), spend per hour in USD (spend_per_hour, spend_rate) and
        tokens per request (tokens_per_request, ratio). Spend per hour prices
        each model's token rate at the rate CostGraph charges for this
        connection's usage on the latest usage day, so it agrees with the bill;
        models with no rate are listed in unpriced_models and get no spend
        series. last_traffic_at is the last point at which the gateway reported
        any tokens or requests in the window, so a gateway that went quiet or
        stopped being scraped can be told apart from one that is serving.
        Signals the gateway does not publish are named in missing_signals rather
        than returned as zero.
      parameters:
        - description: Tenant ID
          name: X-CostGraph-Tenant-ID
          in: header
          required: true
          schema:
            type: string
        - description: AI gateway connection id from the id field of the connection list
          name: id
          in: path
          required: true
          schema:
            type: string
        - description: Time window (e.g. 1h, 6h, 24h, 7d). Default 1h
          name: range
          in: query
          schema:
            type: string
        - description: Resolution step (e.g. 30s, 1m, 5m)
          name: step
          in: query
          schema:
            type: string
        - description: >-
            Latency quantiles between 0 and 1 (comma-separated). Default
            0.5,0.95,0.99
          name: quantiles
          in: query
          schema:
            type: string
        - description: Restrict to one model, as the gateway reports it
          name: model
          in: query
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/responses.SuccessResponse'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/aigateway.GatewayMetrics'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    responses.SuccessResponse:
      type: object
      required:
        - message
        - status
      properties:
        data: {}
        message:
          type: string
          example: some message
        status:
          type: string
          example: success
    aigateway.GatewayMetrics:
      type: object
      properties:
        end:
          type: string
        last_traffic_at:
          type: string
        missing_signals:
          type: array
          items:
            type: string
        rate_window_seconds:
          type: integer
        series:
          type: array
          items:
            $ref: '#/components/schemas/aigateway.ServingLatencySeries'
        start:
          type: string
        step_seconds:
          type: integer
        unpriced_models:
          type: array
          items:
            type: string
    responses.ErrorResponse:
      type: object
      required:
        - message
        - status
      properties:
        message:
          type: string
          example: some message
        status:
          type: string
          example: error
    aigateway.ServingLatencySeries:
      type: object
      properties:
        kind:
          type: string
        model:
          type: string
        points:
          type: array
          items:
            $ref: '#/components/schemas/metrics.MetricPoint'
        quantile:
          type: number
        signal:
          type: string
        unit:
          type: string
        usage_kind:
          type: string
    metrics.MetricPoint:
      type: object
      required:
        - t
        - v
      properties:
        t:
          type: integer
        v:
          type: number
  securitySchemes:
    BearerAuth:
      description: Enter "Bearer {token}"
      type: apiKey
      name: Authorization
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.