# tidybird Agent API Reference (Public Integration Surface)

This file is the **public** API contract for external agents.

- Date: 2026-10-12
- Stability: `Stable for integrations`
- Scope: **only** `/api/v1/**`

## Base URL

- Local: `http://localhost:3000/api/v1`
- Production: `https://www.tidybird.io/api/v1`

## Authentication

Use an API key created in Account > API Access Tokens.
API keys require an expiration date (max 365 days from creation).

Headers (pick one):

- `Authorization: Bearer <api_key>`
- `x-api-key: <api_key>`

API keys are the only supported machine authentication. The `/oauth/*` routes and
the OAuth discovery documents are present but deliberately disabled — they return
`501` and `404`, and there is no plan to enable them for this deployment. Do not
build an authorization-code flow against them.

Available scopes:

- `plans:read`
- `plans:write`
- `plans:publish` (publish/reopen plans; grant explicitly)
- `shopping:read`
- `shopping:write`
- `photos:read`
- `photos:write`
- `inbox:read`
- `inbox:write`
- `meals:read`
- `meals:write`
- `meals:ai`

Existing keys do not gain new scopes automatically. Create a new key with the
needed permissions. A plan-management key does not grant shopping or photo
access. Photo operations require the household's Pro image-upload entitlement.
Agent-created/purchased/uploaded records use a null user actor rather than
impersonating a household member; photo activity records the API credential ID.

## Common Error Shape

```json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request body must be application/json",
    "details": null,
    "resolution": "Correct the request using the schema at /openapi.json, then retry."
  }
}
```

Common codes: `UNAUTHORIZED`, `FORBIDDEN`, `VALIDATION_ERROR`, `CONFLICT`, `NOT_FOUND`, `RATE_LIMITED`, `INTERNAL_SERVER_ERROR`.

## Rate Limits

- API endpoints are rate-limited per client/IP.
- Successful responses include `RateLimit-Policy` and `RateLimit` structured
  fields. Compatibility fields `RateLimit-Limit`, `RateLimit-Remaining`, and
  `RateLimit-Reset` are also returned.
- On limit, API returns `429 RATE_LIMITED` with `Retry-After`.

## Endpoints

### `GET /inbox`

- Scope: `inbox:read`
- Query:
  - `countOnly=1` (optional): returns only `{ count }`
  - `limit` (optional, positive integer, default `40`, capped at `200`)
- Response:
  - `{ count, items }` or `{ count }`

### `POST /inbox`

- Scope: `inbox:write`
- Body:
  - `description` (string, required, 1-280 characters)
  - `estimatedMinutes` (integer, optional, 1-1440)
- Response: `201 { item, count }`

### `GET /plans/week?anchorDate=YYYY-MM-DD`

- Scope: `plans:read`
- Query:
  - `anchorDate` (optional ISO date; defaults to today)
- Response:
  - `anchorDate`
  - `plannerWeekMode` (`mon_fri` | `mon_sun`)
  - `weekStartDate`
  - `weekEndDate`
  - `days[]` (`date`, `status`, `taskCount`, `planId`)

### `GET /plans/:date/tasks`

- Scope: `plans:read`
- Path:
  - `:date` ISO date (`YYYY-MM-DD`)
- Response:
  - `date`
  - `plan` (`null` when day has no plan)
  - `tasks` (`[]` when day has no plan)

### `POST /plans/:date/tasks`

- Scope: `plans:write`
- Path:
  - `:date` ISO date (`YYYY-MM-DD`)
- Behavior:
  - Auto creates/loads draft daily plan if missing.
  - Adds one task to that day.
- Body (one of):
  - `taskTemplateId` (string)
  - `quickTaskDescription` (string, 1-280 characters)
- Optional:
  - `estimatedMinutes` (integer, 1-1440, for quick tasks)
  - `assignedUserId` (string or `null`)
  - `checklistItems` (up to 40 strings, each 1-140 characters)
- Response: `201 { plan, task }`

### `DELETE /plans/:date/tasks/:taskId`

- Scope: `plans:write`
- Path:
  - `:date` ISO date (`YYYY-MM-DD`)
  - `:taskId` UUID
- Behavior:
  - Removes one task from a draft plan.
  - Normalizes remaining order.
- Response: `{ ok: true }`

### Planning lifecycle, shopping and photos

| Method | Path | Required scopes | Purpose |
|---|---|---|---|
| `POST` | `/plans/:date` | `plans:write` | Create/load a day; materialize matching routines on creation. |
| `GET` | `/plans/month?month=YYYY-MM` | `plans:read` | Read month overview, including forecast routine counts. |
| `POST` | `/plans/:date/publish` | `plans:publish` | Publish the day. |
| `POST` | `/plans/:date/edit` | `plans:publish` | Reopen a published day as a draft. |
| `PATCH` | `/plans/:date/tasks/:taskId` | `plans:write` | Edit draft task title, assignment or admin notes. |
| `PATCH` | `/plans/:date/tasks/reorder` | `plans:write` | Set the complete draft task order. |
| `POST` | `/plans/:date/tasks/:taskId/checklist` | `plans:write` | Append a checklist item to a draft or published task. |
| `DELETE` | `/inbox/:itemId` | `inbox:write` | Archive the inbox item. |
| `POST` | `/inbox/:itemId/plan` | `inbox:write` + `plans:write` | Promote the source inbox item into a day, including its photo. |
| `GET` | `/backlog` | `plans:read` | Read open tasks before a date. |
| `DELETE` | `/backlog/:taskId` | `plans:write` | Cancel an open backlog task. |
| `POST` | `/backlog/:taskId/plan` | `plans:write` | Reschedule open work to a later date, copying photos and checklist labels. |
| `GET` | `/shopping-list` | `shopping:read` | Read active and recent purchased items, plus category codes. |
| `POST` | `/shopping-list` | `shopping:write` | Add an active item. |
| `PATCH` | `/shopping-list/:itemId` | `shopping:write` | Edit, mark purchased or reactivate an item. |
| `POST` | `/shopping-list/plan` | `shopping:write` + `plans:write` | Schedule the active list as a shopping task. |
| `GET` | `/plans/:date/tasks/:taskId/attachments` | `photos:read` | Read task photos through temporary signed URLs. |
| `POST` | `/plans/:date/tasks/:taskId/attachments` | `photos:write` | Upload one photo to a draft or published task. |

All IDs are household-scoped UUIDs; the date/task pair must refer to the same
plan. Creating a day returns `201 { plan, created, seededTaskCount }`, or `200`
when it already exists. Publishing/reopening returns `{ plan }`. Task editing
and reordering follow the app's draft-only state rules. PATCH task fields:
`titleSnapshot` (1–280 characters), `assignedUserId` (UUID/null), `adminNotes`
(string/null, max 2000 characters; null/empty clears). Reorder accepts
`{ "taskIds": ["<uuid>", "<uuid>"] }` with every task exactly once.
Checklist append accepts `{ "label": "<1–140 characters>" }` and returns
`201 { taskId, checklistItems }`; it does not mark items completed.

Inbox/backlog promotion accepts `planDate`, optional `assignedUserId`, and
`createPlanIfMissing` (default true). Inbox promotion is atomic: repeating it
for the same destination returns the existing task (`200` rather than `201`);
planning an already-promoted item to a different day returns `409`. Backlog
rescheduling atomically cancels the old open task, creates the new task, copies
photos, and starts a fresh checklist from the original labels. Repeating a
completed backlog move returns `404` because the source is no longer open.
Backlog list/dismiss supports `beforeDate=YYYY-MM-DD` (default today); listing
also supports `limit` (default 40, range 1–200).

Shopping create accepts `name` (1–140 characters), optional `quantity` (positive
integer, max 2147483647; default 1), and optional `category` (a code returned by
GET; otherwise auto-classified). PATCH accepts any of those plus `status`
(`active`/`purchased`). GET optionally filters `status` and returns
`{ activeItems, purchasedItems, categories }` with up to 200 active and 100
recent purchased items. Scheduling accepts `description` (1–280 characters),
`planDate`, optional `assignedUserId`, and `createPlanIfMissing`. It returns
`201 { plan, task }`, requires at least one active item, and preserves the app's
one-open-shopping-task-per-household rule (`409` otherwise).

Photo POST uses `multipart/form-data` with one `file`. Supported types: JPEG,
PNG, WebP and AVIF, maximum 4 MiB per file (before and after sanitization) and 20 attachments per task. Images
are decoded and re-encoded to validate content and strip metadata. GET returns
`{ taskId, attachments }`; POST returns `201 { attachment }`. Storage object
keys and unsigned legacy thumbnail URLs are not exposed (`thumbnailUrl` is null).
URLs expire: fetch the photo list again when a URL expires.
Copying existing photos during inbox/backlog planning does not grant permission
to download or upload photos; those actions still require their dedicated scopes.

Routine configuration, task start/complete/reopen, checklist completion, people
management and meal onboarding remain outside these endpoint additions.
Use `/openapi.json` for the complete schemas and operation-level scope metadata.

### Meal catalog and planning

| Method | Path | Scope | Purpose |
|---|---|---|---|
| `GET` | `/meals/catalog` | `meals:read` | List the shared and household meal catalog. |
| `POST` | `/meals/catalog` | `meals:write` | Create a household meal. |
| `DELETE` | `/meals/catalog/:mealId` | `meals:write` | Delete a household meal. |
| `GET` | `/meals/plans/:weekStart` | `meals:read` | Read the meal plan for the ISO week containing `:weekStart`. |
| `POST` | `/meals/plans/:weekStart/entries` | `meals:write` | Add a lunch or dinner entry to the week. |
| `PATCH` | `/meals/plans/:weekStart/entries/:entryId` | `meals:write` | Replace an entry or edit its slot, type or notes. |
| `DELETE` | `/meals/plans/:weekStart/entries/:entryId` | `meals:write` | Remove a meal-plan entry. |
| `POST` | `/meals/plans/:weekStart/entries/:entryId/push-to-plan` | `meals:write` | Add the meal as a household task. |
| `POST` | `/meals/plans/:weekStart/generate` | `meals:ai` | Generate or regenerate unlocked meal slots with AI. |
| `POST` | `/meals/plans/:weekStart/analyze` | `meals:ai` | Analyze the week for variety and balance. |
| `POST` | `/meals/plans/:weekStart/entries/:entryId/suggestions` | `meals:ai` | Suggest replacements for one entry. |

Meal plan dates use `YYYY-MM-DD`. Write and AI requests use JSON with
`Content-Type: application/json`; see the canonical OpenAPI contract at
`https://www.tidybird.io/openapi.json` for request and response schemas.
Public meal input limits are 140 characters for meal names, 280 for short
descriptions and AI hints, 80 for cuisine/protein, and 500 for entry notes.

## cURL Examples

```bash
# List inbox items
curl -s \
  -H "Authorization: Bearer $tidybird_API_KEY" \
  "https://www.tidybird.io/api/v1/inbox?limit=20"

# Create inbox item
curl -s -X POST \
  -H "Authorization: Bearer $tidybird_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"description":"Clean terrace table"}' \
  "https://www.tidybird.io/api/v1/inbox"

# Get week overview
curl -s \
  -H "Authorization: Bearer $tidybird_API_KEY" \
  "https://www.tidybird.io/api/v1/plans/week?anchorDate=2026-03-20"

# Add task to a day (from library template)
curl -s -X POST \
  -H "Authorization: Bearer $tidybird_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"taskTemplateId":"<template_uuid>"}' \
  "https://www.tidybird.io/api/v1/plans/2026-03-20/tasks"

# List tasks for a day
curl -s \
  -H "Authorization: Bearer $tidybird_API_KEY" \
  "https://www.tidybird.io/api/v1/plans/2026-03-20/tasks"

# Delete task from a day
curl -s -X DELETE \
  -H "Authorization: Bearer $tidybird_API_KEY" \
  "https://www.tidybird.io/api/v1/plans/2026-03-20/tasks/<task_uuid>"
```

## Not Included Here

Internal endpoints such as `/api/admin/**`, `/api/ops/**`, `/api/billing/**`, `/api/me`, `/api/security/**` are intentionally excluded from this public agent contract.

### Request size and security audit limits

Planning lifecycle and shopping JSON mutations accept at most 64 KiB of UTF-8 body data. Photo multipart requests accept at most 4 MiB + 64 KiB in total and must contain exactly one `file` part with no other fields. Actual streamed bytes are counted before parsing; missing or inaccurate Content-Length does not bypass these limits. Oversized or malformed bodies return 422 without mutations. The 4 MiB photo cap leaves multipart overhead below Vercel’s 4.5 MB Function payload limit.

Planning lifecycle, shopping and photo operations emit structured machine audit records for mutations and authorization rejections, with operation, resource path, outcome, tenant and verified credential ID. Invalid credentials have no trusted identity. These use provider-owned application logs; raw keys, request bodies and URL query strings are excluded. Log transport failures do not change committed business outcomes. Publish/reopen and photo activity retain their existing durable audit records.
