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

# Plan Borrow

> Create a plan to borrow assets from a lending protocol

# Plan Borrow

Creates a plan to borrow assets from a lending protocol using collateral. Returns a plan ID and an EIP-712 digest that must be signed to authorize execution.

## Request

```
POST /accounts/:account_id/plan/borrow
```

### Path parameters

| Parameter    | Type   | Description        |
| ------------ | ------ | ------------------ |
| `account_id` | string | The sub-account ID |

### Body parameters

| Parameter           | Type   | Required    | Description                                                                                    |
| ------------------- | ------ | ----------- | ---------------------------------------------------------------------------------------------- |
| `amount`            | string | Yes         | Amount to borrow in the asset's smallest unit                                                  |
| `asset`             | string | Yes         | Asset to borrow (e.g., `"USDC"`)                                                               |
| `collateral_amount` | string | Yes         | Collateral amount in its smallest unit                                                         |
| `collateral_asset`  | string | Yes         | Collateral asset (e.g., `"WETH"`)                                                              |
| `network`           | string | Yes         | Target network (e.g., `"base"`, `"mainnet"`). Funds on other chains are bridged automatically. |
| `protocol`          | string | Yes         | Lending protocol: `"compound"` or `"morpho"`                                                   |
| `market`            | string | Morpho only | Morpho market ID (0x-prefixed 32-byte hex)                                                     |

## Examples

### Compound

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/plan/borrow \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "amount": "1000000",
      "asset": "USDC",
      "collateral_amount": "500000000000000000",
      "collateral_asset": "WETH",
      "network": "base",
      "protocol": "compound"
    }'
  ```

  ```typescript TypeScript theme={null}
  const plan = await client.plan.borrow("acc_2o0yiljtp378", {
    amount: "1000000",
    asset: "USDC",
    collateralAmount: "500000000000000000",
    collateralAsset: "WETH",
    network: "base",
    protocol: "compound",
  });
  ```

  ```python Python theme={null}
  plan = await client.plan.borrow(
      "acc_2o0yiljtp378",
      amount="1000000",
      asset="USDC",
      collateral_amount="500000000000000000",
      collateral_asset="WETH",
      network="base",
      protocol="compound",
  )
  ```

  ```rust Rust theme={null}
  use legend_client::BorrowParams;

  let plan = client.plan.borrow("acc_2o0yiljtp378", &BorrowParams {
      amount: "1000000".into(),
      asset: "USDC".into(),
      collateral_amount: "500000000000000000".into(),
      collateral_asset: "WETH".into(),
      network: "base".into(),
      protocol: "compound".into(),
  }).await?;
  ```
</CodeGroup>

### Morpho

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/plan/borrow \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "amount": "1000000",
      "asset": "USDC",
      "collateral_amount": "500000000000000000",
      "collateral_asset": "WETH",
      "network": "base",
      "protocol": "morpho",
      "market": "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc"
    }'
  ```

  ```typescript TypeScript theme={null}
  const plan = await client.plan.borrow("acc_2o0yiljtp378", {
    amount: "1000000",
    asset: "USDC",
    collateralAmount: "500000000000000000",
    collateralAsset: "WETH",
    network: "base",
    protocol: "morpho",
    market: "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
  });
  ```

  ```python Python theme={null}
  plan = await client.plan.borrow(
      "acc_2o0yiljtp378",
      amount="1000000",
      asset="USDC",
      collateral_amount="500000000000000000",
      collateral_asset="WETH",
      network="base",
      protocol="morpho",
      market="0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
  )
  ```

  ```rust Rust theme={null}
  use legend_client::BorrowParams;

  let plan = client.plan.borrow("acc_2o0yiljtp378", &BorrowParams {
      amount: "1000000".into(),
      asset: "USDC".into(),
      collateral_amount: "500000000000000000".into(),
      collateral_asset: "WETH".into(),
      network: "base".into(),
      protocol: "morpho".into(),
      market: Some("0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc".into()),
  }).await?;
  ```
</CodeGroup>

```json Response (201 Created) theme={null}
{
  "plan_id": "pln_71mcui082png",
  "details": {
    "quark_operation_actions": [...],
    "eip712_data": {
      "digest": "0x8a3f...b7c2",
      "domain_separator": "0x...",
      "hash_struct": "0x..."
    }
  },
  "expires_at": "2025-06-15T10:32:00Z"
}
```

### Response fields

| Field                        | Type   | Description                                                 |
| ---------------------------- | ------ | ----------------------------------------------------------- |
| `plan_id`                    | string | Unique identifier for this plan (`pln_` prefix)             |
| `details`                    | object | Transaction details including EIP-712 signing data          |
| `details.eip712_data.digest` | string | The hash to sign with the account's signer key              |
| `expires_at`                 | string | ISO 8601 timestamp — plan must be executed before this time |

## Errors

| Status | Code             | Description                                                             |
| ------ | ---------------- | ----------------------------------------------------------------------- |
| 400    | `invalid_params` | Missing required parameters, unsupported protocol, or invalid market ID |
| 400    | `plan_failed`    | Could not generate a valid plan (e.g., insufficient collateral)         |
| 400    | `no_wallet`      | Account has no wallets                                                  |
| 408    | `timeout`        | Folio computation timed out                                             |

## Notes

* Plans expire after 2 minutes. Sign and execute via [Execute Plan](/api-reference/plan-execute) before expiry.
* The `market` parameter is required for Morpho and must be a valid 32-byte market ID.
* The resulting activity will have `action_type: "COMET_BORROW"` (Compound) or `"MORPHO_BORROW"` (Morpho) in its metadata.
