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

# Clean up unused images

> Removes unused image versions.

Removes unused sandbox image versions across the selected team. Versions
referenced by active deployments remain available. Cleanup can delete unused
versions saved for future deployments.

To remove only one version or repository, use
[targeted deletion](/sandboxes/manage-images#delete-an-image-or-a-version).


## OpenAPI

````yaml post /v1/sandboxes/cleanup_images
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/sandboxes/cleanup_images:
    post:
      tags:
        - Images
      summary: Clean up unused images
      description: >-
        Remove unused sandbox image versions. Versions referenced by active
        deployments are preserved.
      operationId: CleanupImages
      parameters:
        - $ref: '#/components/parameters/TeamId'
        - $ref: '#/components/parameters/TeamIdHeader'
      responses:
        '200':
          description: Successful operation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CleanupSandboxImagesResponseV1'
              examples:
                complete:
                  $ref: '#/components/examples/CleanupImages'
        '400':
          $ref: '#/components/responses/SandboxError400'
        '401':
          $ref: '#/components/responses/SandboxError401'
        '403':
          $ref: '#/components/responses/SandboxError403'
        '429':
          $ref: '#/components/responses/SandboxError429'
        '500':
          $ref: '#/components/responses/SandboxError500'
components:
  parameters:
    TeamId:
      name: team_id
      in: query
      required: false
      description: >-
        Optional team ID. Must match X-Team-Id when both are supplied. If
        neither selector is supplied, defaults to the caller's only accessible
        team. Callers with multiple accessible teams must select a team.
        Requests without access to any team are forbidden.
      schema:
        minLength: 1
        type: string
    TeamIdHeader:
      name: X-Team-Id
      in: header
      required: false
      description: >-
        Optional team ID. Must match the team_id query parameter when both are
        supplied. If neither selector is supplied, defaults to the caller's only
        accessible team. Callers with multiple accessible teams must select a
        team. Requests without access to any team are forbidden.
      schema:
        minLength: 1
        type: string
  schemas:
    CleanupSandboxImagesResponseV1:
      type: object
      description: Result of cleaning up unused sandbox images.
      properties:
        deleted:
          type: integer
          description: Number of image versions removed.
          minimum: 0
          example: 3
        message:
          type: string
          description: Human-readable cleanup result.
          example: >-
            Removed 3 unused image versions. Image versions used by active
            sandboxes were retained.
      required:
        - deleted
        - message
      example:
        deleted: 3
        message: >-
          Removed 3 unused image versions. Image versions used by active
          sandboxes were retained.
  examples:
    CleanupImages:
      summary: Unused image versions removed
      value:
        deleted: 3
        message: >-
          Removed 3 unused image versions. Image versions used by active
          sandboxes were retained.
  responses:
    SandboxError400:
      description: >-
        Invalid request. Returns a JSON error with code, message, and optional
        details.
      content:
        application/json:
          example:
            code: INVALID_REQUEST
            message: One or more request parameters are invalid.
            details:
              request_id: a3b7c4d2-91e6-4f08-9b5a-2c6d7e8f1043
    SandboxError401:
      description: >-
        Missing or invalid authentication. Returns a JSON error with code,
        message, and optional details.
      content:
        application/json:
          example:
            code: UNAUTHORIZED
            message: Provide a valid authentication token in the Authorization header.
            details:
              header: Authorization
    SandboxError403:
      description: >-
        Insufficient permissions. Returns a JSON error with code, message, and
        optional details.
      content:
        application/json:
          example:
            code: FORBIDDEN
            message: >-
              This authentication token does not grant permission to perform
              this operation.
            details:
              request_id: a3b7c4d2-91e6-4f08-9b5a-2c6d7e8f1043
    SandboxError429:
      description: >-
        Request limit exceeded. Returns a JSON error with code, message, and
        optional details.
      content:
        application/json:
          example:
            code: RATE_LIMITED
            message: Too many requests. Try again in 30 seconds.
            details:
              retry_after_seconds: 30
    SandboxError500:
      description: >-
        Internal server error. Returns a JSON error with code, message, and
        optional details.
      content:
        application/json:
          example:
            code: INTERNAL_ERROR
            message: The request could not be completed. Try again later.
            details:
              request_id: a3b7c4d2-91e6-4f08-9b5a-2c6d7e8f1043
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````