Brain API
What AirFone knows about the organization: objects, their history and how they connect.
The same operations are in the interactive API reference, and the whole contract is in the OpenAPI document.
GET/v1/brain/objects
List objects
Returns the objects in the organization's knowledge, alphabetically by name, a page at a time. An object is one thing the business has: a branch, a product, a doctor, a policy. Each row says how many current facts it has and when a fact was last recorded for it. Retired objects are not listed.
Filters combine with AND. kind takes a value from the types list. q matches part of a name, or the start of an alias, in any script, as written and normalised. source keeps objects that have at least one fact from that source: ingest:{connection id} for a connection AirFone syncs itself, or the name you chose when pushing records. changed_since (RFC 3339) keeps objects with a fact recorded at or after that time, which is how you pick up only what a sync changed.
Needs the brain:read scope. Page with cursor and limit; a limit outside 1 to 200 is clamped rather than refused, and a cursor that cannot be read is ignored, so the list starts again from the top. Check next rather than assuming a short page is the last. A changed_since that is not a timestamp is a 400.
A test key reads the sandbox's knowledge and a live key the live knowledge. Reading is free.
Scope brain:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
kind | query | string | No | Only objects of this kind, a value from `GET /v1/brain/types`. |
q | query | string | No | Name or alias, any script; matched as written and normalised. |
source | query | string | No | Only objects with a fact from this source key (`ingest:{id}`). |
changed_since | query | string | No | Only objects with a fact recorded since. |
cursor | query | string | No | The `next` of the previous page. Pass it back unchanged; never build one yourself. |
limit | query | integer | No | How many items to return, 1 to 200. 50 when left out. |
GET/v1/brain/objects/{id}
Get one object
Returns one object with its current facts. Each fact carries its provenance: which source it came from (ingest:{id} or a pushed source name), the record within that source, when it was received, and whether the raw original is archived so it can be read again. Link counts say how many links the object has per relation and direction; list the linked objects with the neighbours operation.
Only facts that are current now are returned. Facts that were replaced or retired are in the history operation. Staff-only facts appear only when the caller is an admin or a developer, for everyone else they are left out silently.
Needs the brain:read scope. An id that does not exist in this organization, or that belongs to a retired object, is a 404, never a 403. The response body is a free-form object in this contract because its facts vary by kind; the shape of one fact is Fact.
Scope brain:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
id | path | string | Yes | The resource id. |
GET/v1/brain/objects/{id}/history
List the facts an object used to have
Returns the facts about this object that no longer answer, newest first: values replaced by a newer record, facts closed by a rollback, and facts retired when their source was removed. Nothing is erased from the Brain, so this is how you see what the assistant used to say and why it changed.
relation narrows the list to one relation, such as opens_at, which gives the full story of a single value. Page with cursor and limit (1 to 200, 50 when left out; out of range values are clamped). Staff-only facts are included only for an admin or a developer.
Needs the brain:read scope. An id that matches no object gives an empty page, not a 404, so check the id with the object operation first if you need to tell the two apart. The direction parameter is accepted but has no effect here; it applies to the neighbours operation.
Scope brain:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
id | path | string | Yes | The resource id. |
relation | query | string | No | Only facts or links with this relation, such as `opens_at` or `sells`. The relations a business uses are listed by `GET /v1/knowledge/ontology`. |
direction | query | string | No | Neighbours only: `out` (default) or `in`. |
cursor | query | string | No | The `next` of the previous page. Pass it back unchanged; never build one yourself. |
limit | query | integer | No | How many items to return, 1 to 200. 50 when left out. |
GET/v1/brain/objects/{id}/neighbours
List the objects linked to an object
Returns the objects this one links to (out, the default) or the objects that link to it (in), a page at a time, ordered by relation. A branch links out to the products it sells; a product links in from every branch that sells it. Each item names the link (relation), the direction, the linked object and the edge id. Only current links to objects that are not retired are shown.
relation limits the list to one kind of link. Any direction other than in is treated as out. Page with cursor and limit (1 to 200, 50 when left out; out of range values are clamped).
Needs the brain:read scope. An id that matches no object gives an empty page, not a 404. To follow a path across several objects, call this once per hop; there is no graph query.
Scope brain:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
id | path | string | Yes | The resource id. |
relation | query | string | No | Only facts or links with this relation, such as `opens_at` or `sells`. The relations a business uses are listed by `GET /v1/knowledge/ontology`. |
direction | query | string | No | Neighbours only: `out` (default) or `in`. |
cursor | query | string | No | The `next` of the previous page. Pass it back unchanged; never build one yourself. |
limit | query | integer | No | How many items to return, 1 to 200. 50 when left out. |
GET/v1/brain/spans
Get the source text of a fact
Returns the exact passages a synced fact was read from, so a person can see why the assistant believes something. Take provenance.source and provenance.record from a fact and pass them as source and record.
A span is either a spreadsheet row (location is {tab, row}) or a stretch of a page or document (location is {start, end}). The list is empty, not a 404, when the record has no stored spans. Facts you pushed yourself have none, because the record you sent is the original.
Needs the brain:read scope. Both parameters are required; a missing one is a
- Text from staff-only passages is returned only to an admin or a
developer. Reading is free and changes nothing.
Scope brain:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
source | query | string | Yes | A fact's `provenance.source` (`ingest:{id}`). |
record | query | string | Yes | A fact's `provenance.record`. |
GET/v1/brain/types
List the kinds of objects
Returns every kind of object the organization's knowledge holds, such as branch or product, with how many current objects of each kind exist. The kind with the most objects comes first. Use it to build a filter for the object list, or to check that a sync produced the shapes you expected.
Needs the brain:read scope. A restricted key without it is refused with 403; a secret key, or a signed-in person, may always call it. The answer is not paged: an organization has tens of kinds, not thousands.
A test key reads the sandbox's knowledge and a live key reads the live knowledge; the two never mix. Reading is free.
Scope brain:read. Accepts: API key or personal access token. Open in the API reference