> ## 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.

# Choices

> Ask a face what it would do. It proposes the options it would weigh, or the question it would ask.

# Choices

`POST /v1/choices` asks a face for its view of a situation. Describe the situation, ask a
question, and the face proposes the options it would weigh, strongest first: each a short
name and a sentence, in the face's own terms. Leave the question out, and the face proposes
the question it would ask instead.

`model` is the upstream model alone: the face and its maestro, `@alice:maestro-1`. On this
endpoint our model generates the answer, so no downstream model follows. See
[Naming a model](https://docs.headwaters.ai/guides/models.md). To have a face steer another model's reply, use
[chat](https://docs.headwaters.ai/guides/chat.md) or [decisions](https://docs.headwaters.ai/guides/decisions.md).

***

## Ask

```bash theme={null}
curl -X POST https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@head~socrates:maestro-1",
    "state": "I run a small bakery and a national chain just opened a store across the street.",
    "instructions": "What should I do this month?",
    "max_choices": 4
  }'
```

```json theme={null}
{
  "object": "choices",
  "model": "@head~socrates:maestro-1",
  "choices": [
    {"name": "Examine your bakery's excellence",
     "description": "Reflect on what makes your bakery uniquely good, then act to embody that truth in your work and offerings this month."}
  ],
  "usage": {"input_tokens": 1092, "output_tokens": 188}
}
```

The face proposes as many options as it sees, up to `max_choices`, and may propose only one.
Each `name` is the option itself in plain words, and names are unique, so the list can go
straight into a `choice` question on [decisions](https://docs.headwaters.ai/guides/decisions.md) to ask how the face, or
a decision model, would choose between them.

### Request

| Field | Meaning |
| - | - |
| `model` | **Required.** The face and its maestro: one of your faces (`@alice:maestro-1`), one shared with you or a [system face](https://docs.headwaters.ai/guides/system-faces.md) (`@head~socrates:maestro-1`), or a [composite](https://docs.headwaters.ai/guides/synthetic-faces.md#run-time-composites-compose-on-the-fly) (`(@alice \| @bob):maestro-1`). The maestro is `maestro-1`, or `maestro-1-flash`, which answers sooner and is priced 10 times higher when a question is asked. See [Maestros](#maestros). |
| `instructions` | The question. Optional: without one, the face proposes the question it would ask (see [No question](#no-question)). |
| `state` | The situation, in prose, at most **3,000 tokens**. For a longer situation, build a [state](https://docs.headwaters.ai/guides/states.md) and send `state_id`. |
| `state_id` | A [state](https://docs.headwaters.ai/guides/states.md) (`fs_...`): its premises and decisions are the situation. Sent with `state`, the prose is an addendum for this call only (see [A state as the situation](#a-state-as-the-situation)). |
| `into` | Only with `state_id` and a question: a premise of the state. Each option is written in as a premise it rests on (see [Options as premises](#options-as-premises)). |
| `kind` | Only with `into`: `or` (the default) when the options are alternatives, one of which holds; `and` when they must all hold. |
| `premise` | Only with `state_id`, not with `into`: the premise of the state these options are for. The face is shown it and what it reads, but not the premises it already rests on, so it does not repeat them. Nothing is written as a premise (see [Your own options](#your-own-options)). |
| `options` | Only with `into`, in place of a question: options you already have, written in without asking a face (see [Your own options](#your-own-options)). |
| `as` | Only with `options`: who writes, by the name a claim on the premise's branch holds. |
| `depends_on` | Only with `state_id`: what the options rest on, a list of at most 200 premise keys, decision ids, option ids (`opt_...`) and choices ids (`cho_...`) in the state. The face is shown each of them, and the premises each directly depends on, in full (see [What a face is shown](https://docs.headwaters.ai/guides/states.md#what-a-face-is-shown)). The options added to the state record it. |
| `max_choices` | The most options to return, 1 to 32. Default `8`. |

A request needs a situation: `state`, `state_id`, or both.

### Response

| Field | Meaning |
| - | - |
| `object` | `choices`, or `choices.question` when no question was asked. |
| `model` | The model, as sent. |
| `choices` | The options, strongest first, each `{name, description}`. With `state_id` and a question, each also has an `id` (`opt_...`). |
| `choices_item` | Only with `state_id` and a question: the id (`cho_...`) of the options as added to the state. |
| `question`, `alternatives` | Only when no question was asked: the question the face would ask, and other questions it would consider. |
| `usage` | `input_tokens` and `output_tokens`: exactly what the request is billed for (see [Cost](#cost)). |

***

## No question

Leave `instructions` out, and the face reads the situation and proposes the question it
would ask about it.

```bash theme={null}
curl -X POST https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@head~socrates:maestro-1",
       "state": "I run a small bakery and a national chain just opened a store across the street."}'
```

```json theme={null}
{
  "object": "choices.question",
  "model": "@head~socrates:maestro-1",
  "question": "What does your bakery do better than any other, and why does that matter to you?",
  "alternatives": [
    "How do you measure the worth of your work when faced with such competition?",
    "What would it mean for your bakery to fail, and what would it mean to thrive?"
  ],
  "usage": {"input_tokens": 524, "output_tokens": 60}
}
```

Send the question back as `instructions` to get the options.

***

## A state as the situation

Prose is limited to 3,000 tokens. For more, or for a situation your agent keeps building,
put it in a [state](https://docs.headwaters.ai/guides/states.md): each fact a premise, with its status and what it
depends on, and the decisions already made. Then send the state's id.

```bash theme={null}
curl -X POST https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@head~socrates:maestro-1",
       "state_id": "fs_STATE_ID",
       "state": "The chain is selling bread at half our price.",
       "instructions": "What should the shop do about the chain?",
       "max_choices": 3}'
```

```json theme={null}
{
  "object": "choices",
  "model": "@head~socrates:maestro-1",
  "choices": [
    {"id": "opt_OPTION_ID_1", "name": "Direct Answer", "description": "The shop should compare the chain's prices to its own costs and decide if it can compete or must adapt, as rent is already unaffordable."},
    {"id": "opt_OPTION_ID_2", "name": "Virtue Over Profit", "description": "Focus on ethical pricing and quality, even if it means closing, for virtue is more valuable than financial survival."},
    {"id": "opt_OPTION_ID_3", "name": "Terminate Lease", "description": "If the chain's prices make competition impossible, end the lease and seek a new location or business model."}
  ],
  "choices_item": "cho_CHOICES_ID",
  "usage": {"input_tokens": 1431, "output_tokens": 295}
}
```

Prose sent in `state` beside a `state_id` is an **addendum for this one call**: the face reads
it with the state, and it is never saved to the state. Anything that should persist must be
written to the state yourself, as premises through [`/v1/states`](https://docs.headwaters.ai/guides/states#add-items).

The face reads each premise with its status, so it can tell a verified fact from an
assumption, or from one that no longer holds. A state must hold at least one premise or
decision.

With a question, the options are added to the state. Each comes back with an `id`, and the
list with a `choices_item`: name an option in a premise's or decision's `depends_on`, and a
decision resting on it is shown why the face proposed it. See
[Options in a state](https://docs.headwaters.ai/guides/states.md#options-in-a-state).

Send `depends_on` to name what the options rest on: the premises, decisions and earlier
options the face must read. Each is shown to the face in full, with the premises it directly
depends on. The options added to the state keep the list, and they are marked `invalidated`,
with `because`, when an item they name is. An option never invalidates anything itself.

```bash theme={null}
curl -s https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer $FACES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@head~socrates:maestro-1", "state_id": "fs_STATE_ID",
       "instructions": "What should the shop do?",
       "depends_on": ["can_afford_rent"], "max_choices": 3}'
```

***

## Options as premises

With `into`, each option is also written into the state as a premise of its own, and the
premise named in `into` rests on each of them through an edge of `kind` (see
[And, or and weights](https://docs.headwaters.ai/guides/states.md#and-or-and-weights)):

```bash theme={null}
curl -X POST https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@head~socrates:maestro-1", "state_id": "fs_STATE_ID",
       "instructions": "What does handling bad input mean here?",
       "into": "handle bad input", "kind": "or", "max_choices": 4}'
```

```json theme={null}
{"object": "choices", "model": "@head~socrates:maestro-1",
 "choices": [{"id": "opt_OPTION_ID", "name": "Reject malformed files",
              "description": "Refuse a file that does not parse, and say why.",
              "premise": "Reject malformed files"}, …],
 "choices_item": "cho_CHOICES_ID",
 "into": {"premise": "handle bad input", "kind": "or", "side_node": "sn_ID"},
 "usage": { … }}
```

Each option's premise is `assumed`, has `origin: agent` and the `face` that proposed it, and
its key is the option's name (followed by the premise's key in parentheses when the state
already has that key). `into.side_node` is the record of this call. `into` naming no premise of
the state is a `422`, and nothing is charged.

An option that proposes again, in the same or nearly the same words, a premise the `into`
premise already rests on is not written twice. It comes back with `matched: true` and `premise`
set to the key of the premise already there, and the call's side node records it as a
re-proposal:

```json theme={null}
{"id": "opt_OPTION_ID", "name": "Reject malformed files",
 "description": "Refuse a file that does not parse, and say why.",
 "premise": "Reject malformed files", "matched": true}
```

Weigh the options next with
[decisions](https://docs.headwaters.ai/guides/decisions.md#weigh-a-premise).

## Your own options

To choose which options go in, ask with `premise` first: the options come back and nothing is
written as a premise. Then send the ones you keep with `into` and `options`, each
`{name, description}`, at most 32. No face is asked and nothing is charged; each option goes
through the same check as above, against the premises already there and the options before it,
so a near copy is matched and not written twice:

```bash theme={null}
curl -X POST https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"state_id": "fs_STATE_ID", "into": "handle bad input", "kind": "or",
       "options": [{"name": "Skip malformed files", "description": "Leave a file that does not parse out, and report it"},
                   {"name": "Reject malformed files", "description": "Refuse a file that does not parse"}]}'
```

```json theme={null}
{"object": "choices.written", "into": "handle bad input", "kind": "or",
 "premises": ["Skip malformed files", "Reject malformed files"],
 "new": ["Skip malformed files"], "matched": ["Reject malformed files"],
 "side_node": "sn_ID", "usage": {"input_tokens": 0, "output_tokens": 0}}
```

### An option that is already in the state

An option whose name and description are exactly those of a premise elsewhere in the state is
not copied. That premise is linked under `into` as well, so it now rests under two premises,
and its name comes back in `linked`. It keeps what it is: a fact you stated stays your fact, and
a goal or a test is still the same one to prove. Only the same text is linked; an option that
is merely close to a premise elsewhere is written as a new one. To link it instead, send that
premise's own name and description.

So the two differ in where they look and how close a match must be. `matched` is a close
rewording of an option already under `into`, or of one before it in the same call, and nothing
new is written. `linked` is the exact text of a premise anywhere else in the state, now placed
under `into` too.

```bash theme={null}
curl -X POST https://api.faces.sh/v1/choices \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"state_id": "fs_STATE_ID", "into": "keep it fast", "kind": "and",
       "options": [{"name": "report each error", "description": "Each error names the line it is on"},
                   {"name": "stream the input", "description": "Read the file in pieces, never whole"}]}'
```

```json theme={null}
{"object": "choices.written", "into": "keep it fast", "kind": "and",
 "premises": ["report each error", "stream the input"],
 "new": ["stream the input"], "matched": [], "linked": ["report each error"], "refused": [],
 "text": "Wrote 1 sub-goal under \"keep it fast\". \"report each error\" already exists; linked it under \"keep it fast\".",
 "usage": {"input_tokens": 0, "output_tokens": 0}}
```

A match is not linked when the premise is already refuted, or when `into` rests on it, since
linking it would make a loop. It comes back in `refused` with why, and nothing is written for it:

```json theme={null}
{"new": [], "matched": [], "linked": [],
 "refused": [{"key": "handle bad input", "why": "linking it would make a loop: the target rests on it"}]}
```

A withdrawn premise is never matched, so an option with its text is written as a new one.

A premise takes children of one kind only: an `or` option under a premise that rests on `and`
children, or the reverse, is a `422` that says why. So is an option under a test, or under a
fact you stated.

## Maestros

| Maestro | What it is | Price per 1M input tokens | Price per 1M output tokens |
| - | - | - | - |
| `maestro-1` | The standard. | \$0.42 | \$1.00 |
| `maestro-1-flash` | The same face, answered sooner. | $4.20 with a question; $0.42 without | $10.00 with a question; $1.00 without |

`maestro-1-flash` costs 10 times more only when a question is asked. Without `instructions`
it runs as `maestro-1` does, and is billed the same. Both are listed, with their prices, by
`GET /v1/models?kind=upstream`: see [Listing the models](https://docs.headwaters.ai/guides/models.md#listing-the-models).

***

## Cost

A call is billed on `usage`: the tokens the face processed to answer it, input and output.
Nothing else is added, and a refused call is not charged.

* **Free plan:** `input_tokens` and `output_tokens` are paid from credits at the model's
  price.
* **Connect and Pro:** `input_tokens` count against the plan's
  [allowance](https://docs.headwaters.ai/guides/billing.md#allowances), the one chat and decisions use too. On
  `maestro-1-flash` with a question, they count 10 times. Past the allowance, with
  `api_fallback` on, input and output are paid from credits at the model's price; with it
  off, the call is refused with `429`.

***

## Errors

`detail` is a string. Nothing is charged for any of them.

| Status | When |
| - | - |
| `402` | No credit left to pay for the call. See [Billing](https://docs.headwaters.ai/guides/billing.md). |
| `404` | The face, or the state in `state_id`, does not exist or is not yours to use. |
| `409` | The face has nothing compiled, or was compiled before the current release: recompile it. The message says which. |
| `422` | The request cannot be read: `model` is not `@face:maestro-1` (the message shows the form to use; `view` and `version` are removed), there is no situation, `state` is over 3,000 tokens, the state holds no premises or decisions yet, `depends_on` is sent without `state_id`, or it names something not in the state. The message says which. |
| `429` | The per-minute [rate limit](https://docs.headwaters.ai/errors.md#rate-limits), or the plan's allowance is used and `api_fallback` is off. The message names the limit. |
| `503` | The face's options failed. Retry. |

```json theme={null}
{"detail": "This description is 5201 tokens; version 23 reads prose of at most 3,000. Put a longer situation in a state (POST /v1/states, one premise per fact) and send its id as `state_id` instead. Nothing was charged."}
```

```json theme={null}
{"detail": "@alice has nothing compiled, so version 23 has nothing to propose from. Compile a source for it. Nothing was charged."}
```


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