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

# Get file metrics

> Retrieve the latest values of all metrics for a file in a Project's default branch



## OpenAPI

````yaml https://api.qlty.sh/openapi.json get /gh/{ownerKeyOrId}/projects/{projectKeyOrId}/files
openapi: 3.1.0
info:
  title: Qlty API
  version: 1.0.0
  description: >-
    The Qlty API is organized around REST. It provides predictable,
    resource-oriented URLs, accepts JSON-encoded request bodies, and returns
    JSON-encoded responses.
servers:
  - url: https://api.qlty.sh
security:
  - Bearer: []
tags:
  - name: Service
    description: Service status and API discovery operations
  - name: User
    description: Operations for the authenticated user
  - name: Workspaces
    description: Operations for managing workspaces
  - name: Projects
    description: Operations for managing projects
  - name: Issues
    description: Operations for managing issues
  - name: Metrics
    description: Operations for retrieving metrics
  - name: Components
    description: Operations for retrieving components
  - name: Coverage
    description: Operations for retrieving code coverage data
paths:
  /gh/{ownerKeyOrId}/projects/{projectKeyOrId}/files:
    get:
      tags:
        - Metrics
      summary: Get file metrics
      description: >-
        Retrieve the latest values of all metrics for a file in a Project's
        default branch
      operationId: getFileMetrics
      parameters:
        - schema:
            type: string
            minLength: 3
            example: acme-corp
            description: Repository owner name (login) or workspace ID
          required: true
          description: Repository owner name (login) or workspace ID
          name: ownerKeyOrId
          in: path
        - schema:
            type: string
            minLength: 3
            example: my-repo
            description: Repository name or project ID
          required: true
          description: Repository name or project ID
          name: projectKeyOrId
          in: path
        - schema:
            type: string
            minLength: 1
            example: src/index.ts
            description: File path to retrieve metrics for
          required: true
          description: File path to retrieve metrics for
          name: path
          in: query
      responses:
        '200':
          description: Retrieve metrics for a file
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileMetricList'
              example:
                data:
                  - key: CMPLX
                    name: Cognitive Complexity
                    description: Total cognitive complexity across all functions
                    category: maintainability
                    value: 8
                    inverted: true
                  - key: LOC
                    name: Lines of Code
                    description: Total lines of code
                    category: size
                    value: 47
                    inverted: false
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate Limit Exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    FileMetricList:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/Metric'
      required:
        - data
    Error:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              status:
                type: string
                example: '400'
              title:
                type: string
                example: Bad Request
              detail:
                type: string
                example: The request was invalid.
            required:
              - status
              - title
              - detail
      required:
        - errors
    Metric:
      allOf:
        - $ref: '#/components/schemas/MetricDescriptor'
        - type: object
          properties:
            value:
              oneOf:
                - type: number
                - type: string
                  enum:
                    - XS
                    - S
                    - M
                    - L
                    - XL
                - type: string
                  enum:
                    - A
                    - B
                    - C
                    - D
                    - F
              example: 42
              description: The latest value of the metric
          required:
            - value
    MetricDescriptor:
      type: object
      properties:
        key:
          type: string
          example: CMPLX
        name:
          type: string
          example: Cognitive Complexity
        description:
          type: string
          example: Measures how hard the code is to understand
        category:
          type: string
          enum:
            - maintainability
            - reliability
            - security
            - size
            - coverage
            - quality
          example: maintainability
        inverted:
          type: boolean
          example: true
          description: When true, higher values are worse
        valueType:
          type: string
          enum:
            - number
            - percentage
            - grade
            - size
            - duration
            - count
          example: number
          description: How the metric's value should be interpreted
      required:
        - key
        - name
        - category
        - inverted
        - valueType
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer
      description: Generate an API token at https://qlty.sh/user/settings/tokens

````