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

# Borrow API

> The full Borrow API lifecycle: list markets, read positions, build supply, borrow, repay and withdraw actions, sign them with your own signer, and track status.

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](https://docs.yield.xyz/guides/borrow/widget.md) guide. For the model behind every request here, see [Borrow core concepts](https://docs.yield.xyz/documentation/borrow/core-concepts/index.md).

> [!NOTE]
>
> Borrow is not [Earn's Lending](https://docs.yield.xyz/documentation/earn/defi/lending/index.md). 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

| Item | Value |
| - | - |
| Base URL | `https://borrow.yield.xyz/v1` |
| Live integrations | Aave V3, Morpho Blue, SparkLend, Lista Lending |
| Market types | Aave and SparkLend are pooled: all collateral sits in one account. Morpho Blue and Lista are isolated: one collateral token and one loan token per market. |
| API key | The same project key you use for the Earn API |
| Fees | Off unless configured for your project. See [Fees](#fees). |

## Prerequisites

* **Borrow enabled for your project.** Borrow is enabled per project. Contact [hello@yield.xyz](mailto: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](#2-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](https://docs.yield.xyz/guides/transaction-signing/evm.md) for EVM signing code.

> [!NOTE]
>
> 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

| Item | Value |
| - | - |
| Versioning | In the path. Every route starts with `/v1/`. |
| Auth header | `x-api-key: <your API key>`, a UUID. A missing, malformed or unknown key returns `401 API key is missing or invalid`. Expired and rotated keys return their own `401` message. |
| Rate limits | Per API key. Over the limit, requests return `429`. |
| Pagination | `offset` (default `0`) and `limit` (default `25`, max `100`). List responses are `{ "items": [...], "total", "offset", "limit" }`. |
| Unknown fields | Rejected. The API validates bodies and query strings strictly, so an extra field returns `400`. |
| Amounts | Most requests take `amount` (human units, for example `"100"` for 100 USDC) or `amountRaw` (base units, for example `"100000000"`). Send one, never both. |
| Units | Rates, ratios and APYs are decimal strings: `"0.0567"` is 5.67%, `"0.80"` is 80%. |

The examples use these shell variables:

```bash theme={null}
export BORROW=https://borrow.yield.xyz
export YIELD_API_KEY=<your-api-key>
export ADDR=<your wallet EVM address>
```

### Integrations and networks

Use the `integrationId` everywhere a request needs an integration.

| `integrationId` | `providerId` | Market type | Networks (API values) |
| - | - | - | - |
| `aave-borrow` | `aave` | `pool` | `ethereum`, `optimism`, `arbitrum`, `polygon`, `avalanche-c`, `base`, `binance`, `gnosis`, `sonic`, `linea`, `monad`, `plasma` |
| `morpho-blue-borrow` | `morpho` | `isolated` | `ethereum`, `arbitrum`, `avalanche-c`, `base`, `binance`, `gnosis`, `linea`, `monad`, `optimism`, `polygon`, `robinhood`, `sonic` |
| `sparklend-borrow` | `sparklend` | `pool` | `ethereum` |
| `lista-borrow` | `lista` | `isolated` | `binance`, `ethereum` |

This table lists what the API supports. Your project settings decide which markets the default list returns. See [Coverage](https://docs.yield.xyz/documentation/borrow/coverage.md) 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

```bash cURL theme={null}
curl -s "$BORROW/v1/integrations" -H "x-api-key: $YIELD_API_KEY"
curl -s "$BORROW/v1/integrations/morpho-blue-borrow" -H "x-api-key: $YIELD_API_KEY"
```

```json Response (excerpt) theme={null}
{
  "id": "aave-borrow",
  "providerId": "aave",
  "name": "Aave V3 Borrow",
  "networks": ["ethereum", "optimism", "arbitrum", "base", "..."],
  "actions": [
    { "id": "supply", "label": "Supply", "schema": { "...": "..." } },
    { "id": "borrow", "label": "Borrow", "schema": { "...": "..." } },
    { "id": "repay", "label": "Repay", "schema": { "...": "..." } },
    { "id": "withdraw", "label": "Withdraw", "schema": { "...": "..." } },
    { "id": "enableCollateral", "label": "Enable Collateral", "schema": { "...": "..." } },
    { "id": "disableCollateral", "label": "Disable Collateral", "schema": { "...": "..." } }
  ]
}
```

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

```bash cURL theme={null}
# Markets enabled for your project (default)
curl -s "$BORROW/v1/markets?integrationId=aave-borrow&network=ethereum" -H "x-api-key: $YIELD_API_KEY"

# Every market the API supports, enabled or not
curl -s "$BORROW/v1/markets?integrationId=morpho-blue-borrow&network=base&scope=all&limit=100" -H "x-api-key: $YIELD_API_KEY"
```

```json Response (excerpt, one item) theme={null}
{
  "id": "MARKET_ID",
  "integrationId": "aave-borrow",
  "network": "base",
  "type": "pool",
  "loanToken": { "symbol": "USDC", "address": "0x...", "decimals": 6 },
  "collateralTokens": [
    {
      "token": { "symbol": "WETH", "address": "0x..." },
      "maxLtv": "0.80",
      "liquidationThreshold": "0.83",
      "liquidationPenalty": "0.05",
      "supplyRate": "0.02"
    }
  ],
  "borrowRate": "0.0567",
  "availableLiquidity": "1250000.00",
  "isBorrowEnabled": true,
  "minLoan": null
}
```

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](#testing-with-usdc-markets).

> [accordion] Market fields
>
> | Field | Meaning |
> | - | - |
> | `id` | Market id. You pass it as `args.marketId` in every action. |
> | `integrationId`, `network` | The integration and chain the market lives on. |
> | `type` | `pool` (Aave style) or `isolated` (Morpho style). |
> | `poolAddress` | The pool or protocol contract the market lives on. |
> | `loanToken` | The token users borrow: `address`, `symbol`, `name`, `decimals` and, when available, `logoURI`. |
> | `collateralTokens[]` | Accepted collateral, each with `token`, `priceUsd`, `maxLtv`, `liquidationThreshold`, `liquidationPenalty` and `supplyRate`. One entry on isolated markets, every eligible collateral on pool markets. |
> | `borrowRate` | Variable borrow rate, as a decimal. |
> | `availableLiquidity`, `availableLiquidityRaw` | What can still be borrowed from the market. |
> | `totalSupply`, `totalBorrow`, `utilizationRate`, `loanTokenPriceUsd` | Market stats. `totalSupplyRaw` and `totalBorrowRaw` give the totals in raw token units. |
> | `isBorrowEnabled` | Whether borrowing is on for this asset. Check it, and `availableLiquidity`, before offering a market. |
> | `minLoan` | Minimum debt in loan-token units, or `null` when the market has no minimum. Only Lista sets one. |
> | Fee fields | `supplyCollateralFeeBps`, `feeWrapperAddress`, `originationFeeBps`, `originationFeeWrapperAddress`. See [Fees](#fees). |

Market data syncs from the chain every few minutes, so values can lag the chain by up to that interval.

### 3. Read one market

```bash cURL theme={null}
curl -s "$BORROW/v1/markets/$MARKET_ID" -H "x-api-key: $YIELD_API_KEY"
```

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

```bash cURL theme={null}
curl -s "$BORROW/v1/positions?integrationId=aave-borrow&network=ethereum&address=$ADDR" -H "x-api-key: $YIELD_API_KEY"
```

```json Response (excerpt, Aave) theme={null}
{
  "totalSuppliedUsd": "1400.00",
  "totalCollateralUsd": "1400.00",
  "totalBorrowedUsd": "500.00",
  "healthFactor": "2.31",
  "currentLtv": "0.36",
  "availableToBorrowUsd": "620.00",
  "supplyBalances": [
    { "marketId": "MARKET_ID", "tokenSymbol": "WETH", "balance": "0.5", "apy": "0.0203", "isCollateral": true,
      "pendingActions": [
        { "type": "withdraw", "label": "Withdraw WETH", "args": { "marketId": "MARKET_ID", "tokenAddress": "0x...", "amountRaw": "500000000000000000" } },
        { "type": "disableCollateral", "label": "Disable WETH as collateral", "args": { "marketId": "MARKET_ID", "tokenAddress": "0x..." } } ] }
  ],
  "debtBalances": [
    { "marketId": "MARKET_ID", "tokenSymbol": "USDC", "balance": "500.00", "apy": "0.0567",
      "pendingActions": [ { "type": "repay", "label": "Repay USDC", "args": { "marketId": "MARKET_ID", "tokenAddress": "0x...", "repayAll": true } } ] }
  ]
}
```

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.

> [accordion] Position fields
>
> 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](#risk-fields)) and `pendingActions[]`.
> * `debtBalances[]`: `marketId`, `tokenAddress`, `tokenSymbol`, `balance`, `balanceRaw`, `balanceUsd`, `apy` and `pendingActions[]`.

> [!WARNING]
>
> 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:

```json theme={null}
{
  "integrationId": "aave-borrow",
  "action": "supply | borrow | repay | withdraw | enableCollateral | disableCollateral",
  "address": "0x...",
  "args": { "marketId": "...", "...": "..." }
}
```

`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](#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.

> [tab] Supply + borrow
>
> 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:
>
> ```bash Aave theme={null}
> curl -s -X POST "$BORROW/v1/actions" -H "x-api-key: $YIELD_API_KEY" -H "content-type: application/json" -d '{
>   "integrationId": "aave-borrow",
>   "action": "borrow",
>   "address": "'"$ADDR"'",
>   "args": {
>     "marketId": "<Aave USDC market id>",
>     "amount": "100",
>     "collateralTokenAddress": "<collateralTokens[].token.address>",
>     "collateralAmount": "0.05"
>   }
> }'
> ```
>
> ```bash Morpho Blue theme={null}
> curl -s -X POST "$BORROW/v1/actions" -H "x-api-key: $YIELD_API_KEY" -H "content-type: application/json" -d '{
>   "integrationId": "morpho-blue-borrow",
>   "action": "borrow",
>   "address": "'"$ADDR"'",
>   "args": {
>     "marketId": "<Morpho USDC market id>",
>     "amount": "100",
>     "collateralAmount": "0.002"
>   }
> }'
> ```
>
> 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:
>
> | Integration | Order |
> | - | - |
> | Aave, SparkLend | `APPROVAL` (only when the allowance is short), then `SUPPLY`, then `BORROW` |
> | Morpho Blue | `WRAP` (only when the collateral is the wrapped native token and the wallet needs to wrap), then `APPROVAL` (only when the allowance is short), then `SUPPLY`, then `BORROW` |
>
> 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`.

> [tab] Supply
>
> Supply collateral only:
>
> ```json theme={null}
> { "integrationId": "aave-borrow", "action": "supply", "address": "0x...",
>   "args": { "marketId": "<market id>", "tokenAddress": "<collateral token>", "amount": "0.05" } }
> ```
>
> On Aave and SparkLend, `supply` and `withdraw` need `tokenAddress` with `amount`, and the token must be one of the market's collateral tokens. On Morpho Blue and Lista, leave `tokenAddress` out. Transactions: `WRAP` (Morpho Blue, when needed), then `APPROVAL` (when needed), then `SUPPLY`.

> [tab] Borrow more
>
> The same as Supply + borrow without the collateral fields:
>
> ```json theme={null}
> { "integrationId": "morpho-blue-borrow", "action": "borrow", "address": "0x...",
>   "args": { "marketId": "<market id>", "amount": "50" } }
> ```
>
> Transactions: `BORROW`.

> [tab] Repay
>
> ```json Partial repay theme={null}
> { "integrationId": "aave-borrow", "action": "repay", "address": "0x...",
>   "args": { "marketId": "<market id>", "amount": "25" } }
> ```
>
> ```json Full repay theme={null}
> { "integrationId": "morpho-blue-borrow", "action": "repay", "address": "0x...",
>   "args": { "marketId": "<market id>", "repayAll": true } }
> ```
>
> * `repayAll: true` clears the whole debt, accrued interest included. Do not send `amount` or `amountRaw` with it.
> * A full repay approves the maximum allowance for the loan token, because the debt keeps growing until the transaction lands.
> * A full repay checks the wallet first and fails if the loan-token balance does not cover the debt. Keep a little more than `debtBalances[].balance` in the wallet.
> * On every integration, an `amount` at or above the on-chain debt counts as a full repay.
> * To repay and pull collateral in one action, add `collateralAmount` (on Aave, also `collateralTokenAddress`). The withdraw runs after the repay.
>
> Transactions: `APPROVAL` (when needed), then `REPAY`, then `WITHDRAW` (only with a collateral amount).

> [tab] Withdraw
>
> Withdraw collateral:
>
> ```json theme={null}
> { "integrationId": "morpho-blue-borrow", "action": "withdraw", "address": "0x...",
>   "args": { "marketId": "<market id>", "amount": "0.002" } }
> ```
>
> Transactions: `WITHDRAW`. The protocol releases collateral only while the position stays healthy, and releases all of it only once the debt is zero.

> [tab] Authorize (Morpho)
>
> Authorize and deauthorize apply to Morpho Blue only. There is no `deauthorize` action. `AUTHORIZE` and `DEAUTHORIZE` are transaction types the API adds inside Morpho Blue actions when your project has a fee contract configured:
>
> * The first borrow through the fee contract includes an `AUTHORIZE`, so the contract can borrow on the wallet's behalf.
> * If your project is configured to leave no standing authorization, every borrow through the fee contract ends with a `DEAUTHORIZE`, so each borrow authorizes again.
> * A `withdraw`, or a `repay` with a collateral leg, that closes the position ends with a `DEAUTHORIZE`. The position counts as closed when the withdraw takes all remaining collateral, no debt is left, the authorization is still in place, and the address has no other open Morpho Blue position on that network among the markets it has used through the Borrow API.
>
> Without fees, Morpho Blue borrows go straight to Morpho and return no `AUTHORIZE`, `DEAUTHORIZE` or `BUNDLE` transactions. Handle these types in your signer anyway, so a later fee change does not break it.

> [tab] Collateral toggle
>
> Enable or disable collateral (Aave and SparkLend only):
>
> ```json theme={null}
> { "integrationId": "aave-borrow", "action": "disableCollateral", "address": "0x...",
>   "args": { "marketId": "<market id>", "tokenAddress": "<collateral token>" } }
> ```
>
> Transactions: `ENABLE_COLLATERAL` or `DISABLE_COLLATERAL`.

#### What `POST /v1/actions` returns

Status `201`, with `id` (the action id), `integrationId`, `action`, `address`, `status`, `transactions[]`, `hasNextStep`, `currentStep`, `totalSteps`, `rawArguments`, `metadata` and `createdAt`.

```json Response (excerpt) theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "action": "supply",
  "status": "CREATED",
  "transactions": [
    { "id": "6f1c2b7e-3a4d-4e8f-9b1a-2c5d7e9f0a11", "type": "APPROVAL", "status": "CREATED", "chainId": "8453", "signingFormat": "EVM_TRANSACTION", "signablePayload": "..." },
    { "id": "9d3e5a1c-7b2f-4c60-8a4e-1f6b0c2d8e22", "type": "SUPPLY", "status": "CREATED", "chainId": "8453", "signingFormat": "EVM_TRANSACTION", "signablePayload": "..." }
  ],
  "hasNextStep": false,
  "totalSteps": 1,
  "metadata": { "currentHealthFactor": null, "predictedHealthFactor": null, "currentLtv": "0.00", "predictedLtv": "0.00" }
}
```

> [accordion] Fields in each `transactions[]` item
>
> | Field | Notes |
> | - | - |
> | `id` | Transaction id (UUID). You submit against it. |
> | `network`, `chainId` | `chainId` is a string, for example `"1"`. |
> | `type` | `APPROVAL`, `AUTHORIZE`, `DEAUTHORIZE`, `SUPPLY`, `BORROW`, `REPAY`, `WITHDRAW`, `ENABLE_COLLATERAL`, `DISABLE_COLLATERAL`, `BUNDLE` or `WRAP`. Do not reject unknown values in your signer, since new types can be added. |
> | `status` | `CREATED` on a new action. |
> | `address` | The signer address. |
> | `signingFormat` | `EVM_TRANSACTION` for every Borrow integration. |
> | `signablePayload` | A JSON string of the unsigned EVM transaction, with `from`, `to`, `data`, `gasLimit` and `value`. |

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

```bash cURL theme={null}
curl -s -X POST "$BORROW/v1/transactions/$TRANSACTION_ID/submit" \
  -H "x-api-key: $YIELD_API_KEY" -H "content-type: application/json" \
  -d '{ "transactionHash": "0x<64 hex characters>" }'
```

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

```bash cURL theme={null}
curl -s "$BORROW/v1/actions/$ACTION_ID" -H "x-api-key: $YIELD_API_KEY"
```

After you submit, Yield.xyz tracks confirmation in the background. Poll the action every 2 to 5 seconds until it reaches a final status.

| Action status | Meaning |
| - | - |
| `CREATED` | Nothing submitted yet, or a submitted transaction has confirmed and others are still unsubmitted. This is the signal that the next transaction is ready to sign. |
| `PROCESSING` | A submitted transaction is waiting to confirm. |
| `SUCCESS` | Every transaction is confirmed. Final. |
| `FAILED` | A transaction failed on-chain. Final. |
| `STALE` | A broadcast transaction has stayed unconfirmed for more than 30 minutes. Not a failure: the action moves on if the transaction confirms, and you can still submit any transaction that is `CREATED`. |

Transaction statuses: `CREATED`, `BROADCASTED`, `CONFIRMED` and `FAILED`. The full enums, including values the Borrow API does not return, are in [Borrow objects](https://docs.yield.xyz/api-reference/borrow/objects.md#action-statuses).

After `SUCCESS`, call `GET /v1/positions` again to show the new balances.

## Risk fields

| Field | Market (`GET /v1/markets`) | Position (`GET /v1/positions`) | Action (`metadata`, simulate `outcome`) |
| - | - | - | - |
| Max LTV | `collateralTokens[].maxLtv` | `maxLtv` | |
| Liquidation threshold | `collateralTokens[].liquidationThreshold` | `liquidationThreshold`, or `positionState.liquidationThreshold` | `liquidationThreshold` |
| Liquidation penalty | `collateralTokens[].liquidationPenalty` | | |
| Current LTV | | `currentLtv`, or `positionState.currentLtv` | `currentLtv`, `predictedLtv` |
| Health factor | | `healthFactor`, or `positionState.healthFactor` | `currentHealthFactor`, `predictedHealthFactor` |
| Borrow headroom | | `availableToBorrowUsd`, or `positionState.availableToBorrowUsd` | |
| Totals after the action | | | `predictedTotalSupplyUsd`, `predictedTotalDebtUsd` |

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

> [tab] Pooled (Aave, SparkLend)
>
> **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.

> [tab] Isolated (Morpho Blue, Lista)
>
> **Morpho Blue and Lista** isolate each market. The top-level `healthFactor` and `availableToBorrowUsd` are always `null`. Read each supply balance's `positionState` (`currentLtv`, `liquidationThreshold`, `healthFactor`, `availableToBorrowUsd`) instead. The top-level `maxLtv` and `liquidationThreshold` roll up across markets, so do not use them to size a single market.

> [!WARNING]
>
> 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)

```bash cURL theme={null}
curl -s "$BORROW/v1/positions/liquidations?integrationId=morpho-blue-borrow&network=base&address=$ADDR" -H "x-api-key: $YIELD_API_KEY"
```

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](#action-bodies).

To set up fees, contact [hello@yield.xyz](mailto:hello@yield.xyz). See [Borrow monetization](https://docs.yield.xyz/documentation/borrow/monetization.md) 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:

```bash cURL theme={null}
# Aave USDC on Ethereum (one Aave market per loan token)
curl -s "$BORROW/v1/markets?integrationId=aave-borrow&network=ethereum&scope=all&limit=100" -H "x-api-key: $YIELD_API_KEY" \
  | jq '.items[] | select(.loanToken.symbol=="USDC") | {id, borrowRate, availableLiquidity, collateral: [.collateralTokens[] | {symbol: .token.symbol, address: .token.address, maxLtv}]}'

# Morpho Blue USDC markets on Base (one market per collateral and USDC pair)
curl -s "$BORROW/v1/markets?integrationId=morpho-blue-borrow&network=base&scope=all&limit=100" -H "x-api-key: $YIELD_API_KEY" \
  | jq '.items[] | select(.loanToken.symbol=="USDC") | {id, borrowRate, availableLiquidity, collateral: .collateralTokens[0].token.symbol, maxLtv: .collateralTokens[0].maxLtv}'
```

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](#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](#6-sign-broadcast-report-the-hash), and poll as in [step 7](#7-poll-status).
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

> [tab] Per wallet
>
> On the Borrow API:
>
> ```bash cURL theme={null}
> curl -s "$BORROW/v1/actions?address=$ADDR&network=base&integrationId=morpho-blue-borrow&statuses=SUCCESS,FAILED" -H "x-api-key: $YIELD_API_KEY"
> ```
>
> `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`.

> [tab] Project-wide
>
> These routes are on the Earn API at `https://api.yield.xyz`, next to the other [programmatic reporting](https://docs.yield.xyz/documentation/advanced-setup/reporting.md) routes, not on `borrow.yield.xyz`. They take your admin key in `x-admin-api-key`, not the project API key. See [Programmatic access](https://docs.yield.xyz/documentation/advanced-setup/programmatic-access.md) for admin keys.
>
> * `GET /v1/programmatic/projects/{projectId}/reporting/borrow/actions`: every borrow action for the project. Filters: `address`, `status`, `type`, `marketId`, `integrationId`, `from`, `to`, `page` and `limit` (default 10, max 50). Date filters apply to `completedAt`. Send `from` and `to` together, spanning less than 10 days, or neither to get the last 10 days.
> * `GET /v1/programmatic/projects/{projectId}/reporting/borrow/revenue` and `.../borrow/revenue/summary`: fee revenue. Both require `from`, `to` and `granularity`, with a range of up to 90 days. Without fees, revenue is zero.
>
> A `to` given as a date with no time, for example `2026-10-31`, includes the whole of that day in UTC.

## Troubleshooting

Pick the area, then open the error string or symptom you see for its cause and fix.

> [tab] Auth
>
> > [accordion] `401 API key is missing or invalid`
> >
> > 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.
>
> > [accordion] `429`
> >
> > Too many requests for your key. Back off and retry.
>
> > [accordion] `400` naming an unexpected property
> >
> > An unknown field in the body or query. The API rejects anything it does not define.
>
> > [accordion] `400 Must be a valid Ethereum address`
> >
> > `address` or a token address is not `0x` plus 40 hex characters.

> [tab] Markets
>
> > [accordion] `GET /v1/markets` returns `total: 0`
> >
> > No markets are enabled for your project yet. Use `scope=all` and send Yield.xyz the ids to enable.
>
> > [accordion] `400 Unknown integration: X` on `GET /v1/markets`
> >
> > A typo in `integrationId`. Use the ids from [Integrations and networks](#integrations-and-networks).
>
> > [accordion] `404 Market X not found; has the borrow-markets-sync job run?`
> >
> > A wrong id, or the market is not active. `supply`, `borrow` and `enableCollateral` need an active market. `repay`, `withdraw` and `disableCollateral` also work on inactive markets.
>
> > [accordion] `404 Market X not found for integration Y`
> >
> > The market id belongs to another integration.
>
> > [accordion] `400 Integration X not found or not supported`, `404 Integration X not found`
> >
> > A typo in `integrationId`.
>
> > [accordion] `400 Network X is not supported by integration Y` on positions
> >
> > The network is outside that integration's list in [Integrations and networks](#integrations-and-networks).
>
> > [accordion] `400 Liquidation history is only available for Morpho Blue integrations`
> >
> > `GET /v1/positions/liquidations` takes `integrationId=morpho-blue-borrow` only.

> [tab] Amounts
>
> > [accordion] `400 Provide either amount or amountRaw, not both` (same for `collateralAmount`)
> >
> > Send one form only.
>
> > [accordion] `400 Provide repayAll or amount/amountRaw, not both`, `repayAll is only supported for repay actions`
> >
> > `repayAll` goes alone, and only on `repay`.
>
> > [accordion] `400 Either repayAll or amount/amountRaw must be provided`
> >
> > A repay with no amount.
>
> > [accordion] `400 ... must be greater than zero`
> >
> > A zero amount.
>
> > [accordion] `400 Must be a valid decimal amount`
> >
> > A negative amount, or one that is not a plain decimal string such as `"1.5"`.
>
> > [accordion] `400 borrowAmount and targetLtv must be provided together`, `... are only supported for supply actions`
> >
> > Target-LTV sizing is a `supply` feature and needs both fields.
>
> > [accordion] `400 Provide either a collateral amount (amount/amountRaw) or (borrowAmount + targetLtv), not both`
> >
> > Choose one way to size the supply.
>
> > [accordion] `400 tokenAddress does not match market loan token`
> >
> > On `borrow` and `repay`, `tokenAddress` must equal `loanToken.address`. You can also leave it out.
>
> > [accordion] `400 tokenAddress is not a valid collateral token for this market`, `collateralTokenAddress is not a valid collateral token for this market`
> >
> > Use an address from that market's `collateralTokens[]`.
>
> > [accordion] `collateralTokenAddress is required when collateralAmount or collateralAmountRaw is provided`
> >
> > An Aave or SparkLend borrow or repay with a collateral leg needs the collateral token.
>
> > [accordion] `tokenAddress is required for supply and withdraw`, `tokenAddress and amount are required for supply` (or `withdraw`)
> >
> > Aave and SparkLend collateral actions need `tokenAddress` with `amount` or `amountRaw`. In target-LTV mode the message is `tokenAddress is required when deriving collateral from borrowAmount + targetLtv`.

> [tab] Repay
>
> > [accordion] `No debt found to repay`
> >
> > `repayAll` on a Morpho Blue or Lista market where the address has no debt. On Aave and SparkLend the repay is still built.
>
> > [accordion] `Insufficient \<token\> balance to repay the full debt ...`
> >
> > The wallet holds less of the loan token than the debt. Top up, or repay a smaller amount.
>
> > [accordion] `Insufficient \<gas token\> balance to wrap collateral ...`
> >
> > Morpho Blue needs to wrap native token for the collateral, and the wallet does not hold enough.
>
> > [accordion] `Resulting \<token\> debt of X is below the market minimum of Y ...`
> >
> > A Lista borrow or partial repay would leave debt below `minLoan`. Borrow more, or use `repayAll` to close the position.

> [tab] Submit
>
> > [accordion] Submit returns `400 Transaction X is not ready for submission. Status: ...`
> >
> > That transaction was already submitted. Poll the action instead.
>
> > [accordion] Submit returns `400 Provide either signedPayload or transactionHash, not both`
> >
> > Send one.
>
> > [accordion] Submit returns `503 Transaction broadcast failed: ...`
> >
> > Only when Yield.xyz broadcasts your `signedPayload`. The transaction is marked `FAILED`. Build a new action.

> [tab] Onchain
>
> > [accordion] The transaction reverts on-chain
> >
> > Usually an earlier transaction in the list had not confirmed yet (the allowance was not set), or the position's health changed between build and sign. Create the action again and sign in order.
>
> > [accordion] `503` mentioning market metadata, pricing or position state
> >
> > An upstream data read failed. Retry after a short wait.

## Next steps

> [card] [Borrow widget](https://docs.yield.xyz/guides/borrow/widget.md)
>
> Add the Borrow tab to the Yield.xyz widget instead of building your own UI.

> [card] [Core concepts](https://docs.yield.xyz/documentation/borrow/core-concepts/index.md)
>
> The market, position and action model behind every integration.

> [card] [Borrow objects](https://docs.yield.xyz/api-reference/borrow/objects.md)
>
> Every enum, field and nullability rule in the Borrow API.

> [card] [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/evm.md)
>
> EVM signing code for the transactions this guide returns.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.