> ## Documentation Index
> Fetch the complete documentation index at: https://docs.headwaters.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# States

> A state your agent builds and Faces keeps and watches: your premises with their status and what they depend on, and the decisions faces made, each kept with what it rests on.

# States

A **state** is something your agent builds and Faces keeps and watches. It holds your
**premises** (named facts your agent declares, each with a status and what it depends on),
the **decisions** faces made, the faces' replies, and your own messages, linked by what rests
on what. It is not a message log.

When a premise is invalidated, everything that depends on it is too, and the response lists
each status that changed in `status_changes`. When a premise's value changes,
`decisions_made_under_old_values` lists the decisions that rested on the old value. You can
read a state back and page through it at any time. A face's cause is the one thing kept on the
server and never returned: the state keeps it so the face's later turns build on it.

Hand a state to [choices](https://docs.headwaters.ai/guides/choices.md) as `state_id` to have a face propose options
for the situation it describes.

A [chat](https://docs.headwaters.ai/guides/chat.md) or [decision](https://docs.headwaters.ai/guides/decisions.md) request joins a state with
`"conversation": "<id>"`. Send only what is
new on each turn: the state is put in front of it for you, and what a face decided is never
taken from the request, so it cannot be rewritten. Entries are **items** in OpenAI's Responses item
format.

Not to be confused with the `state` field of a [decision](https://docs.headwaters.ai/guides/decisions.md) request, which
describes the situation being decided.

> [!NOTE]
>
> States were called conversations, and before that sessions. `/v1/conversations` still works
> as a deprecated alias of `/v1/states`: it answers with the old object names (`conversation`,
> `conversation.deleted`) and the headers `Deprecation: true` and
> `Link: </v1/states/...>; rel="successor-version"`. It will be removed. `/v1/sessions` also
> still works. The `conversation` request field, and its older name `session`, are unchanged.

## Create a state

```bash theme={null}
curl -X POST https://api.faces.sh/v1/states \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```json theme={null}
{"object": "state", "id": "fs_STATE_ID", "model": null, "turns": 0, "items": 0,
 "causes_visible": true, "status": "open",
 "created_at": "2026-10-28T15:47:11+00:00", "last_used_at": "2026-10-28T15:47:11+00:00",
 "expires_at": "2026-11-27T15:47:11+00:00"}
```

All fields are optional:

| Field | Meaning |
| - | - |
| `model` | A face, alone: `@alice`, `@owner~alias`, or a composite (`(@alice \| @bob)`). No maestro is needed (`@alice:maestro-1` is the same face), and a downstream model is a `422`. The state then takes that face only, and echoes it as `model`. Left out, it takes any of your faces. |
| `causes_visible` | Whether a face's steering reads the other faces' causes. Default `true`. |
| `items` | The first items: your messages and premises (see [Add items](#add-items)). |
| `premises` | The first premises, alone or beside `items`, as on [Add items](#add-items). |

Any other field is a `422` that names it.

## A state as a proof

A state can also be built as a proof in progress: a tree of premises joined by AND and OR. Each
premise is proved `[x]`, open `[ ]` or refuted `[-]`, and the state ends with a line that names
what still stands between you and a proved goal. Writing and reading this way is free, and every
write answers with that line.

### Add a premise

`POST /v1/states/{state_id}/premises` adds one premise. It is a `409` if the key exists.

```bash theme={null}
curl -X POST https://api.faces.sh/v1/states/fs_STATE_ID/premises \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "the dinner is planned", "value": "A dinner party for six", "role": "goal",
       "said": "Plan a dinner party for six."}'
```

```json theme={null}
{"object": "state.reply", "result": "Added the goal \"the dinner is planned\".",
 "summary": ["Open. Proved when 1 is refined."],
 "text": "Added the goal \"the dinner is planned\".\n\nOpen. Proved when 1 is refined.",
 "premise": {"number": "1", "key": "the dinner is planned", "value": "A dinner party for six",
             "role": "goal", "origin": "human", "truth": "open", "children": [], "...": "..."}}
```

`result` says what changed, `summary` is the proof's last line, `text` is both, and `premise` is
the premise as `format=json` returns it.

| Field | Meaning |
| - | - |
| `key` | Its name: plain text, 1 to 120 characters. Every other request names it by this key. |
| `value` | What it says. |
| `role` | `goal` or `test`. Left out, it is a fact. |
| `and` / `or` | The premise it sits under. `and`: it must hold, with its siblings. `or`: it is one candidate, and one proved candidate is enough. A premise takes children of one kind only. |
| `on` | The premises it reads, as a list of keys. Reading is not sitting under: it does not change what proves the premises it reads. |
| `said` | The human's own words it comes from. A premise the human stated is true because they said it. |
| `origin` | Who it comes from: `human`, `agent`, `tool` or `web`. |
| `status` | `stated`, `verified`, `assumed`, `unresolved` or `invalidated`. |
| `await` | What it waits on: `human`, `environment`, or a test's key. |
| `description` | What it is, in a line. |
| `as` | Who writes it, for a branch someone has claimed (see [Several agents](#several-agents-on-one-proof)). |

### Change a premise

`PATCH /v1/states/{state_id}/premises` changes only the fields it is given. A test's run is a
status with the candidate it ran on (`tested`) and what it showed (`evidence`). A failed run
refutes that candidate, and the next one is the one to try:

```bash theme={null}
curl -X PATCH https://api.faces.sh/v1/states/fs_STATE_ID/premises \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "everyone can eat it", "status": "invalidated", "tested": "pie and mash",
       "evidence": "the pie has chicken"}'
```

```json theme={null}
{"object": "state.reply",
 "text": "Edited \"everyone can eat it\": set its status to invalidated, recorded its run on \"pie and mash\" (failed) and recorded the run's evidence.\n\nOpen. Next to try: 1.2.1. Proved when 1.3 passes on 1.2.1."}
```

It also takes `value`, `to` (a new key; everything that named the old one follows), `description`,
`await` (`none` clears it), `note`, `on`, `said`, `as`, and `refinement`. A premise with children
is proved only once its `refinement` is `complete`: its children are all it needs. Set by hand,
the proof says so on that premise's line, `(marked complete by hand)`, and after its last line.
A tool that checked the children sends `refined_by` with it (`refine` or `choices`), and the
proof says nothing more.

### Read the proof

`GET /v1/states/{state_id}/proof` returns the tree and its last line:

```text theme={null}
[x] 1 the dinner is planned  AND
[x]   1.1 the guests (axiom)
[x]   1.2 the menu  OR
[x]     1.2.1 curry and rice
[-]     1.2.2 pie and mash
[x]   1.3 test: everyone can eat it (passed on 1.2.1, failed on 1.2.2)

Proved.
```

`format=json` returns each premise's fields instead, `format=problog` the proof as a ProbLog
program, and `format=dot` as a Graphviz graph. `query=` lists the premises closest in meaning to
a question, best first. `GET /v1/states/{state_id}/premise?key=...` returns one premise and its
branch (`depth=`, or `up=true` for the premises it sits under), then every message linked to it.
`POST /v1/states/{state_id}/note` with `key` and `text` links a message to a premise.
`DELETE /v1/states/{state_id}/premises?key=...` removes one premise and its edges.

### Several agents on one proof

`POST /v1/states/{state_id}/claim` with `key` and `agent` gives that premise and everything under
it to one agent, for `ttl_seconds` (default 1800). A write into the branch by anyone else is a
`409`:

```json theme={null}
{"object": "state.reply",
 "error": "Not written: \"the menu\" is claimed by builder-A until 20:28, and this write is by no one named (`as`)",
 "text": "Not written: \"the menu\" is claimed by builder-A until 20:28, and this write is by no one named (`as`)"}
```

The agent writes with `as`. `POST /v1/states/{state_id}/release` with `key` releases it, and
`POST /v1/states/{state_id}/release-session` with `session` releases every claim taken in that
session (writes name their session in the `X-Headwaters-Session` header).

## Take a turn

Add `"conversation": "<id>"` to a request with a face on [chat](https://docs.headwaters.ai/guides/chat.md)
(`/v1/chat/completions`, `/v1/responses`, `/v1/messages`) or [decisions](https://docs.headwaters.ai/guides/decisions.md)
(`/v1/decisions`, `/v1/systemone`). Send only what is new.

```json theme={null}
{"model": "@alice:maestro-1/jev-latest", "conversation": "fs_STATE_ID",
 "depends_on": ["can_afford_rent"],
 "input": "Decide about the lease.",
 "questions": [{"type": "predicate", "name": "move",
                "instructions": "Move the shop to a cheaper street before March?"}]}
```

The face reads the state so far, then your request, and the turn is added to the state. Each
turn is billed as it would be without a state. See [Decisions in a state](#decisions-in-a-state).

[Choices](https://docs.headwaters.ai/guides/choices.md) reads a state, with `state_id`. With a question, it adds the options
it proposes to the state (see [Options in a state](#options-in-a-state)). Prose sent beside the
`state_id` is read for that one call and never saved: write anything that should persist as
premises with [Add items](#add-items).

## Items

Each entry is an item, in OpenAI's Responses item format, with an `id` (`ci_1`, `ci_2`, ...)
in the order it was added.

**A message.** Yours have `role: user`. A face's reply on chat has `role: assistant`, the
face's `name`, the `model` that answered and `shown`, the items it read.

```json theme={null}
{"id": "ci_7", "type": "message", "role": "assistant", "name": "alice",
 "model": "gpt-5.4-mini-2026-03-17", "shown": ["ci_3", "ci_4"],
 "content": "Yes, 40k fits under the 50k budget."}
```

**A decision.** One item of type `decision`, in the same shape whichever route asked it
(`source` says which: `decisions` or `systemone`). The `question` has its `name`, `type`
(`predicate`, `choice` or `score`), `instructions` and `options`; the `answer` has the `result`
(the probability for a predicate, the chosen value for a choice, the number for a score), the
`probabilities` and the `confidence`. It also carries the `face`, the decision `model`, the
`depends_on` it declared, and its `status`. Its `call_id` is the
decision's id.

```json theme={null}
{"id": "ci_4", "type": "decision", "call_id": "dec_CALL_ID", "source": "decisions",
 "face": "alice", "model": "jev-1.14.0",
 "question": {"name": "planner", "type": "choice", "instructions": "Hire an outside planner?",
              "options": [{"value": "yes"}, {"value": "no"}]},
 "answer": {"result": "no", "confidence": 0.68,
            "probabilities": [{"value": "yes", "probability": 0.16}, {"value": "no", "probability": 0.84}]}}
```

A state that holds decisions made before 29 October 2026 shows each of those as a
`function_call` named `decision` and its `function_call_output`, until it expires.

**A face's tool call.** A state may hold a face's tool calls from chat turns: each a
`function_call` naming the `face` and the `model`, and its `function_call_output`.

```json theme={null}
{"id": "ci_3", "type": "function_call", "name": "get_weather", "call_id": "call_CALL_ID",
 "arguments": "{\"city\":\"Lisbon\"}", "face": "alice", "model": "MODEL"}
{"id": "ci_4", "type": "function_call_output", "call_id": "call_CALL_ID", "output": "18C and sunny"}
```

**A premise.** A `function_call` named `premise` holding the `key`, and its
`function_call_output` holding the `value`, its `description`, and the `status` and
`depends_on` you set.

```json theme={null}
{"id": "ci_2", "type": "function_call", "name": "premise", "call_id": "prem_CALL_ID",
 "arguments": "{\"key\": \"vendor_certified\"}"}
{"id": "ci_3", "type": "function_call_output", "call_id": "prem_CALL_ID",
 "output": "{\"value\": true, \"description\": \"the vendor holds a SOC 2 report\"}"}
```

Only you add messages with `role: user` and premises. A face's replies, decisions and tool
calls are added by the turns that produce them.

## Premises

A premise is a fact your agent's decisions depend on, named by a `key`, with a `value` and a plain `description`. The description is required
the first time a key is used, and kept after that.

A key is plain text of 1 to 120 characters on one line, such as `costs under $100?` or
`Resolve "can eat"`. Spaces, quotes and punctuation are kept as written, and spaces at
either end are trimmed. A key cannot hold control characters (a tab or a newline among them),
line or paragraph separators, or the characters that reverse the direction of text. Name a
key in `depends_on` exactly as you wrote it.

| Field | Meaning |
| - | - |
| `key` | **Required.** The premise's name. |
| `value` | Its value: any JSON. |
| `description` | What it means, in plain words. Required the first time the key is used. |
| `status` | How sure your agent is of it: `stated` (the default), `verified`, `assumed`, `unresolved` or `invalidated`. |
| `depends_on` | What it rests on: premise keys, decision ids and option ids, at most 200, each already in the state or sent in the same request. Each entry is a plain id or an edge with a kind and a weight (see [And, or and weights](#and-or-and-weights)). A premise cannot depend on itself. See [Options in a state](#options-in-a-state). |
| `role` | `goal` marks the premise as a goal: the outcome the state is working toward. `test` marks a check that must pass. Optional. `wanted` is a deprecated name for `goal`, stored as `goal`, and is removed by 2026-12-31. |
| `touches` | What working on it touches: a list of at most 20 resources in plain text, such as a repository or a file. Two premises that touch the same resource are not given to two agents at once (see [Several agents](#several-agents)). Optional. |
| `origin` | Who set the premise: `human`, `agent`, `tool` or `web`. Optional. Use it to keep the user's goals and rules apart from your agent's own findings. |

Send premises with a turn as `premises`, a list of these, or add them on their own (see
[Add items](#add-items)).

A newer reading of a key replaces it from that point on. A newer reading without
`depends_on` keeps the earlier one; `[]` clears it. A newer reading without `role`,
`origin` or `touches` keeps the earlier one too; `null` clears it. Any other value is a `422`.
`role`, `origin` and `touches` are kept with the state and returned when you read it; they do
not change what a face is shown. A `goal` premise marks an outcome your agent works toward,
for it to know when to stop. To have a face read a premise, name it in the call's `depends_on`
(see [What a face is shown](#what-a-face-is-shown)). Every decision
is made with the premises in force when it was made, and the state keeps each reading, so you can always see what a
decision was made under.

## And, or and weights

`A depends_on B` means B must be true for A to be true. Each entry of a premise's
`depends_on` is a plain id or an edge:

```json theme={null}
{"key": "handle bad input", "value": "malformed files are handled", "depends_on": [
  {"id": "reject malformed files", "kind": "or", "p": 0.7},
  {"id": "repair malformed files", "kind": "or", "p": 0.3},
  {"id": "keep the parser fast", "kind": "and", "p": 0.5, "decision": "dec_DECISION_ID"},
  "tests pass"]}
```

| Field | Meaning |
| - | - |
| `id` | **Required.** What it rests on, as in a plain entry. |
| `kind` | **Required.** `and`: a child that must hold. `or`: one of the premise's alternatives, the readings of an ambiguity or the ways to do something, one of which holds. |
| `p` | Optional, 0 to 1. For an `and` edge, how much the child matters. For an `or` edge, its probability: one premise's `or` weights sum to 1. |
| `decision` | Optional: the decision that set `p`, a decision id in the state. |
| `why` | Optional: your note on the weight, up to 2,000 characters. |

A plain id is an `and` edge with no weight. One premise's `or` weights that do not sum to 1
are kept, and the write answers with `warnings` naming them. Support runs one way: a write
whose `depends_on` would make a loop between premises is a `422`.

To confirm a reading, write the premise again with the weights you mean, such as `p: 1` for
the confirmed alternative and `p: 0` for the rest. The new weights apply from then on, and the
earlier readings keep theirs. [Choices](https://docs.headwaters.ai/guides/choices.md#options-as-premises) can propose the
alternatives, and [decisions](https://docs.headwaters.ai/guides/decisions.md#weigh-a-premise) can weigh them. The weights do
not change what a face is shown.

## Status

Each premise has the status your agent gave it, and each decision is `decided`. What you read
back is the **effective** status: `invalidated` when the item's own status is, when anything
it rests on through a plain id or an `and` edge is invalidated, or when every one of its `or`
alternatives is, directly or through other items; otherwise its own. Only `invalidated`
spreads. An item that declared no `depends_on` does not depend on anything.

Set an invalidated premise to another status and what depended on it is restored, unless it
still depends on something else that is invalidated.

A write answers with `status_changes`: every effective status that changed, and why:

```bash theme={null}
curl -X POST https://api.faces.sh/v1/states/fs_STATE_ID/items \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"premises": [{"key": "rent_rises", "value": "no rise this year", "status": "invalidated"}]}'
```

```json theme={null}
{"object": "list", "data": [ … ],
 "premises": {
   "chain_opened": {"value": true, "description": "a national chain opened a bakery across the street",
                    "status": "verified"},
   "rent_rises": {"value": "no rise this year", "description": "the landlord says rent goes up 12% in March",
                  "status": "invalidated"},
   "can_afford_rent": {"value": false, "description": "the shop cannot carry the higher rent at current sales",
                       "status": "invalidated", "asserted_status": "stated", "because": "rent_rises",
                       "depends_on": ["rent_rises"]}},
 "decisions_made_under_old_values": [],
 "status_changes": [
   {"kind": "premise", "key": "rent_rises", "from": "assumed", "to": "invalidated", "because": null},
   {"kind": "premise", "key": "can_afford_rent", "from": "stated", "to": "invalidated", "because": "rent_rises"},
   {"kind": "decision", "id": "dec_DECISION_ID", "from": "decided", "to": "invalidated", "because": "can_afford_rent"}]}
```

| Field | Meaning |
| - | - |
| `status` | The effective status. |
| `asserted_status` | The status your agent set, shown when it differs from `status`. |
| `because` | What invalidated it, when that was something it depends on. |
| `depends_on` | What it rests on, as declared: plain ids, and edges with their `kind`, `p` and `decision`. |
| `role` | `goal` when it is a goal, `test` when it is a check. Left out when none is set. |
| `face` | The face that proposed it, for an option written in with [choices](https://docs.headwaters.ai/guides/choices.md#options-as-premises). |
| `reason` | Why its status was set for you: an alternative a [weighing](https://docs.headwaters.ai/guides/decisions.md#weigh-a-premise) set aside. |
| `origin` | Who set it, as declared. Left out when none is set. |

A decision item carries `status` (`decided` or `invalidated`) and `because` the same way.

## Options in a state

Ask [choices](https://docs.headwaters.ai/guides/choices.md) a question with `state_id` and the options it proposes are added
to the state as one item. The response gives each option an `id` (`opt_...`) and the list its
own, `choices_item` (`cho_...`).

A premise or a decision names an option in its `depends_on`, like a premise key or a decision
id. A list's `choices_item` names all of its options. A decision that rests on an option,
directly or through the premises and decisions it rests on, is shown why the face proposed it.
Options have no status: resting on one never invalidates anything.

```json theme={null}
{"premises": [{"key": "plan", "value": "Hold the price and sell on quality",
               "description": "the way the shop chose", "depends_on": ["opt_OPTION_ID"]}]}
```

## Add items

`POST /v1/states/{state_id}/items` adds your messages and premises, at most 20
at a time, as `items` (a premise may be written `{key, value, description}`), as `premises`, or both.
Both are one write, `items` first, checked together: if anything in it is invalid, the write
is a `422` and nothing is written.

```bash theme={null}
curl -X POST https://api.faces.sh/v1/states/fs_STATE_ID/items \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"premises": [{"key": "vendor_certified", "value": false}]}'
```

```json theme={null}
{"object": "list", "data": [{"id": "ci_11", "type": "function_call", "name": "premise", …},
                            {"id": "ci_12", "type": "function_call_output", …}],
 "first_id": "ci_11", "last_id": "ci_12", "has_more": false,
 "premises": {"vendor_certified": {"value": false, "status": "stated",
                                   "description": "the vendor holds a SOC 2 report"},
              "budget_usd": {"value": 50000, "status": "stated",
                             "description": "the most we can spend this year"}},
 "decisions_made_under_old_values": [
   {"call_id": "dec_CALL_ID", "question": {"id": "sign", "instructions": "Sign the contract?", …},
    "choice": "no", "face": "alice", "via": null,
    "changed": {"vendor_certified": {"was": true, "now": false}}}],
 "status_changes": []}
```

`premises` is each key's current reading, with its [status](#status). `status_changes`
lists every effective status the write changed. `decisions_made_under_old_values` lists
every earlier decision that rested on a key whose value you just changed: the keys it
declared in `depends_on`, or every premise in force when it was made if it declared none,
and any decision resting on one of those, with `via` naming the decision that reached it.
Your agent decides which to revisit. Nothing is decided again for you.

## Decisions in a state

A decision request in a state may send `depends_on`: the premise keys, decision ids and option
ids the decision rests on, at most 200, each already in the state or sent as a premise in the same
request. The decision is shown those premises and decisions, in full, with the premises each
of them directly depends on, and is invalidated when one of them is. Without `depends_on`, it
rests on every premise in force when it is made.

## What a face is shown

When a face reads a state, for [choices](https://docs.headwaters.ai/guides/choices.md#a-state-as-the-situation) or a
decision, it is shown:

* **What the call names in `depends_on`**, and the premises each of those directly depends
  on, always and in full, however many premises the state holds, up to about 60,000
  characters in all. Past that, the rest are shown like any other premise.
* **The premises the state rests on most**: those the most other items depend on.
* **The premises closest to the question**, and what they depend on.

Other premises are not shown, and a premise shown without being named is cut to its first
few hundred characters. A premise's `role` never changes what a face is
shown, and neither does the wording of the question: to make sure a face reads a premise,
name it in `depends_on`.

The response adds `decision_ids`, each question's decision id, to name in a later
`depends_on`, and `decisions_reopened`, the decisions the premises sent with it put in
question:

```json theme={null}
{"object": "decision", "model": "@alice:maestro-1/jev-latest",
 "answers": [{"type": "predicate", "name": "move", "probability": 0.36}],
 "decision_ids": {"move": "dec_DECISION_ID"},
 "decisions_reopened": [],
 "answered_by": "jev-1.14.0",
 "usage": {"input_tokens": 1685, "output_tokens": 279}}
```

## Several faces

A state opened without `model` takes any of your faces, each turn naming its face in
`model`. Each face reads its own replies as its own, and the others' as someone else's,
labelled with their name. Its steering reads their causes too, unless `causes_visible` is
`false` on the state or on the turn.

## What to do next

`GET /v1/states/{state_id}/synopsis` reads the state as work to do. Add `?since=ci_N` to list
what was written after item `ci_N`. `GET /v1/states/{state_id}/items?synopsis=1` returns the
same, as `synopsis`, beside the items.

A premise is **achieved** when it is verified, or when it rests on other premises, each of
its `and` children is achieved, and the alternative its `or` split is committed to is achieved.
An `or` split is committed to the alternative a human stated (`origin: human`), or to a clear
winner (`p` of at least 0.6, ahead of the next by at least 0.2), or to the only alternative
still standing.

```json theme={null}
{"object": "state.synopsis", "id": "fs_STATE_ID", "done": false,
 "goals": [{"key": "task", "status": "stated", "achieved": false}],
 "next": "task",
 "frontier": [
   {"key": "tests pass", "action": "test", "reason": "run the test", "weight": 1.0,
    "path": ["task", "tests pass"]},
   {"key": "handle bad input", "action": "decide", "reason": "an `or` split with no weights: weigh it",
    "weight": 0.5, "path": ["task", "handle bad input"],
    "alternatives": ["reject malformed files", "repair malformed files"]}],
 "ready": [ … ], "groups": [ … ], "claims": [],
 "outline": "stated task [goal]\n  stated (and) tests pass [test]\n  stated (and) handle bad input\n …",
 "text": "Next goal: task.\n- test tests pass: run the test [weight 1]\n …"}
```

| Field | Meaning |
| - | - |
| `done` | `true` when every goal premise that is not invalidated is achieved, and there is at least one. |
| `goals` | Each goal premise, with its status and whether it is achieved. |
| `next` | The first goal premise not yet achieved whose goal premises under it, other than invalidated ones, all are. A goal premise set `invalidated` is never `next`, and nothing under it is in `frontier` or `ready`. |
| `frontier` | What blocks `next`, heaviest first. Each item has its `action`: `test` (a check to write, run or fix), `decide` (an `or` split with no weights), `ask` (an `or` split with no clear winner: ask the person), `expand` (too vague to check, or needed and invalidated) or `reopen` (options or weights made before a premise they read changed). `weight` is the product of the shares along `path`, a share being a weight that was set, renormalised among its siblings, or an equal share where none was. |
| `changed` | With `since`: the items written after it. |
| `outline` | The support tree under each goal premise, invalidated ones included, one line per premise: its status, the kind and weight of the edge into it, its key. |
| `text` | `next`, `frontier` and `changed` in at most 1,500 characters, to read at the start of a session. |

## Several agents

The synopsis also gives the work for several agents at once:

| Field | Meaning |
| - | - |
| `ready` | Every frontier item, across every goal premise whose goal premises under it are achieved, each with the `goals` it serves. Invalidated goal premises, and what is under them, are left out, as is an item another agent has claimed. |
| `groups` | The ready items in groups: take one item from each group and run them at once. Two items share a group when one rests on the other, when they rest on a premise in common that is not verified, or when they share a `touches`. |
| `claims` | Who holds which premise, since when and until when. |

An agent claims an item before it starts:

```bash theme={null}
curl -X POST https://api.faces.sh/v1/states/fs_STATE_ID/claims \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "tests pass", "agent": "worker-1", "ttl_seconds": 1800}'
```

```json theme={null}
{"object": "claim", "id": "clm_CLAIM_ID", "key": "tests pass", "agent": "worker-1",
 "since": "2026-11-21T22:40:00+00:00", "expires_at": "2026-11-21T23:10:00+00:00"}
```

`ttl_seconds` is 1 to 86,400, 900 by default. A claim holds until it expires, until it is
released with `DELETE /v1/states/{state_id}/claims/{claim_id}`, or until the premise's status
changes. While it holds, another agent's claim on the same premise is a `409`; the same agent
claiming again renews it.

## Read a state

`GET /v1/states/{state_id}` returns the state, as on creation, with
`items`, `turns` and `last_used_at` up to date.

`GET /v1/states/{state_id}/items` lists the items a page at a time, like
OpenAI's list of conversation items. **Newest first** by default. Each premise and decision
carries its effective `status`, as in [Status](#status).

| Parameter | What it does |
| - | - |
| `limit` | Items per page, `1` to `100`. Default `20`. |
| `order` | `desc` (newest first, the default) or `asc` (oldest first). |
| `after` | An item `id`: start the page after it. Pass the last page's `last_id` to get the next page. |
| `format` | `faces` (the default) or `openai`. |

```bash theme={null}
curl "https://api.faces.sh/v1/states/fs_STATE_ID/items?limit=2" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```json theme={null}
{"object": "list",
 "data": [
   {"id": "ci_3", "type": "function_call_output", "call_id": "prem_CALL_ID",
    "output": "{\"value\": \"50k\", \"description\": \"the offsite budget\"}"},
   {"id": "ci_2", "type": "function_call", "name": "premise", "call_id": "prem_CALL_ID",
    "arguments": "{\"key\": \"budget\"}"}],
 "first_id": "ci_3", "last_id": "ci_2", "has_more": true,
 "premises": {"budget": {"value": "50k", "description": "the offsite budget", "status": "stated"}}}
```

`has_more` is `true` while there are more pages. With `format=faces`, every page also carries
the `premises` in force now, all of them.

`format=openai` returns only the item types and fields OpenAI defines, so you can pass them
to anything that reads OpenAI's conversation items. Our own fields are left out: the face's
name, the model and the premises. A decision becomes a call to a `decision` tool
followed by its result. Any other `format` is a `422`.

## Compact

`POST /v1/states/{state_id}/compact` writes one face's position over the state, in the
face's own terms, and keeps it on the server under a `compaction_id`. The text itself is not
returned. In a state open to any face, name the face in `model` (`@alice`).

```bash theme={null}
curl -X POST https://api.faces.sh/v1/states/fs_STATE_ID/compact \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@alice"}'
```

```json theme={null}
{"object": "compaction", "compaction_id": "fcmp_COMPACTION_ID",
 "session_id": "fs_STATE_ID", "turns": 2,
 "created_at": "2026-10-28T15:49:02+00:00", "expires_at": "2026-11-27T15:49:02+00:00",
 "usage": {"input_tokens": 5210, "output_tokens": 640}}
```

Add `"compaction": "<compaction_id>"` to a later chat or decision request with the same face to
have its steering read the summary. A slow compaction is held open like a decision: see
[Speed](https://docs.headwaters.ai/guides/decisions.md#speed).

## Close a state

`DELETE /v1/states/{state_id}` closes it:
`{"id": "fs_STATE_ID", "object": "state.deleted", "deleted": true}`. A closed
state takes no more turns and cannot be read. Its compactions stay usable until they
expire.

## Cost

* Opening, reading, adding items to and closing a state are free. A turn costs what it
  costs without one.
* **Compacting** is billed at the compaction rate (`compaction` in
  [`GET /v1/rates`](https://docs.headwaters.ai/guides/billing#current-rates)) on the tokens it reads and writes,
  `usage.input_tokens + usage.output_tokens`. On Connect and Pro it counts against the plan's
  [allowance](https://docs.headwaters.ai/guides/billing.md#allowances).
* **Using** a compaction adds its text to what the steering reads, and is billed with it.

Creating a state, adding items and compacting count against your plan's per-minute
[rate limit](https://docs.headwaters.ai/errors.md#rate-limits).

> [!NOTE]
>
> Every state route takes `version`, a body field on `POST` and a query parameter on `GET`:
> `23`, the default, or `22`, which reads and writes the same states without statuses,
> `depends_on`, `role` or `origin` (sending them is a `422`) and without `status_changes`.

## Expiry

A state expires 30 days after it was last used, and is then deleted with everything in
it. A compaction expires 30 days after it is written. Closing your account deletes your
states at once.

## Errors

`detail` is a string.

| Status | When | `detail` |
| - | - | - |
| `404` | The state does not exist, has expired or been closed, or is another account's | `no such state, or it has expired` |
| `404` | A turn sends a `conversation` (a state's id) that is unknown, expired, closed or another account's | `no such conversation, or it has expired. Nothing was charged.` |
| `404` | A turn names a different face from the one the state was opened with | `no such conversation, or it has expired. Nothing was charged.` |
| `422` | Adding a reply or a decision as if a face wrote it | ``a client adds its own messages (`role: user`) only: a face's replies and decisions are written by the server`` |
| `422` | A premise key used for the first time, with no `description` | ``premise 'rates' is new: give its `description` (what it means, in plain words)`` |
| `422` | A premise `key` that is empty, longer than 120 characters, or holds a newline or another control character | ``a premise `key` is plain text of 1 to 120 characters on one line, with no control characters ('two\nlines')`` |
| `422` | `premises` or `causes_visible` on a turn with no `conversation` | `` `premises` and `causes_visible` belong to a conversation: send its id as `conversation` `` |
| `422` | `conversation` and `session` both sent, with different ids | ``send `conversation` (or its old name `session`), not both`` |
| `422` | `causes_visible` that is not `true` or `false` | `` `causes_visible` is true or false `` |
| `422` | Compacting a state open to any face, without `model` | `` this conversation takes any face: name the one to compact in `model` `` |
| `422` | A premise `status` that is not one of the five | ``a premise `status` is one of stated, verified, assumed, unresolved, invalidated ('maybe')`` |
| `422` | A premise that depends on itself | `premise 'rent' cannot depend on itself` |
| `422` | A `depends_on` that would make a loop between premises | ``premise 'a': `depends_on` would make a loop (a -> b -> a); support flows one way`` |
| `422` | An edge with a `kind` other than `and` or `or`, or a `p` outside 0 to 1 | ``a `depends_on` entry's `kind` is "and" or "or" ('xor', on 'a')`` |
| `422` | An edge's `decision` that is not a decision in the state | ``premise 'a': a `depends_on` entry's `decision` names no decision in this conversation: dec_X`` |
| `422` | A field `POST /v1/states` does not take | `` unknown field `premise`: a state takes `model`, `causes_visible`, `items`, `premises`, `version` `` |
| `409` | A claim on a premise another agent holds | `'tests pass' is claimed by worker-1 until 2026-11-21T23:10:00+00:00` |
| `422` | `depends_on` naming something not in the state or the request | ``premise 'can_afford_rent': `depends_on` names no premise or decision (or choices option) in this conversation: rent`` |
| `422` | `depends_on` that is not a list, or names more than 200 | `` `depends_on` is a list of premise keys, decision ids and choices ids `` |
| `402` | A turn or a compaction with no credit left | See [Billing](https://docs.headwaters.ai/guides/billing.md). |
| `403` | The API key may not use the face | See [Errors](https://docs.headwaters.ai/errors.md). |
| `429` | The per-minute rate limit, or the plan's allowance is used and `api_fallback` is off | Names the limit. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.