Skip to main content
This guide covers the full borrow lifecycle through the Borrow API: list markets, read positions, build actions, sign them with your own signer, and track their status. The flow matches the Earn API: request unsigned transactions, sign them, broadcast them, and report the hash. The Borrow API is a separate service with its own base URL and endpoints. To embed a ready-made Borrow interface instead of building your own, see the Borrow widget guide. For the model behind every request here, see Borrow core concepts.
Borrow is not Earn’s Lending. Lending supplies an asset to earn yield through the Earn API. Borrow supplies collateral and borrows against it through the Borrow API. A Borrow supply action and a lending yield are different positions, even on the same protocol.

At a glance

Prerequisites

  • Borrow enabled for your project. Borrow is enabled per project. Contact hello@yield.xyz with the API key you test with. Start with your dev environment.
  • Markets enabled for your project. The default market list returns only the markets enabled for your project. Browse every market with scope=all (see List markets) and send Yield.xyz the market ids you want. Enabling a market changes what the list returns. It does not block actions on other active markets, so restrict users to certain markets in your own UI.
  • A funded test wallet on Ethereum or Base, holding collateral (for example WETH or cbBTC) and native gas. Testing on Base costs less than on Ethereum.
  • A signer for the target network: an EOA, smart account, MPC or custodial signer. See Transaction signing for EVM signing code.
We construct. You sign. Every action returns unsigned transactions. Yield.xyz never holds keys and never signs on your behalf. Inspect signablePayload before you sign it, and never modify it.

Basics

The examples use these shell variables:

Integrations and networks

Use the integrationId everywhere a request needs an integration. This table lists what the API supports. Your project settings decide which markets the default list returns. See Coverage for the protocols behind each integration.

The lifecycle

Seven calls cover every flow, in this order: discover integrations, list markets, read one market, read positions, build an action, sign and report each transaction, then poll the action.

1. Discover integrations

Each item has id, providerId, name, networks[], metadata (description, externalLink, logoURI) and actions[]. Each action has an id, a label and a JSON schema of its arguments. Read actions[] for your key rather than hard-coding the list, since the actions available can depend on your project’s configuration. Action ids, sent as action in requests: supply, borrow, repay, withdraw, enableCollateral, disableCollateral.
  • Aave and SparkLend expose supply, borrow, repay, withdraw, enableCollateral and disableCollateral.
  • Morpho Blue and Lista expose supply, borrow, repay and withdraw.

2. List markets

Query parameters: integrationId, network, scope (enabled or all, default enabled), offset and limit. scope=enabled returns only the markets enabled for your project. If none are enabled yet, the response is an empty list (total: 0), not an error. scope=all lists every market, so you can browse and pick the ids to enable. POST /v1/actions accepts any active market, whatever the list returns. There is no server-side filter by token symbol. Filter on your side, as in Testing with USDC markets.
Market data syncs from the chain every few minutes, so values can lag the chain by up to that interval.

3. Read one market

cURL
The response has the same shape as one list item. It returns 404 for an unknown id and for a market that is no longer active. Always take ids from GET /v1/markets and never build them yourself: the format differs by integration, and Morpho Blue and Lista ids carry an on-chain market key.

4. Read positions for an address

All three parameters are required, and address must be a 0x EVM address. One call covers one integration on one network. pendingActions[] on each row is { type, label, args }. type is the value to send as action in POST /v1/actions, and args comes pre-filled. An Aave debt row, for example, offers a repay with repayAll: true. This is the shortest way to build Repay and Withdraw buttons.
The top level carries address, integrationId, network, totalSuppliedUsd, totalCollateralUsd, totalBorrowedUsd, netWorthUsd, healthFactor, currentLtv, maxLtv, liquidationThreshold, availableToBorrowUsd, netApy, supplyBalances[] and debtBalances[].
  • supplyBalances[]: marketId, tokenAddress, tokenSymbol, balance, balanceRaw, balanceUsd, apy, isCollateral, positionState (isolated markets only, see Risk fields) and pendingActions[].
  • debtBalances[]: marketId, tokenAddress, tokenSymbol, balance, balanceRaw, balanceUsd, apy and pendingActions[].
On isolated integrations (Morpho Blue, Lista), positions cover the markets the address has used through the Borrow API. A position the address opened somewhere else does not appear. Positions are cached for about 30 seconds, except for an address that ran an action in the last 30 minutes.

5. Build an action

Every action is a POST /v1/actions with the same envelope:
args fields: marketId (required), amount or amountRaw, tokenAddress, collateralTokenAddress, collateralAmount or collateralAmountRaw, repayAll, and borrowAmount with targetLtv. The network comes from the market, so you do not send it.

Preview with simulate

POST /v1/actions/simulate takes the same body, saves nothing, and returns:
  • gas: amount (the total native-token cost, null unless every transaction has an estimate), token, and transactions[] with amount, token, gasLimit and type for each transaction that has an estimate.
  • outcome: the predicted risk fields described in Risk fields.
Call simulate while the user types an amount, so you do not create an action on every keystroke.

Action bodies

Pick the tab for the action you are building. Each tab lists the transactions the API returns, in order.
Supply collateral and borrow in one action. Use action: "borrow" with a collateral leg. The API returns the collateral transactions first, then the borrow.On Aave (a pool market), pick the market whose loanToken is the token to borrow, and pick the collateral from that market’s collateralTokens[]. On Morpho Blue (an isolated market), the market fixes the collateral token, so you send amounts only:
On Aave, collateralTokenAddress is required whenever you send collateralAmount. The loan token comes from the market, so tokenAddress is optional on borrow and repay. If you send it, it must match loanToken.address.The transactions[] order, without fees:To size collateral from a target LTV instead, supply accepts borrowAmount plus targetLtv (for example "0.5") in place of amount, and the API calculates the collateral. On Aave this mode also needs tokenAddress, the collateral token. On Aave, SparkLend and Morpho Blue the result comes back as metadata.effectiveCollateralAmount. You then send a separate borrow.

What POST /v1/actions returns

Status 201, with id (the action id), integrationId, action, address, status, transactions[], hasNextStep, currentStep, totalSteps, rawArguments, metadata and createdAt.
Response (excerpt)
The payload has no nonce or fee fields. Your signer sets the nonce, the chain id (from chainId) and EIP-1559 fees. Borrow actions are single-step: hasNextStep is false and totalSteps is 1, so you never call POST /v1/actions/{id}/step. Calling it returns 400.

6. Sign, broadcast, report the hash

Go through transactions[] in array order. For each transaction:
1

Sign

Parse signablePayload, set the nonce and fees, and sign.
2

Broadcast

Broadcast the signed transaction.
3

Report the hash

cURL
4

Wait for confirmation

Poll the action (step 7) until this transaction is CONFIRMED, then sign the next one.
Later transactions depend on earlier ones: a SUPPLY needs its APPROVAL mined first, or it reverts for insufficient allowance. If a gas estimate fails because of such a dependency when the API builds the action, the API uses a fixed gas limit instead. Do not treat gasLimit on later transactions as a live estimate. To have Yield.xyz broadcast for you, send { "signedPayload": "0x..." } instead of transactionHash. Send one of the two, never both. The response carries transactionHash, link (a block explorer URL) and status, which is BROADCASTED on success. A transaction can be submitted once, while it is still CREATED. A second submit returns 400 with its current status. When Yield.xyz fails to broadcast a signedPayload, the call returns 503 and the transaction is marked FAILED.

7. Poll status

cURL
After you submit, Yield.xyz tracks confirmation in the background. Poll the action every 2 to 5 seconds until it reaches a final status. Transaction statuses: CREATED, BROADCASTED, CONFIRMED and FAILED. The full enums, including values the Borrow API does not return, are in Borrow objects. After SUCCESS, call GET /v1/positions again to show the new balances.

Risk fields

A health factor above 1 is safe. Below 1, the position can be liquidated. Health factors are null when there is no debt, and predictedHealthFactor is null when the action leaves no debt.

Pooled and isolated markets

Aave and SparkLend pool all collateral in the account. Read the top-level healthFactor, currentLtv, maxLtv, liquidationThreshold and availableToBorrowUsd. maxLtv and liquidationThreshold are blended across all of the account’s collateral and include e-mode. supplyBalances[].positionState is not present.
A workflow that reads only the account-level fields silently breaks on Morpho Blue and Lista. Branch on integrationId, or check whether positionState is present, before you decide which fields to read.

Predicted health factor

Every action response has metadata with currentHealthFactor, predictedHealthFactor, currentLtv, predictedLtv and liquidationThreshold. Show predictedHealthFactor on the confirm screen, and block an action client side when it would push the health factor below a level you accept.

Liquidation history (Morpho Blue only)

cURL
Optional parameters: marketId (a market id or the on-chain bytes32 market key), offset and limit. Results are newest first. Each item has id, marketId, type (partial, full or null), realizedBadDebt, occurredAt, blockNumber, transactionHash, transactionLink, liquidator, repaidDebt, seizedCollateral, badDebt and lif. A fully liquidated position no longer appears in GET /v1/positions, so this endpoint is the only place to show it.

Fees

Fees are available on Morpho Blue markets only, and are off unless configured for your project. With no fee configuration, and on Aave, SparkLend and Lista, the fee fields on each market are "0" or null. A project can have two kinds of fee: a deposit fee on supplied collateral (supplyCollateralFeeBps, up to 500 bps, enforced on-chain by the fee wrapper) and an origination fee on borrows (originationFeeBps). With an origination fee, amount stays what the user receives, and the recorded debt is that amount plus the fee (metadata.originationFeeAmount, metadata.effectivePrincipalAmount). With a 1% fee, for example, a 500 USDC borrow opens about 505 USDC of debt and the user receives 500 USDC. Origination fees also add the AUTHORIZE and DEAUTHORIZE transactions described in the Authorize (Morpho) tab of Action bodies. To set up fees, contact hello@yield.xyz. See Borrow monetization for how the fee contracts work.

Testing with USDC markets

Find the market ids

List markets with scope=all and filter for USDC as the loan token:
cURL
If total is above 100, page with offset=100, offset=200 and so on. To try the other chain, swap network=base and network=ethereum. Both integrations support both chains. For Morpho Blue, pick a market with enough availableLiquidity for your test borrow and a collateral your test wallet already holds.

Run the flow

  1. Call POST /v1/actions/simulate with a small borrow plus collateralAmount (the body from the Supply + borrow tab in Action bodies). Check outcome.predictedHealthFactor and gas.
  2. Send the same body to POST /v1/actions. Sign and submit each transaction as in step 6, and poll as in step 7.
  3. Check GET /v1/positions: the top-level fields on Aave, supplyBalances[].positionState on Morpho Blue.
  4. Close the position: repay with repayAll: true, then withdraw the full collateral. Check that the debt and supply rows are gone from GET /v1/positions.

Reporting

On the Borrow API:
cURL
address is required. Optional filters: integrationId, network, action, status, statuses (comma-separated or repeated, up to 7; it overrides status), offset and limit. Results cover your project’s actions only, newest first, with the same item shape as GET /v1/actions/{id} minus metadata.

Troubleshooting

Pick the area, then open the error string or symptom you see for its cause and fix.
The header is missing, is not a UUID, or the key is unknown. Check x-api-key. Expired and rotated keys return their own 401 message.
Too many requests for your key. Back off and retry.
An unknown field in the body or query. The API rejects anything it does not define.
address or a token address is not 0x plus 40 hex characters.

Next steps

Borrow widget

Add the Borrow tab to the Yield.xyz widget instead of building your own UI.

Core concepts

The market, position and action model behind every integration.

Borrow objects

Every enum, field and nullability rule in the Borrow API.

Transaction signing

EVM signing code for the transactions this guide returns.