API reference · Monitoring

Set alert rules

PUT/v1/bots/{bot_id}/alerts

Alert on a missing heartbeat, a daily loss, drift from the test, or a halt, by email and a signed webhook. Members left out keep their value.

On this page

Auth. An account token (Authorization: Bearer lb_…) or a signed-in web session. A report-only token (lbr_…) is refused here with 403 scope_denied.

Limits. Counts against your plan's API requests (60, 600 or 3,000 a minute on Free, Builder and Standard).

Parameters

Path parameters

NameTypeRequiredDescription
bot_idstringyesThe bot id (bot_…).

Body

NameTypeRequiredDescription
heartbeat_missing_minintegernoAlert when no heartbeat arrives for this many minutes; null turns it off. 1 to 1440. Default 5.
daily_loss_usdnumbernoAlert when today's net P&L (since 00:00 UTC, marked) is at or below minus this many dollars; null turns it off. Up to 1,000,000,000.
driftobjectno{metric, threshold, min_fills}: alert when the live value of pnl_per_contract, fill_rate or fee_per_contract differs from the test by more than threshold, once min_fills live fills exist; null turns it off.
haltedbooleannoAlert when the bot reports a halt. Default true.
emailbooleannoSend alerts to your account's email. Default true.
webhook_urlstringnoAn https URL to POST alerts to; null removes it.
rotate_secretbooleannoMint a new webhook signing secret. Default false.

Request

Terminal
curl -X PUT "https://api.langbot.ai/v1/bots/bot_01M6G72RFQRQ8JGNG8T1447GGP/alerts" \
  -H "Authorization: Bearer $LANGBOT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"heartbeat_missing_min": 5, "daily_loss_usd": 50, "drift": {"metric": "pnl_per_contract", "threshold": 0.05, "min_fills": 30}, "webhook_url": "https://example.com/langbot-alerts"}'

Response

200 OK

JSON
{
  "rules": {
    "heartbeat_missing_min": 5,
    "daily_loss_usd": 50.0,
    "drift": {
      "metric": "pnl_per_contract",
      "min_fills": 30,
      "threshold": 0.05
    },
    "halted": true
  },
  "channels": {
    "email": {
      "enabled": true,
      "to": "docs-1163406543@example.com"
    },
    "webhook": {
      "url": "https://example.com/langbot-alerts",
      "secret_set": true
    }
  },
  "incidents": [],
  "webhook_secret": "…"
}

webhook_secret is returned once, when a webhook URL is first set or rotate_secret is true. Each alert is one incident: notified once when it opens and once when it resolves, never repeated while it lasts. A webhook is a POST of {"type": "bot.alert", "state": "open" | "resolved", "incident_id", "bot_id", "bot_name", "rule", "value", "threshold", "opened_at", "resolved_at", "ts"} with X-Langbot-Event: bot.alert and X-Langbot-Signature: sha256=<hex HMAC of the raw body with your secret>, signed like every Langbot webhook.

Errors

StatuscodeWhen
404not_foundNo bot with that id on your account (or it was deleted).
401auth_requiredNo token was sent.
401token_invalidThe token was not recognised (mistyped, revoked or expired).
422validation_errorA parameter failed validation; detail[].loc names it.
429rate_limitedOver your request budget; wait Retry-After seconds.

Every error body is {"detail": …, "code": "…"}; branch on code. All codes: Errors.