Skip to main content
POST
/
v2
/
credit
/
borrow
Python (SDK)
from compass_api_sdk import CompassAPI, models


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

    res = compass_api.credit.credit_borrow(owner="0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425", chain=models.Chain.BASE, token_in="USDC", amount_in=100, collateral_token="USDC", borrow_token="WETH", borrow_amount=0.01, interest_rate_mode=models.InterestRateMode.VARIABLE, slippage=0.5, gas_sponsorship=False)

    # Handle response
    print(res)
{
  "transaction": {
    "chainId": "<string>",
    "data": "<string>",
    "from": "<string>",
    "gas": "<string>",
    "to": "<string>",
    "value": "<string>",
    "nonce": "<string>",
    "maxFeePerGas": "<string>",
    "maxPriorityFeePerGas": "<string>"
  },
  "eip_712": {
    "domain": {
      "chainId": 123,
      "verifyingContract": "<string>"
    },
    "types": {
      "EIP712Domain": [
        {
          "name": "<string>",
          "type": "<string>"
        }
      ],
      "SafeTx": [
        {
          "name": "<string>",
          "type": "<string>"
        }
      ]
    },
    "primaryType": "<string>",
    "message": {
      "to": "<string>",
      "value": "<string>",
      "data": "<string>",
      "operation": 0,
      "safeTxGas": "<string>",
      "baseGas": "<string>",
      "gasPrice": "<string>",
      "gasToken": "<string>",
      "refundReceiver": "<string>",
      "nonce": "<string>"
    }
  },
  "estimated_collateral_amount": "<string>"
}

Authorizations

x-api-key
string
header
required

Your Compass API Key. Get your key here.

Body

application/json
owner
string
default:0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425
required

The address that owns the Credit Account.

chain
enum<string>
default:base
required

Blockchain network.

Available options:
base,
ethereum,
arbitrum
token_in
string
default:USDC
required

Token currently held in the Credit Account to use as input. If the same as collateral_token, no swap is performed.

Examples:

"USDC"

"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

amount_in
default:100
required

Amount of token_in to use (in token units, not wei).

Required range: x > 0
Example:

100

collateral_token
string
default:USDC
required

Aave reserve token to supply as collateral.

Examples:

"WETH"

"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"

borrow_token
string
default:WETH
required

Asset to borrow from Aave.

Examples:

"DAI"

"0x6b175474e89094c44da98b954eedeac495271d0f"

borrow_amount
default:0.01
required

Amount to borrow (in token units, not wei).

Required range: x > 0
Example:

50

interest_rate_mode
enum<string>
default:variable

The interest rate mode for the borrow position.

Available options:
stable,
variable
Example:

"variable"

slippage
default:0.5

Maximum slippage tolerance as a percentage (e.g., 0.5 = 0.5%). Only used when a swap is needed.

Required range: 0 <= x <= 100
Example:

0.5

gas_sponsorship
boolean
default:false

If true, returns EIP-712 signature data instead of an unsigned transaction.

permit2_signature
string | null

The EOA owner's signature of the Permit2 PermitTransferFrom typed data. When provided, the borrow bundle will first pull token_in 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
integer | null

The nonce used in the Permit2 signature (from the signed typed data).

Required range: x >= 0
permit2_deadline
integer | null

The deadline timestamp used in the Permit2 signature (from the signed typed data).

Required range: x >= 0

Response

Successful Response

transaction
UnsignedTransaction · object

Unsigned transaction to execute the borrow bundle. Present when gas_sponsorship is false.

eip_712
BatchedSafeOperationsResponse · object

EIP-712 typed data for gas-sponsored execution. Present when gas_sponsorship is true.

estimated_collateral_amount
string | null

Estimated amount of collateral token received from swap. Only present when token_in differs from collateral_token.