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

> ## Agent Instructions
> These are the Ampli Intelligence docs. API base: https://si.ampli.net/api/v1. API MCP: https://si.ampli.net/mcp.
> Auth is a partner key (X-Partner-Name and X-Partner-API-Key headers) or an x402 payment in USDC on Base.
> For a single-treasury agentic wallet or Wallet-as-a-Service, use the ampli^ SDK at https://ampli.net and https://docs.ampli.net. agk_ keys and /api/v1/agent-runtime belong to that SDK.
> Use only the routes and tools documented here. Do not invent endpoints or parameters.
> The ampli^ SDK (https://ampli.net, docs at https://docs.ampli.net) can use this intelligence to deliver a single-treasury agentic wallet or Wallet-as-a-Service. This host is si.ampli.net. Auth is a partner key or an x402 payment. agk_ keys and /api/v1/agent-runtime belong to the SDK Agent API.
> Every amount is an integer string in the token's base units. USDC, EURC, USDT0, and USDG use 6 decimals (1000000 is 1 USDC). WETH and cbETH use 18. cbBTC uses 8.
> The service is non-custodial. It returns an allocation, an action plan, and calldata. It never holds keys, signs, or sends a transaction.
> APR values are percentages measured now or over the trailing 7 days. They are not forecasts and nothing here guarantees a return.
> x402 payments are verified before the work and settled only when the response is 2xx. A 400 or 422 costs nothing.
> Partner headers always win. A request with a wrong partner key returns 401 and does not fall back to payment.
> Monitor alerts arrive only on the websocket. create_monitor_session returns a token; the client must open the socket itself.
> Market names in optimize must come from list_protocols for the same chain and token. Do not guess names.

# Monitor

> Subscribe to depeg, utilization, and liquidity alerts over a websocket. Partners connect with headers; anyone else buys a time window with x402 and connects with a session token.

```http theme={null}
WS wss://si.ampli.net/api/v1/monitor
```

The monitor checks your subscriptions every 60 seconds and pushes an event the first time a threshold is crossed. An alert is sent once and re-arms after the condition clears.

| Event | Fires when |
| :- | :- |
| `depeg` | A stablecoin is more than 3% from its peg |
| `utilization` | A market's utilization is above 95% |
| `liquidity` | A market has open borrows and no withdrawable liquidity |

## Connect

> [tab] Partner key
>
> Open the socket with the partner headers. There is no time limit.
>
> ```ts theme={null}
> const socket = new WebSocket("wss://si.ampli.net/api/v1/monitor", {
>   headers: { "X-Partner-Name": "your-partner-name", "X-Partner-API-Key": process.env.AMPLI_PARTNER_API_KEY },
> });
> ```

> [tab] x402 session
>
> A stream does not fit per-request payment, so you buy a window up front. Call `POST /monitor/sessions` (MCP tool: `create_monitor_session`) with the number of hours, from 1 to 24. It is priced per hour and paid with x402 like any other route.
>
> ```bash theme={null}
> curl -s https://si.ampli.net/api/v1/monitor/sessions \
>   -H "Content-Type: application/json" \
>   -H "PAYMENT-SIGNATURE: <base64 payment payload>" \
>   -d '{"hours": 6}'
> ```
>
> ```json theme={null}
> {
>   "token": "eyJ...",
>   "expires_at": "2026-11-12T22:00:00Z",
>   "payer": "0xPayerWallet",
>   "session_id": "6c1f...",
>   "subject": "x402:0xpayerwallet",
>   "hours": 6,
>   "websocket_url": "wss://si.ampli.net/api/v1/monitor",
>   "subscribe_message": {
>     "action": "subscribe",
>     "events": ["depeg", "utilization", "liquidity"],
>     "assets": [{ "chain_id": 8453, "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" }]
>   }
> }
> ```
>
> Connect to `websocket_url` with `Authorization: Bearer <token>`. Clients that cannot set headers can use `?access_token=<token>` instead, but the header keeps the token out of URLs and access logs.
>
> ```ts theme={null}
> const socket = new WebSocket(session.websocket_url, {
>   headers: { Authorization: `Bearer ${session.token}` },
> });
> ```

## Subscribe

After the socket opens, send a subscribe message. You can send more later to add assets, or `unsubscribe` to remove them.

```json theme={null}
{
  "action": "subscribe",
  "events": ["depeg", "utilization", "liquidity"],
  "assets": [
    { "chain_id": 8453, "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" },
    { "chain_id": 999, "address": "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb" }
  ]
}
```

* `assets` takes underlying tokens (every market for that token is watched) or single markets and vaults.
* `events` is optional. Leave it out to receive all three.
* The server answers `{"event": "subscribed", "assets": [...]}` and runs a first check straight away.

## Events

```json theme={null}
{
  "event": "utilization",
  "chain_id": 8453,
  "address": "0xedc817a28e8b93b03976fbd4a3ddbc9f7d176c22",
  "protocol": "moonwell",
  "utilization": 0.962,
  "threshold": 0.95
}
```

| Event | Fields besides `event` and `chain_id` |
| :- | :- |
| `depeg` | `address` (the token), `price`, `deviation`, `threshold` |
| `utilization` | `address` (the market), `protocol`, `utilization`, `threshold` |
| `liquidity` | `address` (the market), `protocol`, `total_supply`, `total_borrows`, `available_liquidity` in base units |

| Event | Meaning |
| :- | :- |
| `subscribed`, `unsubscribed` | Your current asset list |
| `depeg`, `utilization`, `liquidity` | A threshold was crossed |
| `error` | Your last message was invalid. The socket stays open |
| `session_expired` | The x402 window ended. The server closes with code `1008` right after |

A socket with an invalid token or partner key is closed with code `1008` straight away.

> [!TIP]
>
> **Renewing a window**
>
> Buy the next session before `expires_at`, open a second socket, subscribe, then close the old one. Nothing is missed and nothing is paid twice for the same hour.

> [!NOTE]
>
> The MCP tool `create_monitor_session` only issues the token. It does not hold the socket for you. Your agent or service must open the websocket and keep it open.


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