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

# Latest failure for an agent

> Returns diagnostics for the most recent failed run of the specified agent.
Useful when asking "Why did my agent fail?" without specifying a run ID.



## OpenAPI

````yaml GET /api/v1/analytics/agents/{agentId}/latest-failure
openapi: 3.0.1
info:
  title: Sequentum Cloud API
  description: API endpoints for Sequentum Cloud
  version: v1
servers: []
security:
  - ApiKey: []
    Bearer: []
paths:
  /api/v1/analytics/agents/{agentId}/latest-failure:
    get:
      tags:
        - ApiAnalytics
      summary: Get the most recent failed run for an agent
      description: >-
        Returns diagnostics for the most recent failed run of the specified
        agent.

        Useful when asking "Why did my agent fail?" without specifying a run ID.
      parameters:
        - name: agentId
          in: path
          description: The ID of the agent
          required: true
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: Returns the run diagnostics
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunDiagnosticsApiModel'
        '401':
          description: If the API key is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '404':
          description: If the agent is not found or has no failed runs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
components:
  schemas:
    RunDiagnosticsApiModel:
      type: object
      properties:
        runId:
          type: integer
          format: int64
        agentId:
          type: integer
          format: int32
        agentName:
          type: string
          nullable: true
        status:
          $ref: '#/components/schemas/RunStatus'
        errorMessage:
          type: string
          nullable: true
        startTime:
          type: string
          format: date-time
          nullable: true
        endTime:
          type: string
          format: date-time
          nullable: true
        runtimeSeconds:
          type: integer
          format: int32
          nullable: true
        stats:
          $ref: '#/components/schemas/RunStatsApiModel'
        possibleCauses:
          type: array
          items:
            type: string
          description: Possible failure reasons based on status and error message
          nullable: true
        suggestedActions:
          type: array
          items:
            type: string
          description: Suggested actions to resolve the issue
          nullable: true
      additionalProperties: false
      description: Response model for run diagnostics (why a run failed)
    ProblemDetails:
      type: object
      properties:
        type:
          type: string
          nullable: true
        title:
          type: string
          nullable: true
        status:
          type: integer
          format: int32
          nullable: true
        detail:
          type: string
          nullable: true
        instance:
          type: string
          nullable: true
      additionalProperties: {}
    RunStatus:
      enum:
        - 0
        - 1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        - 10
        - 11
        - 12
      type: integer
      description: >-
        `0` = `Invalid`; `1` = `Running`; `2` = `Exporting`; `3` = `Starting`;
        `4` = `Queuing`; `5` = `Stopping`; `6` = `Failure`; `7` = `Failed`; `8`
        = `Stopped`; `9` = `Completed`; `10` = `Success`; `11` = `Skipped`; `12`
        = `Waiting`
      format: int32
    RunStatsApiModel:
      type: object
      properties:
        dataCount:
          type: integer
          format: int32
        inputCount:
          type: integer
          format: int32
          nullable: true
        errorCount:
          type: integer
          format: int32
        pageCount:
          type: integer
          format: int32
        exportCount:
          type: integer
          format: int32
          nullable: true
        traffic:
          type: integer
          format: int64
          nullable: true
      additionalProperties: false
      description: Run statistics
  securitySchemes:
    ApiKey:
      type: apiKey
      description: >-
        API Key authorization header. Example: "Authorization: ApiKey
        {your-api-key}"
      name: Authorization
      in: header
    Bearer:
      type: http
      description: 'OAuth 2.0 Bearer token. Example: "Authorization: Bearer {access-token}"'
      scheme: bearer
      bearerFormat: JWT

````