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

# Analyse the latest build of a job

> Starts an AI analysis of the latest build of the service. It runs in the background and reports its progress on the websocket route `/build/analysis`.
The result gives a confidence, the estimated time saved, what was reviewed, a summary, the improvements to make, a prompt for the customer's own AI agent, and a reworked Dockerfile when an improvement is a Dockerfile change.
Starting an analysis replaces the previous one. It never changes the build or the image.



## OpenAPI

````yaml /api-reference/openapi.yaml post /job/{jobId}/buildAnalysis
openapi: 3.0.0
info:
  version: 1.0.4
  title: Qovery API
  description: >
    - Qovery is the fastest way to deploy your full-stack apps on any Cloud
    provider.

    - ℹ️ The API is stable and still in development.
  contact:
    name: Qovery Product Team
    url: https://www.qovery.com
    email: support+api+documentation@qovery.com
  x-logo:
    url: https://console.qovery.com/assets/logos/logo-white.svg
    altText: Qovery
servers:
  - url: https://api.qovery.com
security:
  - bearerAuth: []
  - ApiKeyAuth: []
tags:
  - name: Account
  - name: Account Info
  - name: IPs
  - name: Alert Receivers
  - name: Alert Rules
  - name: Admin
  - name: ArgoCD
  - name: Agentic Workflows
  - name: Application
  - name: Application Actions
  - name: Application Build Analysis
  - name: Application Configuration
  - name: Application Database
  - name: Application Deployment Restriction
  - name: Application Deployment History
  - name: Application Environment Variable
  - name: Application Logs
  - name: Application Main Calls
  - name: Application Secret
  - name: Application Annotations Group
  - name: Applications
  - name: AutoscalingPolicy
  - name: Container
  - name: Container Actions
  - name: Container Configuration
  - name: Container Database
  - name: Container Deployment History
  - name: Container Environment Variable
  - name: Container Logs
  - name: Container Main Calls
  - name: Container Registry
  - name: Container Secret
  - name: Container Annotations Group
  - name: Containers
  - name: Deployment Stage Main Calls
  - name: Job
  - name: Job Actions
  - name: Job Build Analysis
  - name: Job Configuration
  - name: Job Database
  - name: Job Deployment Restriction
  - name: Job Deployment History
  - name: Job Environment Variable
  - name: Job Logs
  - name: Job Main Calls
  - name: Job Registry
  - name: Job Secret
  - name: Job Annotations Group
  - name: Jobs
  - name: KedaTriggerAuthentication
  - name: Helm
  - name: Helm Actions
  - name: Helm Configuration
  - name: Helm Database
  - name: Helm Deployment Restriction
  - name: Helm Deployment History
  - name: Helm Logs
  - name: Helm Main Calls
  - name: Helm Repository
  - name: Helms
  - name: Backups
  - name: Billing
  - name: Blueprint Catalog
  - name: Cloud Provider
  - name: Cloud Provider Credentials
  - name: Clusters
  - name: Cluster Deployment History
  - name: Cluster Operator
  - name: Platform Configuration
  - name: Custom Domain
  - name: Container Custom Domain
  - name: LLM Providers
  - name: MCP Servers
  - name: Database
  - name: Database Actions
  - name: Database Application
  - name: Database Container
  - name: Database Deployment History
  - name: Database Main Calls
  - name: Database Annotations Group
  - name: Databases
  - name: Environment
  - name: Environment Actions
  - name: Environment Deployment History
  - name: Environment Deployment Rule
  - name: Environment Logs
  - name: Environment Main Calls
  - name: Environment Secret
  - name: Environment Variable
  - name: Environments
  - name: Git
  - name: Github App
  - name: Git repositories
  - name: Members
  - name: Organization
  - name: Organization Account Git Repositories
  - name: Organization Cluster Lock
  - name: Organization Main Calls
  - name: Organization Custom Role
  - name: Organization Event
  - name: Organization Api Token
  - name: Organization Policy Api Token
  - name: Organization Webhook
  - name: Organization Annotations Group
  - name: Organization Labels Group
  - name: Organization Enterprise Connection
  - name: Project
  - name: Project Deployment Rule
  - name: Project Environment Variable
  - name: Project Main Calls
  - name: Project Secret
  - name: Projects
  - name: Referral & Rewards
  - name: Secret Manager Access
  - name: Terraforms
  - name: Terraform Main Calls
  - name: Terraform Resources
  - name: Terraform Deployment History
  - name: Terraform Deployment Restriction
  - name: Container Registries
  - name: Helm Repositories
  - name: User Sign Up
  - name: Variable Main Calls
  - name: Helm Custom Domain
  - name: Lifecycle Template Main Calls
  - name: Blueprint Main Calls
paths:
  /job/{jobId}/buildAnalysis:
    post:
      tags:
        - Job Build Analysis
      summary: Analyse the latest build of a job
      description: >-
        Starts an AI analysis of the latest build of the service. It runs in the
        background and reports its progress on the websocket route
        `/build/analysis`.

        The result gives a confidence, the estimated time saved, what was
        reviewed, a summary, the improvements to make, a prompt for the
        customer's own AI agent, and a reworked Dockerfile when an improvement
        is a Dockerfile change.

        Starting an analysis replaces the previous one. It never changes the
        build or the image.
      operationId: startJobBuildAnalysis
      parameters:
        - $ref: '#/components/parameters/jobId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BuildAnalysisStartRequest'
      responses:
        '202':
          description: Build analysis started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildAnalysisResponse'
        '400':
          $ref: '#/components/responses/400'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/BuildAnalysisForbidden'
        '404':
          $ref: '#/components/responses/404'
        '409':
          $ref: '#/components/responses/BuildAnalysisConflict'
        '422':
          $ref: '#/components/responses/BuildAnalysisDockerfileUnavailable'
        '503':
          $ref: '#/components/responses/BuildAnalysisNotConfigured'
components:
  parameters:
    jobId:
      name: jobId
      in: path
      description: Job ID
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    BuildAnalysisStartRequest:
      type: object
      required:
        - execution_id
      properties:
        execution_id:
          type: string
          description: >-
            Execution id of the build to analyse. It must be the latest build of
            the service, `latest_build_execution_id` in `BuildAnalysisState`.
          example: 6e5c1d3a-6b6f-4c35-9a2f-8f1d2c3b4a5e-42
    BuildAnalysisResponse:
      type: object
      required:
        - service_id
        - execution_id
        - status
        - stale
        - dockerfile_source
        - failure_code
        - failure_reason
        - result
        - created_at
        - updated_at
      properties:
        service_id:
          type: string
          format: uuid
        execution_id:
          type: string
          description: Execution id of the analysed build.
          example: 6e5c1d3a-6b6f-4c35-9a2f-8f1d2c3b4a5e-42
        status:
          $ref: '#/components/schemas/BuildAnalysisStatus'
        stale:
          type: boolean
          description: >-
            True when the latest build of the service is not the analysed one.
            The analysis stays readable, but only the latest build can be
            analysed.
        dockerfile_source:
          $ref: '#/components/schemas/BuildAnalysisDockerfileSource'
        failure_code:
          type: string
          allOf:
            - $ref: '#/components/schemas/BuildAnalysisFailureCode'
          nullable: true
          description: Why the analysis failed, when `status` is FAILED.
        failure_reason:
          type: string
          nullable: true
          description: Human-readable detail of the failure, when `status` is FAILED.
        result:
          type: object
          allOf:
            - $ref: '#/components/schemas/BuildAnalysisResult'
          nullable: true
          description: Set when `status` is DONE.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    BuildAnalysisStatus:
      type: string
      description: >-
        PENDING is queued, COLLECTING reads the build logs and the cache
        history, ANALYSING waits for the model, then DONE or FAILED. The
        Dockerfile is resolved before the start answers 202.
      enum:
        - PENDING
        - COLLECTING
        - ANALYSING
        - DONE
        - FAILED
    BuildAnalysisDockerfileSource:
      type: string
      description: >-
        Where the analysed Dockerfile came from. GIT is the repository at the
        build commit, INLINE the Dockerfile stored on the job.
      enum:
        - GIT
        - INLINE
    BuildAnalysisFailureCode:
      type: string
      description: >-
        MODEL_ERROR when the model call failed or returned an invalid result,
        TIMEOUT when the analysis took too long, INTERNAL_ERROR otherwise.
      enum:
        - MODEL_ERROR
        - TIMEOUT
        - INTERNAL_ERROR
    BuildAnalysisResult:
      type: object
      required:
        - confidence
        - assets_reviewed
        - summary
        - improvements
        - agent_prompt
        - estimated_time_saved
        - dockerfile
        - dockerfile_rationale
      properties:
        confidence:
          $ref: '#/components/schemas/BuildAnalysisConfidence'
        estimated_time_saved:
          type: object
          allOf:
            - $ref: '#/components/schemas/BuildAnalysisTimeSaved'
          nullable: true
          description: >-
            Build time saved on each build once every improvement is applied.
            Null when there is nothing to save or no timing to base it on.
            `confidence` applies to this range.
        assets_reviewed:
          type: array
          items:
            $ref: '#/components/schemas/BuildAnalysisAsset'
        summary:
          type: string
          description: What slows the build and why, with the evidence from the build.
        improvements:
          type: array
          description: >-
            Changes to make, one sentence each, ordered by impact on build time,
            highest first. Empty when the build is already efficient.
          items:
            type: string
          example:
            - >-
              Copy package.json and package-lock.json before the rest of the
              code, so the install stays cached until dependencies change
        dockerfile:
          type: string
          nullable: true
          description: >-
            Reworked Dockerfile to copy. Null when no improvement is a
            Dockerfile change, for example a variable value. Values hidden from
            the analysis appear as `<redacted>` and must be put back before use.
        dockerfile_rationale:
          type: string
          nullable: true
          description: Why the reworked Dockerfile is faster.
        agent_prompt:
          type: string
          description: >-
            Prompt the customer pastes into their own AI agent to apply the
            improvements in their repository.
    BuildAnalysisConfidence:
      type: string
      description: >-
        How sure the analysis is that applying the improvements saves
        `estimated_time_saved`. HIGH when the build logs, the cache history or
        the build metrics show both the cause and the time it costs, MEDIUM when
        one of the two is inferred, LOW when only the Dockerfile suggests it or
        there is no time estimate. With no improvement, how sure the analysis is
        that the build has nothing left to gain.
      enum:
        - HIGH
        - MEDIUM
        - LOW
    BuildAnalysisTimeSaved:
      type: object
      description: >-
        Seconds saved on each build, as a range from min_seconds to max_seconds.
        When nothing is saved, the field holding it is null instead.
      required:
        - min_seconds
        - max_seconds
      properties:
        min_seconds:
          type: integer
          minimum: 0
          example: 50
        max_seconds:
          type: integer
          minimum: 0
          example: 90
    BuildAnalysisAsset:
      type: string
      description: >-
        What the analysis read. DOCKERFILE and BUILD_SETTINGS (build
        configuration and build argument names) are always read, DOCKERIGNORE
        when Qovery could check the repository for it, BUILD_LOGS when the build
        or earlier builds sharing its cache have logs.
      enum:
        - DOCKERFILE
        - DOCKERIGNORE
        - BUILD_LOGS
        - BUILD_SETTINGS
  responses:
    '400':
      description: Bad request
    '401':
      description: Access token is missing or invalid
    '404':
      description: Resource not found
    BuildAnalysisForbidden:
      description: >-
        Access forbidden, or AI features are disabled for the organization
        (`ai_features_enabled`).
    BuildAnalysisConflict:
      description: >-
        The execution is not the latest build of the service, the service has no
        build, or an analysis is already in progress. Read the build analysis
        again to get the current `latest_build_execution_id` and the running
        analysis.
    BuildAnalysisDockerfileUnavailable:
      description: >-
        Qovery cannot read the Dockerfile of this build, for example a git fetch
        failure or a path that does not exist at the build commit.
    BuildAnalysisNotConfigured:
      description: >-
        Build analysis is not available on this Qovery instance because no AI
        model is configured. Checked before the organization's AI features.
        Retrying does not help until the instance is configured.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT tokens should be used with OIDC account (human to machine). JWT
        tokens used by the Qovery console to communicate with the API have a
        TTL. Curl Example ' curl https://console.qovery.com/organization -H
        "Authorization: Bearer $qovery_token" '
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Token API are generated by Qovery to manage machine to machine
        interaction and do not have a TTL. Curl Example ' curl
        https://console.qovery.com/organization -H "Authorization: Token
        $qovery_token" '

````

## Related topics

- [Analyse the latest build of an application](https://www.qovery.com/docs/api-reference/application-build-analysis/analyse-the-latest-build-of-an-application.md)
- [Get the build analysis of a job](https://www.qovery.com/docs/api-reference/job-build-analysis/get-the-build-analysis-of-a-job.md)
- [Get the build analysis of an application](https://www.qovery.com/docs/api-reference/application-build-analysis/get-the-build-analysis-of-an-application.md)
- [Stop job](https://www.qovery.com/docs/api-reference/job-actions/stop-job.md)
- [Redeploy job](https://www.qovery.com/docs/api-reference/job-actions/redeploy-job.md)


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