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

# Repay debt and withdraw collateral

> Repay an Aave debt and withdraw collateral from a Credit Account.

Bundles repayment, collateral withdrawal, and an optional swap into a single atomic Safe transaction.

- If `token_out` is None or equals `withdraw_token`, the withdrawn collateral is kept as-is.
- If `token_out` differs from `withdraw_token`, a swap is performed after withdrawal via 1inch.

The Credit Account must already have a borrow position created via `/v2/credit/borrow`.
The repay_token must be available in the Credit Account (or pulled from EOA via Permit2).



## OpenAPI

````yaml /v2/combined_spec.json post /v2/credit/repay
openapi: 3.1.0
info:
  title: Compass API
  description: Compass Labs DeFi API
  version: 0.0.1
servers:
  - url: https://api.compasslabs.ai
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /v2/credit/repay:
    post:
      tags:
        - Credit
      summary: Repay debt and withdraw collateral
      description: >-
        Repay an Aave debt and withdraw collateral from a Credit Account.


        Bundles repayment, collateral withdrawal, and an optional swap into a
        single atomic Safe transaction.


        - If `token_out` is None or equals `withdraw_token`, the withdrawn
        collateral is kept as-is.

        - If `token_out` differs from `withdraw_token`, a swap is performed
        after withdrawal via 1inch.


        The Credit Account must already have a borrow position created via
        `/v2/credit/borrow`.

        The repay_token must be available in the Credit Account (or pulled from
        EOA via Permit2).
      operationId: v2_credit_repay
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreditRepayRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreditRepayResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from compass_api_sdk import CompassAPI, models


            with CompassAPI(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as compass_api:

                res = compass_api.credit.credit_repay(owner="0x831Ad0C52C77708DA5D49dc8278C966dfdD4ddA1", chain=models.Chain.BASE, repay_token="WETH", repay_amount=0.01, sub_account_id=0, interest_rate_mode=models.InterestRateMode.VARIABLE, withdraw_token="USDC", withdraw_amount=100, slippage=0.5, gas_sponsorship=False)

                # Handle response
                print(res)
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { CompassApiSDK } from "@compass-labs/api-sdk";

            const compassApiSDK = new CompassApiSDK({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await compassApiSDK.credit.creditRepay({
                owner: "0x831Ad0C52C77708DA5D49dc8278C966dfdD4ddA1",
                chain: "base",
                repayToken: "WETH",
                repayAmount: 0.01,
                interestRateMode: "variable",
                withdrawToken: "USDC",
                withdrawAmount: 100,
                slippage: 0.5,
                gasSponsorship: false,
              });

              console.log(result);
            }

            run();
components:
  schemas:
    CreditRepayRequest:
      properties:
        owner:
          type: string
          title: Owner
          description: The address that owns the Credit Account.
          default: '0x831Ad0C52C77708DA5D49dc8278C966dfdD4ddA1'
          examples:
            - '0x831Ad0C52C77708DA5D49dc8278C966dfdD4ddA1'
        chain:
          $ref: '#/components/schemas/Chain'
          description: Blockchain network.
          default: base
          examples:
            - base
        protocol:
          $ref: '#/components/schemas/CreditProtocol'
          description: Lending protocol to use. Defaults to Aave.
          default: AAVE
        borrow_vault:
          anyOf:
            - type: string
            - type: 'null'
          title: Borrow Vault
          description: >-
            Euler only: the EVK vault the debt is owed to (repay target).
            Required when protocol=EULER.
        market_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Market Id
          description: >-
            Morpho only: the bytes32 market id (from /v2/credit/morpho_markets).
            Required when protocol=MORPHO.
        collateral_vault:
          anyOf:
            - type: string
            - type: 'null'
          title: Collateral Vault
          description: >-
            Euler only: the EVK collateral vault to withdraw from. Required when
            protocol=EULER and withdrawing collateral.
        sub_account_id:
          type: integer
          maximum: 255
          minimum: 0
          title: Sub Account Id
          description: >-
            Euler only: EVC sub-account (0–255) holding the debt to repay. Each
            sub-account is an independent Euler position with its own
            collateral, borrow controller, and health. Defaults to 0. Ignored
            for Aave/Morpho.
          default: 0
        repay_token:
          type: string
          title: Token
          description: >-
            The borrowed asset to repay (e.g. WETH). Must match the debt
            position's token.
          examples:
            - WETH
            - '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
          default: WETH
        repay_amount:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Repay Amount
          description: Amount of repay_token to repay (in token units, not wei).
          examples:
            - 0.01
            - 50
          default: 0.01
        interest_rate_mode:
          $ref: '#/components/schemas/InterestRateMode'
          description: >-
            The interest rate mode of the debt position being repaid. Must match
            the mode used when borrowing.
          default: variable
          examples:
            - variable
        withdraw_token:
          anyOf:
            - type: string
              title: Token
              description: >-
                A token identifier - either a supported symbol (e.g., USDC,
                WETH) or a valid Ethereum address (0x...)
              examples:
                - USDC
                - WETH
                - '0xA0b86a33E6441ccF30EE5DdEF1E9b652C91ac1c8'
            - type: 'null'
          title: Withdraw Token
          description: >-
            Collateral token to withdraw from Aave after repaying debt. Omit
            together with withdraw_amount for repay-only mode.
          examples:
            - USDC
            - '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
          default: USDC
        withdraw_amount:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Withdraw Amount
          description: >-
            Amount of collateral to withdraw (in token units, not wei). Omit
            together with withdraw_token for repay-only mode.
          examples:
            - 100
            - 1.5
          default: 100
        token_out:
          anyOf:
            - type: string
              title: Token
              description: >-
                A token identifier - either a supported symbol (e.g., USDC,
                WETH) or a valid Ethereum address (0x...)
              examples:
                - USDC
                - WETH
                - '0xA0b86a33E6441ccF30EE5DdEF1E9b652C91ac1c8'
            - type: 'null'
          title: Token Out
          description: >-
            Desired output token. If different from withdraw_token, a swap is
            performed after withdrawal. If None, the withdrawn collateral is
            kept as-is.
          examples:
            - WETH
            - '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
        slippage:
          anyOf:
            - type: number
              maximum: 100
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Slippage
          description: >-
            Maximum slippage tolerance as a percentage (e.g., 0.5 = 0.5%). Only
            used when a swap is needed.
          default: '0.5'
          examples:
            - 0.5
        gas_sponsorship:
          type: boolean
          title: Gas Sponsorship
          description: >-
            If true, returns EIP-712 signature data instead of an unsigned
            transaction.
          default: false
          examples:
            - false
        permit2_signature:
          anyOf:
            - type: string
            - type: 'null'
          title: Permit2 Signature
          description: >-
            The EOA owner's signature of the Permit2 PermitTransferFrom typed
            data. When provided, the repay bundle will first pull repay_token
            from the owner's EOA into the Credit Account via Permit2. Obtain by
            calling /v2/credit/transfer and signing the returned EIP-712 data.
        permit2_nonce:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Permit2 Nonce
          description: >-
            The nonce used in the Permit2 signature (from the signed typed
            data).
        permit2_deadline:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Permit2 Deadline
          description: >-
            The deadline timestamp used in the Permit2 signature (from the
            signed typed data).
      type: object
      required:
        - owner
        - chain
        - repay_token
        - repay_amount
      title: CreditRepayRequest
      default:
        owner: '0x831Ad0C52C77708DA5D49dc8278C966dfdD4ddA1'
        chain: base
        repay_token: WETH
        repay_amount: 0.01
        interest_rate_mode: variable
        withdraw_token: USDC
        withdraw_amount: 100
        slippage: 0.5
        gas_sponsorship: false
    CreditRepayResponse:
      properties:
        transaction:
          anyOf:
            - $ref: '#/components/schemas/UnsignedTransaction'
            - type: 'null'
          description: >-
            Unsigned transaction to execute the repay bundle. Present when
            gas_sponsorship is false.
          example:
            chainId: '0x2105'
            data: 0x6a761202000000000000000000000000...
            from: '0xc98949522db2eE403d6c75E91DDEe875a824bB10'
            gas: '0x9eb10'
            maxFeePerGas: '0x3b9aca00'
            maxPriorityFeePerGas: '0x5f5e100'
            nonce: '0x2d'
            to: '0xaB5801a7D398351b8bE11C439e05C5B3259aeC9B'
            value: '0x0'
        eip_712:
          anyOf:
            - $ref: '#/components/schemas/BatchedSafeOperationsResponse-Output'
            - type: 'null'
          description: >-
            EIP-712 typed data for gas-sponsored execution. Present when
            gas_sponsorship is true.
        estimated_token_out_amount:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Estimated Token Out Amount
          description: >-
            Estimated amount of token_out received from swap. Only present when
            token_out differs from withdraw_token.
          example: '100.5000000000'
      type: object
      title: CreditRepayResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    Chain:
      type: string
      enum:
        - base
        - ethereum
        - arbitrum
        - hyperevm
        - tempo
        - bsc
      title: Chain
      description: The chain to use.
    CreditProtocol:
      type: string
      enum:
        - AAVE
        - EULER
        - MORPHO
      title: CreditProtocol
      description: >-
        Which lending protocol a credit action targets.


        ``AAVE`` is the default so existing callers (which never send a
        ``protocol``

        field) keep hitting the unchanged Aave code path. ``EULER`` opts in to
        the

        Euler V2 path, where the market is identified by EVK vault address(es).

        ``MORPHO`` identifies Morpho Blue lending markets (bytes32 market id)
        and is

        currently read-only: positions and market discovery only — transaction

        builders land with the looping work (COM-7106/7107/7108), so transact

        endpoints reject it with a 422.
    InterestRateMode:
      type: string
      enum:
        - stable
        - variable
      title: InterestRateMode
      description: |-
        On AAVE there are 2 different interest modes.

        A stable (but typically higher rate), or a variable rate.
    UnsignedTransaction:
      properties:
        chainId:
          type: string
          title: Chainid
          description: The chain id of the transaction
        data:
          type: string
          title: Data
          description: The data of the transaction
        from:
          type: string
          title: From
          description: The sender of the transaction
        gas:
          anyOf:
            - type: string
            - type: 'null'
          title: Gas
          description: The gas of the transaction
        to:
          type: string
          title: To
          description: The recipient of the transaction
        value:
          type: string
          title: Value
          description: The value of the transaction
        nonce:
          type: string
          title: Nonce
          description: The nonce of the address
        maxFeePerGas:
          type: string
          title: Maxfeepergas
          description: The max fee per gas of the transaction
        maxPriorityFeePerGas:
          type: string
          title: Maxpriorityfeepergas
          description: The max priority fee per gas of the transaction
      type: object
      required:
        - chainId
        - data
        - from
        - gas
        - to
        - value
        - nonce
        - maxFeePerGas
        - maxPriorityFeePerGas
      title: UnsignedTransaction
      example:
        chainId: '0x2105'
        data: >-
          0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d
        from: '0x4A83b4413CF41C3244027e1590E35a0F48403F0c'
        gas: '0x7a120'
        maxFeePerGas: '0x59682f00'
        maxPriorityFeePerGas: '0x3b9aca00'
        nonce: '0x5'
        to: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67'
        value: '0x0'
    BatchedSafeOperationsResponse-Output:
      properties:
        domain:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Domain
          description: EIP-712 domain separator
        types:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Types
          description: EIP-712 type definitions
        primaryType:
          type: string
          const: SafeTx
          title: Primarytype
          description: Primary type for the structured data
        message:
          $ref: '#/components/schemas/SafeTxMessage'
          description: Safe transaction message data
      type: object
      required:
        - domain
        - types
        - primaryType
        - message
      title: BatchedSafeOperationsResponse
      description: Response containing EIP-712 typed data for Safe transaction signing.
      example:
        domain:
          chainId: 8453
          verifyingContract: '0x6B90E8B4E3E971E74C1A47a3a20976377E2dB4b1'
        message:
          baseGas: '0'
          data: >-
            0x8d80ff0a0000000000000000000000000000000000000000000000000000000000000020
          gasPrice: '0'
          gasToken: '0x0000000000000000000000000000000000000000'
          nonce: '7'
          operation: 1
          refundReceiver: '0x0000000000000000000000000000000000000000'
          safeTxGas: '0'
          to: '0x93C23AAE4793C14D6DF35D2A2A2234204e1559dA'
          value: '0'
        primaryType: SafeTx
        types:
          EIP712Domain:
            - name: chainId
              type: uint256
            - name: verifyingContract
              type: address
          SafeTx:
            - name: to
              type: address
            - name: value
              type: uint256
            - name: data
              type: bytes
            - name: operation
              type: uint8
            - name: safeTxGas
              type: uint256
            - name: baseGas
              type: uint256
            - name: gasPrice
              type: uint256
            - name: gasToken
              type: address
            - name: refundReceiver
              type: address
            - name: nonce
              type: uint256
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Domain:
      properties:
        chainId:
          type: integer
          title: Chainid
          description: Chain ID
        verifyingContract:
          type: string
          title: Verifyingcontract
          description: Address of the Product Account
      type: object
      required:
        - chainId
        - verifyingContract
      title: EIP712Domain
      description: The EIP-712 domain separator.
    compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Types:
      properties:
        EIP712Domain:
          items:
            $ref: '#/components/schemas/EIP712DomainField'
          type: array
          title: Eip712Domain
          description: EIP712Domain type definition
        SafeTx:
          items:
            $ref: '#/components/schemas/SafeTxField'
          type: array
          title: Safetx
          description: SafeTx type definition
      type: object
      required:
        - EIP712Domain
        - SafeTx
      title: EIP712Types
      description: The type definitions for EIP-712 structured data.
    SafeTxMessage:
      properties:
        to:
          type: string
          title: To
          description: Destination address
        value:
          type: string
          title: Value
          description: Value in wei as a string
        data:
          type: string
          title: Data
          description: Transaction data as hex string
        operation:
          $ref: '#/components/schemas/OperationType'
          description: Operation type (0=Call, 1=DelegateCall)
        safeTxGas:
          type: string
          title: Safetxgas
          description: Gas for the transaction
        baseGas:
          type: string
          title: Basegas
          description: Base gas costs
        gasPrice:
          type: string
          title: Gasprice
          description: Gas price
        gasToken:
          type: string
          title: Gastoken
          description: Token address for gas payment
        refundReceiver:
          type: string
          title: Refundreceiver
          description: Address to receive gas refund
        nonce:
          type: string
          title: Nonce
          description: Transaction nonce
      type: object
      required:
        - to
        - value
        - data
        - operation
        - safeTxGas
        - baseGas
        - gasPrice
        - gasToken
        - refundReceiver
        - nonce
      title: SafeTxMessage
      description: The message data for the transaction.
    EIP712DomainField:
      properties:
        name:
          type: string
          title: Name
        type:
          type: string
          title: Type
      type: object
      required:
        - name
        - type
      title: EIP712DomainField
      description: A field in the EIP712Domain type definition.
    SafeTxField:
      properties:
        name:
          type: string
          title: Name
        type:
          type: string
          title: Type
      type: object
      required:
        - name
        - type
      title: SafeTxField
      description: A field in the SafeTx type definition.
    OperationType:
      type: integer
      enum:
        - 0
        - 1
      title: OperationType
      description: Safe operation types.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your Compass API Key. Get your key
        [here](https://www.compasslabs.ai/dashboard).

````