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

# Withdraw collateral

> Withdraws collateral from an existing loan. Full collateral removal may include internal weight-matrix and loan-lock handling before the transaction is returned.



## OpenAPI

````yaml post /markets/creditbook/collateral/withdraw
openapi: 3.1.0
info:
  title: Loopscale API
  version: 0.1.0
servers:
  - url: https://tars.loopscale.com/v1
    description: Loopscale Production Server
security: []
paths:
  /markets/creditbook/collateral/withdraw:
    post:
      tags:
        - creditbook
      summary: Withdraw collateral
      description: >-
        Withdraws collateral from an existing loan. Full collateral removal may
        include internal weight-matrix and loan-lock handling before the
        transaction is returned.
      operationId: query_withdraw_collateral
      parameters:
        - name: Idempotent-Key
          in: header
          description: >-
            Optional idempotency key; a retried write with the same key replays
            the original response
          required: false
          schema:
            type:
              - string
              - 'null'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TxnWithdrawCollateralParams'
        required: true
      responses:
        '200':
          description: Serialized transaction for withdrawing collateral.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VersionedTransactionReturn'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Idempotency-Key reused with a different request body
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    TxnWithdrawCollateralParams:
      type: object
      required:
        - loan
        - collateralMint
        - amount
        - collateralIndex
        - expectedLoanValues
      properties:
        amount:
          type: integer
          format: int64
          minimum: 0
        assetIndexGuidance:
          type: array
          items:
            type: integer
            format: int32
            minimum: 0
          description: >-
            Per-collateral oracle asset-index guidance (one byte per collateral
            slot).
        collateralIndex:
          type: integer
          format: int32
          minimum: 0
        collateralMint:
          type: string
        expectedLoanValues:
          $ref: '#/components/schemas/ExpectedLoanValuesSchema'
        loan:
          type: string
        lockLoan:
          type: boolean
        skipClose:
          type: boolean
        stakeInstructions:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/StakeLpQueryParams'
    VersionedTransactionReturn:
      type: object
      description: versioned txn return
      required:
        - message
        - signatures
      properties:
        message:
          type: string
          description: serialized message
        signatures:
          type: array
          items:
            $ref: '#/components/schemas/VersionedTransactionSignature'
          description: serialized signatures
    ErrorResponse:
      type: object
      description: |-
        Canonical error envelope for every endpoint. The `x-request-id` response
        header carries the correlation id for the failing request.
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetails'
          description: error detail
    ExpectedLoanValuesSchema:
      type: object
      description: >-
        Expected loan economics the borrower signs off on, checked on-chain
        against the

        freshly-priced values to bound slippage.
      required:
        - expectedApy
        - expectedLqt
      properties:
        expectedApy:
          type: integer
          format: int64
          description: Expected loan APY, in basis points of a hundredth (cbps).
          minimum: 0
        expectedLqt:
          type: array
          items:
            type: integer
            format: int32
            minimum: 0
          description: >-
            Expected per-ledger liquidation threshold, one entry per ledger
            slot.
    StakeLpQueryParams:
      type: object
      required:
        - vault
        - amount
      properties:
        amount:
          type: integer
          format: int64
          minimum: 0
        stakeAccount:
          type:
            - string
            - 'null'
        vault:
          type: string
    VersionedTransactionSignature:
      type: object
      description: versioned txn return
      required:
        - publicKey
        - signature
      properties:
        publicKey:
          type: string
          description: serialized message
        signature:
          type: string
          description: serialized signatures
    ErrorDetails:
      type: object
      description: Inner detail of the [`ErrorResponse`] envelope.
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
          description: HTTP status code, mirrored in the response status line
          example: 400
          minimum: 0
        message:
          type: string
          description: human-readable, client-safe message (sensitive data redacted)
          example: Request could not be processed.

````