# Open Brain — for agents

Open Brain (openbrain.run) is the search-first discovery and execution layer of Open Group. This file tells
automated agents what the public API really does today. The running contract is `/openapi.json`;
if this file and the contract ever disagree, trust the contract.

## Rules

- Public, non-adult product. Adult services are never searched, linked or integrated.
- Every public web search result is a real page with its URL and the time it was checked. Do not present
  Open Brain results as anything else, and do not invent results when the list is empty.
- Respect `429` responses: wait `retry_after_s` seconds before retrying.
- Send `Accept-Language: pt-PT`, `en` or `es`. Results are returned in that language.
- Send an `Idempotency-Key` header when you create a task, so a retry never creates a second one.
- Keep personal data out of public URLs and query strings. Use Brain Search on the signed-in app origin.

## Search (no account needed)

```bash
curl -s https://dev.openbrain.run/api/v1/search \
  -H 'content-type: application/json' -H 'accept-language: en' \
  -d '{"q":"rent apartments"}'
```

```json
{"scope":"open_group","results":[{"url":"https://openhome.fun/","title":"Open Home",
"snippet":"Find homes and apartments to buy or rent using a map-based property search.",
"fetched_at":"2026-11-21T06:38:55.000Z"}],"source":"open-group","fetched_at":"…","verified":true}
```

- `q`: 1–4000 characters. `scope`: `open_group` (default) or `web`.
- `scope: "web"` returns `404 capability_unavailable` while its gate is closed, and `503 capability_unavailable`
  if the gate is open but no provider is configured.
- A query that is plain arithmetic (for example `2+3*4`) also returns an exact `calculation`, without a model.

## Status

| Endpoint | Purpose |
|---|---|
| `GET /api/health` | Database, worker heartbeat, model configuration and Brain Search mode |
| `GET /api/ready` | `503` while the service drains for a release |
| `GET /api/revision` | Deployed commit SHA and build time |
| `GET /api/v1/capabilities` | `features`: each user journey (`search.open_group`, `search.tasks`, `model.text`, `account.passkey`…) with `available` or `unavailable`, whether it needs a session, its endpoints and, when closed, its gate and reason. `adapters`: provider status |
| `GET /api/v1/flags` | Public feature gates |

Check `features` before calling an endpoint: it is computed from the same conditions the routes check.

## Needs a signed-in session

`POST /api/v1/model`, `POST /api/v1/model/stream`, `GET|POST /api/v1/tasks`, `GET /api/v1/tasks/{id}`,
`POST /api/v1/tasks/{id}/cancel`, `POST /api/v1/auth/data-export`, `POST /api/v1/account/delete/options`
and `DELETE /api/v1/account` act for a signed-in person only. Without a session they return
`401 auth_required`. There are no API keys for third-party agents yet. The legacy `/api/v1/model*` endpoints are
deprecated (see `sunset` in capabilities); use live search and plans.

## Live search across Open Group apps (no account needed)

`GET /api/v1/search/live?q=casa%20lisboa&locale=pt-PT&limit=3` returns record cards from each live source app (today
Open Home, Open List and Open Party) with exact source links, per-source status and separate real and demo counts.
It never calls a model (`inference_calls: 0`). `GET /api/v1/search/live/connectors` lists sources and their status.

## Plans (signed-in)

`POST /api/v1/plans {"q":"bicicleta até 300€"}` turns a query into a comparison of real records and typed next
steps (save the shortlist, watch the search, add Open List favorites, save the search on Open List). Retrieval makes
no model call; an optional short summary may cite only records in the plan and carries its provenance (model and
effort). Run a step with `POST /api/v1/plans/{id}/steps/{step}/run`, an `Idempotency-Key` per action and the plan
`rev`; a step is `confirmed` only after Open Brain reads the result back from its destination. Open List steps need
the person to connect Open List (OAuth 2.1 + PKCE, scopes `account:read listings:manage`); they can disconnect at any
time. Full contract: `/openapi.json`.

## Brain Search

`GET /api/v1/brain/search` searches the signed-in account’s memories, ready captures and conversations. Pass `q` (1–400 characters), optional comma-separated `kinds` (`memory,capture,thread` by default), and `limit` (1–100, default 20). Check the `semantic_search` journey for route availability. Use the response’s `mode` to distinguish semantic and keyword results. The model runs on the app host, and account export excludes derived vectors.

## Capture

Check the `capture` journey in `GET /api/v1/capabilities`. Capture endpoints require a session. Mutations also require the canonical `Origin` and `X-OpenBrain-Auth: 1`.

- `POST /api/v1/captures` accepts JSON text or public HTTP(S) URLs, or multipart with `kind=file`, a single `file` and optional `title`. Uploads accept PDF, plain text, Markdown and image metadata up to 10 MiB. Send an `Idempotency-Key` when retrying creation.
- `GET /api/v1/captures` lists summaries and supports `q` and cursor paging. `GET /api/v1/captures/{id}` returns extracted text. `DELETE /api/v1/captures/{id}` removes the capture.
- `POST /api/v1/captures/{id}/suggest-memories` previews up to five unsaved suggestions. Check the capture's `status` and `error_code` for extraction results. Images record metadata and report `ocr_unavailable`.
- `POST /api/v1/captures/{id}/extract` and `POST /api/v1/captures/extract-image` turn a capture into search criteria with a confidence per field (deterministic first; a functional model only when needed). `PUT /api/v1/captures/{id}/extraction` corrects fields; the `effective_query` starts a plan.

## Errors

Every error uses one envelope:

```json
{"error":{"code":"capability_unavailable","message_key":"unavailable.search","details":{"gate":"G-WEBSEARCH-PROVIDER"}}}
```

## Not available yet

External web search, MCP, voice, API keys and SDKs.
They appear here and in `/openapi.json` only once they work.
