# Droplet.ai HTTP API

`POST https://ujtuxanqlzmhnrzijfoo.supabase.co/functions/v1/agent-api`

Authenticate with `Authorization: Bearer dp_…` (or a `"token"` field in the body). The body is JSON with an `action`. Responses are JSON. Errors are `{"error": "message"}` with status 400, 401, 403, 404, 409, 429 or 500.

Send `x-region: us-east-1` on every request. It runs the function next to the database and roughly halves latency (`get_events` about 0.98 s down to 0.55 s).

```bash
curl -s -X POST "https://ujtuxanqlzmhnrzijfoo.supabase.co/functions/v1/agent-api" \
  -H "Authorization: Bearer $DROPLET_TOKEN" \
  -H "Content-Type: application/json" \
  -H "x-region: us-east-1" \
  -d '{"action":"whoami"}'
```

The MCP tools are the same functions; their names are in [SKILL.md](../SKILL.md#4-tools-at-a-glance).

---

## Pairing

`/functions/v1/connect` (GET gives plain text for agents; POST with a JSON body gives JSON):

| Step | GET | POST body | Returns |
|---|---|---|---|
| Get a code | `?start=1&name=Claude%20Code` | `{"action":"start","name":"Claude Code"}` | `code` (like `K7QX-29PL`), `secret` (`dpw_…`, keep it), `expires_at`, `minutes` (15), `qr_url`, `app_link` |
| Wait for the user | `?wait=dpw_…` | `{"action":"wait","secret":"dpw_…"}` | waits up to 50 s: `{"status":"pending","expires_at"}`, or `{"status":"connected","token","name","mcp_url","api_url","guide","welcome"}` |
| QR image | `?qr=K7QX29PL` (`&format=text` for the terminal) | | a PNG that opens Droplet.ai with the code |
| Code shown in the app (older builds) | `?code=K7QX29PL&name=…` | `{"code","name"}` | `{"token","name","mcp_url","api_url","guide","welcome"}` |

The token is shown once. `welcome` is `{"widget_slug","request_id","approvals_request_id","next"}`: Droplet.ai's welcome widget, its first question ("What should I put on your Home Screen first?") and the approvals question ("When <agent> needs your OK, ask you here?", sent without a notification; the answer sets `approvals` in `whoami`). See SKILL.md, Your first session.

---

## Widgets

### whoami
→ `{"agent": "Claude Code", "kind": "agent", "approvals": "droplet" | "chat" | null, "approvals_means": "…", "your_widget": {"slug", "title"} | null, "your_widgets": [...], "slots": {"used", "max": null, "left": null}, "standing_orders": ["1. …", …]}`. `your_widget` is the widget to keep updating (with `placed`: the sizes the user put it on screen at, and `placed_means` in words); `standing_orders` is what to do on every task without being asked. `approvals` is where the user wants your approval requests and questions: `"droplet"` (send them with `ask`; they show on your widget), `"chat"` (ask in chat), or `null` (not answered yet: ask once). Only the approvals question Droplet.ai asks at pairing sets it. Call this first in every session. MCP: `droplet_whoami`.

### list_widgets
→ `{"widgets": [{"slug","title","subtitle","symbol","accent","theme","layout","blocks","variants","url","relevance","private","sizes","lock","agent_name","updated_at","mine"}]}`. Every widget on the user's Droplet.ai, from every agent, with the user's current ticks. `mine` is true for yours. Another connected agent's widget can't be changed or deleted by you (409); pick your own slug.

### library
`{"action":"library","query":"commute"}` → `{"templates":[{"id","title","category","tagline","uses"}]}`. `{"action":"library","id":"leave-by"}` → `{"template":{..., "widget", "guide"}, "how"}`. Droplet.ai's library of Agentic Widgets: start new widgets from a template and build on it with the user's real data (SKILL.md Process A). MCP: `droplet_library`.

Widgets the user sends you from the Library in the app arrive on `get_events` as `{"widget":"library","kind":"request","target":"<id>","value":{"template","title","mode":"replace"|"new","slug","note","widget","guide","how"}}` (SKILL.md Process H).

### set_widget
`{"action":"set_widget","slug":"build","title":"Build","symbol":"hammer.fill","blocks":[...]}`

Creates or updates the widget by slug. There's no limit on widgets per user (`slots.max` is null; a future plan limit would show there). **One widget per agent by default:** while you already have a widget, a new slug is refused (409) unless you send `"new_widget": true`, which you only do after the user asked for a separate widget and confirmed. Fields:

| Field | Notes |
|---|---|
| `slug` | Required (or a `title` to derive it from). Lowercased, other characters become dashes, up to 40 |
| `title` | 40. Defaults to the slug on a new widget |
| `reset_checklists` | `true` to untick every checklist item (a new day). Without it, items the user ticked stay ticked when you resend the list |
| `new_widget` | `true` only when the user asked for a separate, additional widget and you confirmed with them |
| `subtitle` | 60 |
| `symbol` | SF Symbol name |
| `accent` | `#RRGGBB` |
| `theme` | `{style: system|light|dark|glass|solid|gradient|image, color, colors, image, dim, font: default|rounded|serif|mono, text: auto|light|dark}`. `solid` needs `color`, `gradient` two `colors`, `image` an https `image` |
| `layout` | `auto`, `hero`, `grid`, `list` |
| `blocks` | Up to 8 (types below) |
| `variants` | Up to 6 `{when: {from, to, days, place}, title, subtitle, relevance, blocks}`. `from`/`to` are `"HH:MM"` (together, different; wraps past midnight when `from` > `to`, and then belongs to the day it started on), `days` `["mon",…]`, `place` a saved place name or `"away"`. Any other `when` key is rejected |
| `url` | Opened when the widget is tapped |
| `relevance` | Whole number 0 to 100, for the Smart Stack |
| `private` | `true` hides the content while the phone is locked |
| `sizes` | `{small, medium, large, extra_large}`, each a list of block indexes |
| `lock` | `{inline (40), circular (index), rectangular (index), symbol}`. `circular` must point at a gauge, progress, metric, clock, countdown or text block |

Every field you leave out keeps its old value, including `blocks` and `variants`; when you send `blocks` or `variants`, the whole list is replaced (`"variants": []` removes them). Send `null` to clear `subtitle`, `symbol`, `accent`, `theme`, `url`, `relevance`, `sizes` or `lock`. Unknown fields are dropped.

→ `{"ok": true, "widget": {...}, "check": {"showing_now", "sizes", "warnings", "notes"}, "hint"}`. `check.warnings` should be empty. When you create a second widget while you already have one, `hint` says so: unless the user asked for a separate widget, update the existing one instead (and delete the new one), and tell them which widget changed.

### preview_widget
`{"action":"preview_widget","slug":"build"}` for a saved widget, or the same fields as `set_widget` for a draft (a draft is anything with `blocks` or `variants`; nothing is saved). Optional `at` (`"07:30"`, today in the phone's time zone) and `place` (`"home"`, `"away"`) to see which version shows then. A draft gets the same checks as `set_widget` (including `sizes`, `lock` and `accent`), so one that previews will save.

→ `{"slug","draft","previewed_for","showing_now","sizes","warnings","notes"}`, fast, without drawing anything. Add `"raw": true` to get the PNG itself (`curl … -o preview.png`), or `"image": true` to add `png_base64` to the JSON.

### delete_widget
`{"action":"delete_widget","slug":"build"}` → `{"ok": true, "deleted": "build"}`. Also deletes any scheduled job that fills this widget, and drops taps still queued for it.

---

## Blocks

| type | fields |
|---|---|
| `text` | `text` (400), `style` (`title`, `body`, `caption`) |
| `metric` | `label` (40), `value` (24), `change` (16), `trend` (`up`, `down`, `flat`, `auto`) |
| `list` | `title` (40), `items` (up to 8 strings or `{title (140), detail (80), url (https only)}`) |
| `progress` | `label` (60), `value` (0 to 1, or 0 to 100) |
| `countdown` | `label` (40), `to` (ISO with offset), `from` (ISO before `to`, adds a bar), `style` (`relative`, `timer`, `date`, `time`) |
| `clock` | `label` (30), `timezone` (IANA), `digit_sum` |
| `gauge` | `label` (30), `value`, `min` (0), `max` (1, or 100 when value > 1), `text` (8), `style` (`ring`, `bar`) |
| `chart` | `label` (40), `values` (2 to 48 numbers), `value` (24), `change` (16), `trend`, `style` (`line`, `bar`, `area`) |
| `checklist` | `title` (40), `items` (up to 8 strings or `{title (80), done}`) |
| `buttons` | `items` (1 to 4 strings or `{label (24), id (30), symbol, url}`); without `url` a tap is an event |
| `image` | `url` (https picture), `fit` (`fill`, `fit`), `caption` (60), `link` (opened on tap) |
| `map` | `lat` (-90 to 90), `lon` (-180 to 180), `label` (40, the place's name), `span` (metres across, 100 to 50000, default 800). The phone draws an Apple Maps snapshot with a pin (Droplet.ai build 33 or later; older builds show nothing for it) |

Any block also takes `url` (opened on tap), `color` (hex) and `sensitive` (hidden while locked). Links may start with `https://`, `tel:`, `sms:`, `mailto:`, `facetime:`, `maps:`, `shortcuts://`, `music://`, `calshow:`, `x-apple-reminderkit://` or `droplet://`; app links like `uber://` are rejected (use the app's https link). Details: [references/blocks.md](../references/blocks.md).

---

## Taps

### get_events
`{"action":"get_events","slug":"habits","wait_seconds":50,"peek":false}` (all optional)

Waits up to `wait_seconds` (0 to 50, default 0) and returns the moment a tap lands, or `events: []` with a `hint`.

→ `{"events": [{"id","widget","kind":"button|check|answer","target","value","source":"widget|app|control","created_at"}]}`

- `target`: a button's `id`, a checklist item's title, or (for an answer) the question's `request_id`.
- `value`: `{"label"}` for a button; `{"done","block","item"}` (plus `"variant"`) for a tick; `{"answer","question","request_id"}` for an answer, whose `widget` is `"question"`.
- An answer you already read with `get_answer` is marked seen and doesn't come again here.
- Only taps on widgets this agent owns, and answers to its own questions. Each is returned once and marked seen (the button shows Seen), unless `peek: true`.

### set_webhook
`{"action":"set_webhook","url":"https://yourapp.example.com/droplet/tap"}` → `{"ok": true, "webhook", "secret": "lvs_…", "how"}`

- https and reachable from the internet (localhost and private addresses are rejected).
- Each tap, tick and answer is POSTed as `{"type":"widget_tap","event":{…same as get_events…}}` with `X-Droplet-Signature: sha256=<hex HMAC-SHA256 of the raw body>`.
- Answer 2xx within 6 s; otherwise Droplet.ai retries after 1.5 s and 4 s. A 2xx marks the tap Seen.
- The secret is shown once; a new `set_webhook` makes a new one. `{"url": null}` or `""` turns it off.

---

## Questions

### ask
`{"action":"ask","question":"Ship it?","details":"…","kind":"decision","options":["Ship","Wait"],"risk":"high"}`

`question` (140), `details` (600), `kind` (`decision`: 2 options, else Approve/Reject; `choice`: 2 to 4; `input`: free text with optional `default_answer`), `options` (up to 4, 40 each), `risk` (`low`, `medium`, `high`), `notify` (optional boolean).

The question shows on your own widget: while it's pending, each of your Home Screen widgets shows "<agent> asks" with the answer buttons, then goes back. It's also in the Droplet.ai app and the optional Questions widget. A notification is sent only when `risk` is `"high"`, `notify` is `true`, or the user has no Droplet.ai widget installed; `"notify": false` keeps it silent even when high risk.

→ `{"ok": true, "request_id": "…", "status": "pending", "shown_on": "…"}` at once (the MCP tool `droplet_ask` also waits for the answer). The answer also arrives as an event on `get_events` and the webhook (below).

### get_answer
`{"action":"get_answer","request_id":"…","wait_seconds":45}` (0 to 50, default 0 over HTTP)
→ `{"request_id","status":"pending|answered|cancelled","answer","answered_from":"app|widget","answered_at"}`, plus a `hint` while pending. `answer` may be the user's own words.

### list_requests
→ `{"pending": [...]}`, up to 20, from every agent.

### cancel_request
`{"action":"cancel_request","request_id":"…"}` → `{"ok": true, "cancelled": "…"}`

---

## The phone

### get_context (also get_phone_context)
`{"action":"get_context","fresh":false}`

→ `{"shared": true, "timezone", "local_time", "can", ...the fields the user shares..., "updated_at", "age_seconds"}`, plus `not_shared_with_you` when the user withheld fields from you. `{"shared": false, "hint"}` when sharing is off. `fresh: true` wakes the phone and waits up to 20 s for a new report. Every field is in [references/phone.md](../references/phone.md).

### phone_action
`{"action":"phone_action","kind":"alarm","params":{"time":"07:30","label":"Gym"},"wait_seconds":25}`

`kind`: `alarm`, `timer`, `cancel_alarm`, `reminder`, `cancel_reminder`, `event`, `cancel_event`, `notify`. Fields go in `params` (or at the top level). Only kinds allowed by `can` work. Waits up to `wait_seconds` (0 to 50, default 25) for the phone.

→ `{"action_id","kind","status":"done|failed|pending","summary","result","error","created_at","done_at","hint"}`. `result` per kind: alarm and timer `{alarm_id, label, rings_at}`, cancel_alarm `{cancelled}`, reminder `{reminder_id, list}`, cancel_reminder `{removed}`, event `{event_id, calendar}`, cancel_event `{removed}`, notify `{delivered_to}` or `{shows_at}`. Params per kind: [references/phone.md](../references/phone.md#kinds).

`notify`: at most 4 per agent per hour, counted when created, failed ones excluded (429 after).

### phone_action_status
`{"action":"phone_action_status","action_id":"…","wait_seconds":10}` → the same shape as `phone_action`. Without `action_id`: `{"actions": [...]}`, the 20 most recent.

---

## Scheduled jobs

### schedule
```json
{
  "action": "schedule",
  "name": "btc-price",
  "widget_slug": "crypto",
  "every_minutes": 15,
  "fetch": { "url": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_change=true" },
  "values": { "btc": "bitcoin.usd", "change": "bitcoin.usd_24h_change" },
  "widget": {
    "title": "Bitcoin",
    "symbol": "bitcoinsign.circle.fill",
    "blocks": [
      { "type": "metric", "label": "BTC", "value": "{{btc|money}}", "change": "{{change|percent}}" },
      { "type": "list", "items": ["24h: {{change|percent}}", "Updated {{now|time}}", "Source: CoinGecko"] }
    ],
    "sizes": { "small": [0] },
    "lock": { "circular": 0 }
  }
}
```

| Field | Notes |
|---|---|
| `name` | Required id; reuse it to change the job |
| `widget_slug` | Required. The widget it creates and keeps updated |
| `every_minutes` | 5 to 1440, default 15. Due jobs run every 5 minutes |
| `fetch` | `{url, format}`: an https GET, no custom headers, 10 s timeout, 1 MB. `format` `json`, `rss` or `text` (detected when left out) |
| `values` | `name: "path.to.value"`, or `name: {path, title, detail, url}` for a list (up to 8 rows). Required for JSON. RSS gives `title` and `items` (`title`, `url`); text gives `text` (first 400 characters, HTML not parsed) |
| `widget` | The template: any `set_widget` fields, with `{{name}}` in strings. Filters: `money` (`money:EUR`), `number`, `round:N`, `percent` (`percent:N`), `upper`, `time`. `{{now|time}}` is the run time. A string that is only `"{{list}}"` becomes the list. Missing values print `–` |
| `enabled` | `false` to pause |

Runs once at once and returns `{"ok", "job", "widget", "every_minutes", "first_run": {values, widget}, "check"}`. If the first run fails nothing is saved and you get the error. Later runs update only `title`, `subtitle`, `blocks`, `theme`, `layout` and `symbol`, and only when the title, subtitle or blocks changed. 20 jobs per user.

### test_job
Same body. Runs once, saves nothing: `{"ok": true, "values", "widget"}` or `{"ok": false, "error"}`.

### list_jobs
→ `{"jobs": [{"name","widget_slug","every_minutes","enabled","spec","agent_name","last_run_at","next_run_at","last_status","last_error","created_at"}]}`

### delete_job
`{"action":"delete_job","name":"btc-price"}` → `{"ok": true, "deleted": "btc-price"}`. The widget keeps its last content.

---

## MCP

`https://ujtuxanqlzmhnrzijfoo.supabase.co/functions/v1/mcp` speaks MCP over Streamable HTTP with JSON responses and no sessions (protocol versions 2024-11-05 to 2025-11-25). Send `Authorization: Bearer dp_…`, or put the token in the path: `/functions/v1/mcp/dp_…`. Add `x-region: us-east-1` there too:

```bash
claude mcp add --transport http --scope user droplet \
  https://ujtuxanqlzmhnrzijfoo.supabase.co/functions/v1/mcp \
  --header "Authorization: Bearer dp_YOUR_TOKEN" \
  --header "x-region: us-east-1"
```

`droplet_preview_widget` returns the picture as an image the model can see.
