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, borrow_token="WETH", borrow_amount=0.01, sub_account_id=0, token_in="USDC", amount_in=100, collateral_token="USDC", interest_rate_mode=models.InterestRateMode.VARIABLE, slippage=0.5, gas_sponsorship=False, fee=None)

    # Handle response
    print(res)
import { CompassApiSDK } from "@compass-labs/api-sdk";

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

async function run() {
  const result = await compassApiSDK.credit.creditBorrow({
    owner: "0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425",
    chain: "base",
    tokenIn: "USDC",
    amountIn: 100,
    collateralToken: "USDC",
    borrowToken: "WETH",
    borrowAmount: 0.01,
    interestRateMode: "variable",
    slippage: 0.5,
    gasSponsorship: false,
  });

  console.log(result);
}

run();
curl --request POST \
  --url https://api.compasslabs.ai/v2/credit/borrow \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "owner": "0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425",
  "chain": "base",
  "token_in": "USDC",
  "amount_in": 100,
  "collateral_token": "USDC",
  "borrow_token": "WETH",
  "borrow_amount": 0.01,
  "interest_rate_mode": "variable",
  "slippage": 0.5,
  "gas_sponsorship": false
}
'
const options = {
  method: 'POST',
  headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    owner: '0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425',
    chain: 'base',
    token_in: 'USDC',
    amount_in: 100,
    collateral_token: 'USDC',
    borrow_token: 'WETH',
    borrow_amount: 0.01,
    interest_rate_mode: 'variable',
    slippage: 0.5,
    gas_sponsorship: false
  })
};

fetch('https://api.compasslabs.ai/v2/credit/borrow', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.compasslabs.ai/v2/credit/borrow",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'owner' => '0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425',
    'chain' => 'base',
    'token_in' => 'USDC',
    'amount_in' => 100,
    'collateral_token' => 'USDC',
    'borrow_token' => 'WETH',
    'borrow_amount' => 0.01,
    'interest_rate_mode' => 'variable',
    'slippage' => 0.5,
    'gas_sponsorship' => false
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "x-api-key: <api-key>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.compasslabs.ai/v2/credit/borrow"

	payload := strings.NewReader("{\n  \"owner\": \"0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425\",\n  \"chain\": \"base\",\n  \"token_in\": \"USDC\",\n  \"amount_in\": 100,\n  \"collateral_token\": \"USDC\",\n  \"borrow_token\": \"WETH\",\n  \"borrow_amount\": 0.01,\n  \"interest_rate_mode\": \"variable\",\n  \"slippage\": 0.5,\n  \"gas_sponsorship\": false\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<api-key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.compasslabs.ai/v2/credit/borrow")
  .header("x-api-key", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"owner\": \"0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425\",\n  \"chain\": \"base\",\n  \"token_in\": \"USDC\",\n  \"amount_in\": 100,\n  \"collateral_token\": \"USDC\",\n  \"borrow_token\": \"WETH\",\n  \"borrow_amount\": 0.01,\n  \"interest_rate_mode\": \"variable\",\n  \"slippage\": 0.5,\n  \"gas_sponsorship\": false\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.compasslabs.ai/v2/credit/borrow")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"owner\": \"0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425\",\n  \"chain\": \"base\",\n  \"token_in\": \"USDC\",\n  \"amount_in\": 100,\n  \"collateral_token\": \"USDC\",\n  \"borrow_token\": \"WETH\",\n  \"borrow_amount\": 0.01,\n  \"interest_rate_mode\": \"variable\",\n  \"slippage\": 0.5,\n  \"gas_sponsorship\": false\n}"

response = http.request(request)
puts response.read_body
{
  "transaction": {
    "chainId": "0x2105",
    "data": "0x6a761202000000000000000000000000...",
    "from": "0xc98949522db2eE403d6c75E91DDEe875a824bB10",
    "gas": "0xb71b0",
    "maxFeePerGas": "0x3b9aca00",
    "maxPriorityFeePerGas": "0x5f5e100",
    "nonce": "0x2b",
    "to": "0xaB5801a7D398351b8bE11C439e05C5B3259aeC9B",
    "value": "0x0"
  },
  "eip_712": {
    "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"
        }
      ]
    }
  },
  "estimated_collateral_amount": "99.8500000000",
  "fee_amount": "0.1500000000"
}
{
  "detail": [
    {
      "loc": [
        "<string>"
      ],
      "msg": "<string>",
      "type": "<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.

Example:

"0xfeEb60eBf707DAA8248277058eb8D28EaeCF5425"

chain
enum<string>
default:base
required

Blockchain network.

Available options:
base,
ethereum,
arbitrum,
hyperevm,
tempo,
bsc
Example:

"base"

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

protocol
enum<string>
default:AAVE

Lending protocol to use. Defaults to Aave.

Available options:
AAVE,
EULER,
MORPHO
collateral_vault
string | null

Euler only: the EVK collateral vault to supply into. Required when protocol=EULER and supplying collateral.

borrow_vault
string | null

Euler only: the EVK vault to borrow from. Required when protocol=EULER.

market_id
string | null

Morpho only: the bytes32 market id (from /v2/credit/morpho_markets). Required when protocol=MORPHO.

sub_account_id
integer
default:0

Euler only: EVC sub-account (0–255) to isolate this position. Each sub-account is an independent Euler position with its own collateral, borrow controller, and health, letting one Credit Account hold multiple isolated Euler positions. Defaults to 0. Ignored for Aave/Morpho.

Required range: 0 <= x <= 255
token_in
string | null
default:USDC

A token identifier - either a supported symbol (e.g., USDC, WETH) or a valid Ethereum address (0x...)

Example:

"USDC"

amount_in
default:100

Amount of token_in to use (in token units, not wei). Omit together with token_in and collateral_token for borrow-only mode.

Required range: x > 0
Example:

100

collateral_token
string | null
default:USDC

A token identifier - either a supported symbol (e.g., USDC, WETH) or a valid Ethereum address (0x...)

Example:

"WETH"

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.

Example:

false

fee
CreditFee · object | null

Optional fee configuration. If provided, a fee will be deducted from the borrowed amount and sent to the specified recipient address.

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 | null

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

Example:
{
  "chainId": "0x2105",
  "data": "0x6a761202000000000000000000000000...",
  "from": "0xc98949522db2eE403d6c75E91DDEe875a824bB10",
  "gas": "0xb71b0",
  "maxFeePerGas": "0x3b9aca00",
  "maxPriorityFeePerGas": "0x5f5e100",
  "nonce": "0x2b",
  "to": "0xaB5801a7D398351b8bE11C439e05C5B3259aeC9B",
  "value": "0x0"
}
eip_712
BatchedSafeOperationsResponse · object | null

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

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" }
    ]
  }
}
estimated_collateral_amount
string | null

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

Pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
Example:

"99.8500000000"

fee_amount
string | null

The fee amount charged on the borrow, in borrow token units. Present when a fee was applied.

Pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
Example:

"0.1500000000"