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

# Decisions

> Ask what a face would decide, in OpenAI's Decisions format or TypeSafe Jev's System One.

# Decisions

[Choices](https://docs.headwaters.ai/guides/choices.md) give you the options a face would weigh. Decisions give you what it would *decide*: describe
a situation, ask typed questions about it (yes/no, pick one, or a graded scale), and get back
numbers, as this face.

Use it where you need a number rather than prose: routing, simulations, survey-style
panels, or checking how a face leans before you ask it to write anything.

Two compatible endpoints, each in its own API's format:

| path | format |
| - | - |
| `POST /v1/decisions` | [OpenAI's Decisions API](https://developers.openai.com/api/docs/guides/decisions): `input`, `questions` as an array, OpenAI's answers |
| `POST /v1/systemone` | [System One](https://docs.typesafe.ai/api), the API of Jev, TypeSafe's decision model, exactly: `state`, `questions` keyed by id, Jev's answers |

Name the model as the upstream model over the decision model, `@alice:maestro-1/jev-latest`
(see [Naming a model](https://docs.headwaters.ai/guides/models.md)): the face steers the decision model's answer. A decision
model with no face is not served, and neither is the face alone. Each path refuses the other's
format with a `422` that names the right path. Faces, limits and prices are the same on both, and so are the
decision models, except `gpt-6-luna`, which is on `/v1/decisions` only (see
[`gpt-6-luna`](#gpt-6-luna)).

> [!NOTE]
>
> **A face needs something compiled.** A face with nothing compiled answers `409` (see
> [Failures](#failures)).

***

## Ask

```bash theme={null}
curl -X POST https://api.faces.sh/v1/decisions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@alice:maestro-1/jev-latest",
    "input": "A colleague asks you to put your name on a grant proposal you have not read, due in an hour. They say it is a formality.",
    "questions": [
      {"type": "choice", "name": "sign", "instructions": "Does the speaker sign the proposal?",
       "choices": [{"value": "yes",   "description": "signs it as asked"},
                   {"value": "no",    "description": "declines to sign"},
                   {"value": "later", "description": "asks for time to read it first"}]},
      {"type": "predicate", "name": "irked", "instructions": "Is the speaker irritated?"},
      {"type": "score", "name": "firm", "instructions": "How firm is the reply?",
       "levels": [{"label": "yields"}, {"label": "hedges"}, {"label": "firm"}]}
    ]
  }'
```

```json theme={null}
{
  "object": "decision",
  "model": "@alice:maestro-1/jev-latest",
  "answers": [
    {"type": "choice", "name": "sign", "choice": "later", "confidence": 0.24,
     "probabilities": [{"value": "yes", "probability": 0.05}, {"value": "no", "probability": 0.46},
                       {"value": "later", "probability": 0.49}]},
    {"type": "predicate", "name": "irked", "probability": 0.24},
    {"type": "score", "name": "firm", "score": 1.12, "confidence": 0.34,
     "probabilities": [{"value": 0, "label": "yields", "probability": 0.16},
                       {"value": 1, "label": "hedges", "probability": 0.56},
                       {"value": 2, "label": "firm", "probability": 0.28}]}
  ],
  "answered_by": "jev-1.14.0",
  "usage": {"input_tokens": 4652, "output_tokens": 826}
}
```

### The request

| field | meaning |
| - | - |
| `model` | `@face:maestro-1/<decision model>`. See [Model forms](#model-forms). Required. |
| `input` | The situation: a string, or `user` messages whose `content` is a string or `input_text` parts. Size limits are in tokens; see [Limits](#limits). |
| `questions` | An array, each `{type, name, instructions, ...}`. `name` is unique and is echoed in the answer. Up to 10. Required. |

| `type` | extra fields | answer |
| - | - | - |
| `predicate` | none | `{type, name, probability}`: the probability of yes. |
| `choice` | `choices: [{value, description}]`, 2 to 255 | `{type, name, choice, probabilities: [{value, probability}], confidence}` |
| `score` | `levels: [{label, description}]`, lowest first, 2 to 10 | `{type, name, score, probabilities: [{value, label, probability}], confidence}`: `value` is the level's index, and `score` is the expected index (it may be fractional). |

Write `input` the way the face would hear it, addressed to them or describing what is in
front of them.

Descriptions do the work. `"no"` alone is ambiguous; `"declines to sign"` is not. Keep
choices mutually exclusive.

### The response

`{object: "decision", model, answers, answered_by, usage}`.

| field | meaning |
| - | - |
| `model` | The model, as sent: `@alice:maestro-1/jev-latest`. |
| `answers` | One answer per question, in the order asked. |
| `answered_by` | The decision model's versioned id that answered (`jev-1.14.0`). |
| `usage` | `{input_tokens, output_tokens}`, the steering and the decision model together. See [Cost](#cost) for what is billed. |

The face's cause steers the answer and is never returned.

### Where it differs from OpenAI's

This section is about `jev-latest`, `clef` and `clef-flash`. `gpt-6-luna` takes OpenAI's own
request unchanged; see [`gpt-6-luna`](#gpt-6-luna).

* `model` is `@face:maestro-1/<decision model>`, with our decision models (`jev-latest`,
  `clef`, `clef-flash`, `gpt-6-luna`) after the `/`. Any other model there is a `400`.
* Images aren't supported. See [Images](#images).
* Fields OpenAI's API does not document are refused (`422`) rather than ignored. That includes
  `stream`, and messages from any role but `user`.
* A question the decision model gives no usable answer to comes back as
  `{"type": "refusal", "name": …, "refusal": …}`.
* The response carries `answered_by`, the decision model's versioned id.

### `gpt-6-luna`

`gpt-6-luna` is OpenAI's Decisions model, on `/v1/decisions` in OpenAI's own request and
response shape: send what you would send to OpenAI, with `model` set to
`@alice:maestro-1/gpt-6-luna`.

* **The request:** OpenAI's text fields as they are. `input` is a string or a message array
  (any role, including tool calls and their outputs), or `input_json`; instruction parts;
  `name` on a question is optional; and `prompt_cache_key`, `prompt_cache_options` and
  `safety_identifier` are accepted. Up to 10 questions.
* **The response:** `id`, `object`, `model`, `answers` and OpenAI's full `usage`.
* **Price:** from your credits only, never through a linked ChatGPT plan. Input $0.10 per
  million tokens, cached input $0.01, cache writes \$0.125 (kept 30 minutes), output free, plus
  the markup. [`GET /v1/models?kind=decision`](https://docs.headwaters.ai/guides/models#listing-the-models) lists it with
  `cached_input_cost_per_million_tokens` and `cache_write_cost_per_million_tokens`.
* **Not on `/v1/systemone`,** which is Jev's format and models: it refuses `gpt-6-luna` with a
  `400` that points to `/v1/decisions`.

***

## System One

**It is [Jev](https://docs.typesafe.ai/api)'s API, exactly, at Jev's own path.** A request
written for TypeSafe's `/v1/systemone` works here with only the host and `model` changed: the
same `state`, the same `questions`, the same answers. To use TypeSafe's SDK, see
[From a Jev SDK](#from-a-jev-sdk).

```bash theme={null}
curl -X POST https://api.faces.sh/v1/systemone \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@alice:maestro-1/jev-latest",
    "state": "A colleague asks you to put your name on a grant proposal you have not read, due in an hour. They say it is a formality.",
    "questions": {
      "sign": {
        "type": "choice",
        "instructions": "Does the speaker sign the proposal?",
        "criteria": {
          "yes":   "signs it as asked",
          "no":    "declines to sign",
          "later": "asks for time to read it first"
        }
      },
      "irked": {
        "type": "noul",
        "instructions": "Is the speaker irritated?"
      },
      "firm": {
        "type": "score",
        "instructions": "How firm is the reply?",
        "criteria": ["yields", "hedges", "firm"]
      }
    }
  }'
```

```json theme={null}
{
  "model": "@alice:maestro-1/jev-latest",
  "answers": {
    "sign":  {"type": "choice", "choice": "later", "confidence": 0.25,
              "probabilities": {"yes": 0.05, "no": 0.45, "later": 0.5}},
    "irked": {"type": "noul", "noul": 0.25},
    "firm":  {"type": "score", "score": 1.11, "confidence": 0.34,
              "legend": {"0": "yields", "1": "hedges", "2": "firm"},
              "probabilities": {"0": 0.16, "1": 0.56, "2": 0.28}}
  },
  "usage": {"input_tokens": 4701, "output_tokens": 814},
  "answered_by": "jev-1.14.0"
}
```

### The request

| field | meaning |
| - | - |
| `model` | `@face:maestro-1/<decision model>`. See [Model forms](#model-forms). Required. |
| `state` | The situation: a string, an object or an array, as in Jev. Size limits are in tokens; see [Limits](#limits). |
| `questions` | Up to 10 questions, keyed by an id you choose. Required. |
| `questions.<id>.type` | `noul`, `choice` or `score`. |
| `questions.<id>.instructions` | The question itself: a string, an object or an array. |
| `questions.<id>.criteria` | Depends on `type`, below. |

| `type` | `criteria` | answer |
| - | - | - |
| `noul` | Optional `{"true": ..., "false": ...}`: what a yes and a no mean. | `{type, noul}`: the probability of yes, 0 to 1. |
| `choice` | Required. `{option: description}`, 2 to 255 options; a description may be `null`. | `{type, choice, probabilities, confidence}`: the likeliest option, a probability per option. |
| `score` | Required. An ordered array of 2 to 10 level descriptions. | `{type, score, legend, probabilities, confidence}`: the expected level (0 to n−1), the levels by index, a probability per level. |

### The response

| field | meaning |
| - | - |
| `model` | The model, as sent. |
| `answers` | One answer per question, keyed by your ids. |
| `answered_by` | The decision model's versioned id that answered. |
| `usage` | `{input_tokens, output_tokens}`, the steering and the decision model together. |

***

## Model forms

| `model` | what you get |
| - | - |
| `@alice:maestro-1/jev-latest` | The decision model answers, steered by your face `alice`. |
| `@alice:maestro-1-flash/jev-latest` | The same, steered sooner, at 10 times the steering price. |
| `@head~socrates:maestro-1/clef` | Another account's face: a [system face](https://docs.headwaters.ai/guides/system-faces.md), or one [published or shared with you](https://docs.headwaters.ai/guides/sharing.md). |
| `(@alice \| @bob):maestro-1/jev-latest` | A [composite](https://docs.headwaters.ai/guides/synthetic-faces.md#run-time-composites-compose-on-the-fly), priced like one face. |

`jev-latest` alone (no face), `@alice:maestro-1` alone (no decision model), `alice@jev-latest`
and `alice` are each a `422` whose message shows the form to use.

The decision models are `jev-latest`, `clef`, `clef-flash` and, on `/v1/decisions` only,
`gpt-6-luna`. Any other model after the `/` is a `400`. Their prices are in
[`GET /v1/models?kind=decision`](https://docs.headwaters.ai/guides/models#listing-the-models): per input token, output
free, plus the markup in [`GET /v1/rates`](https://docs.headwaters.ai/guides/billing#current-rates).

`confidence` is Jev's on both paths: for a choice `(p_max − 1/n) / (1 − 1/n)`, for a score
one minus the expected distance from the likeliest level, scaled by a uniform answer's. See
[Jev's confidence](https://docs.typesafe.ai/confidence).

### What the face brings

For each question the face works out its cause from the situation and that question together,
and steers the decision model with it. The cause stays on the server; in a
[state](https://docs.headwaters.ai/guides/states.md) it is kept there with the decision, for the face's later turns.

To have the face propose the options instead of giving them yourself, ask
[choices](https://docs.headwaters.ai/guides/choices.md) first: each option's `name` can be a value in a `choice` question.

### Images

Images aren't supported on the decision endpoints, or with a face. A request with one is a
`422`, before any work, so nothing is charged:

* "Images aren't supported with a face yet. Send the situation as text."

An `instructions` array of text parts is read as text.

### Limits

Counted in tokens, per decision model. The situation plus your longest question, and the
whole request (the situation plus every question):

| decision model | situation + longest question | whole request |
| - | - | - |
| `jev-latest` | 24,600 | 50,200 |
| `clef` | 14,000 | 14,000 |
| `clef-flash` | 14,000 | 14,000 |

Over a limit is a `422` that names the size and the limit, before any work, so nothing is
charged. The same numbers are at [`GET /v1/rates`](https://docs.headwaters.ai/guides/billing#current-rates)
(`limits.decisions`).

Both paths count against your plan's per-minute request limit
(`limits.requests_per_minute` in [`GET /v1/rates`](https://docs.headwaters.ai/guides/billing#current-rates)). Over it
is a `429` with `Retry-After`; see [Errors](https://docs.headwaters.ai/errors.md).

***

## From a Jev SDK

Point TypeSafe's SDK at Faces with two environment variables:

```bash theme={null}
export TYPESAFE_BASE_URL=https://api.faces.sh
export TYPESAFE_API_KEY=YOUR_FACES_API_KEY
```

Then set `model` to a face over Jev: `@alice:maestro-1/jev-latest`. The SDK
posts to `/v1/systemone`, which takes only Jev's format; `/v1/decisions` takes OpenAI's.

**Raise the SDK's timeout to at least 300 seconds.** Its default is 10 seconds per attempt,
retried twice, and every retry is a new, billed request. A decision typically takes 10 to 25
seconds.

Compressed request bodies are accepted on both paths: `Content-Encoding: gzip`, `x-gzip` or
`zstd`. The Python SDK sends zstd by default when it can (Python 3.14+, or the `typesafe-sdk[zstd]`
extra). One layer only: any other encoding, or two layers, is a `415`. At most 32 MiB once
decompressed, or it is a `413`.

**Where it differs from Jev:**

* Over a size limit is a `422` naming the size (see [Limits](#limits)), not Jev's `400 max_tokens_exceeded`.
* A decision model that fails is a `503` (retry), not Jev's `529`. The SDK retries both.
* At most 10 questions per request, and a face is required.
* `box` questions are not supported, and nor are [images](#images).
* The response also carries `answered_by`. The SDK ignores fields it doesn't know.

***

## Chaining decisions

Decisions keep no history between requests, so **you send the history in the situation**.
`/v1/systemone` takes it as a `messages` array in `state`: each earlier situation as a `user`
message, what was decided as an `assistant` message, and the current situation last.

```json theme={null}
{
  "model": "@alice:maestro-1/jev-latest",
  "state": {"messages": [
    {"role": "user", "content": "Monday. A new flour supplier is half the price of the old one... (the first situation)"},
    {"role": "assistant", "content": "Alice decided: Switch to the new supplier."},
    {"role": "user", "content": "Tuesday. The new supplier missed the morning delivery... (now)"}
  ]},
  "questions": {"move": {"type": "choice",
                         "instructions": "What does Alice do now?",
                         "criteria": {"keep": "Keep the new supplier",
                                      "switch": "Go back to the old supplier"}}}
}
```

On `/v1/decisions`, `input` takes `user` messages only: write the history into the text.

* **Include the earlier situations, not just the earlier choices.**

Both paths accept `conversation`, `premises`, `depends_on` and `compaction`: see
[States](https://docs.headwaters.ai/guides/states.md#decisions-in-a-state).

## Weigh a premise

In a state, `weigh` asks the face to weigh one premise's edges, in place of `questions`:

```bash theme={null}
curl -X POST https://api.faces.sh/v1/decisions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "@head~socrates:maestro-1/jev-latest", "conversation": "fs_STATE_ID",
       "weigh": {"premise": "handle bad input"}}'
```

| Field | Meaning |
| - | - |
| `premise` | **Required.** A premise of the state with at least two children of one kind. |
| `kind` | `or` or `and`: which edges to weigh, needed only when the premise rests on both. |
| `as` | Who writes, by the name a claim on the premise's branch holds. A write into a branch someone else holds is a `409`. |
| `cutoff` | Deprecated: it no longer sets anything aside. With an `or` premise it is a `422`. |

The face decides one `choice` between the premise's children, and each child's probability is
written onto its edge, with the decision's id. For `or` edges the probabilities rank the
candidates: they say which to try first, and none is set aside. A candidate is ruled out only
by a test that fails on it, or by you. An `and` child is never set aside either: every one must
still hold.

```json theme={null}
{"object": "decision", "answers": [{"type": "choice", "name": "weigh", "choice": "Reject malformed files",
  "probabilities": [ … ], "confidence": 0.54}],
 "decision_ids": {"weigh": "dec_DECISION_ID"},
 "weigh": {"premise": "handle bad input", "kind": "or", "cutoff": 0.85,
           "edges": [{"id": "Reject malformed files", "p": 0.77}, {"id": "Repair malformed files", "p": 0.23}],
           "pruned": [], "side_node": "sn_ID", "written": true, "decision": "dec_DECISION_ID"}}
```

`pruned` is always empty, and `cutoff` is echoed without effect.

`weigh` with `questions`, without `conversation`, naming a premise with fewer than two
children of the kind, or naming a test or a fact you stated, is a `422`, and nothing is
charged.

## Cost

A decision is charged in two parts: the steering (the upstream model), then the decision model.

* **The steering** costs $0.42 per million input tokens it processes, plus a fixed **$0.00042 per call\*\*, with no output charge; `maestro-1-flash` is 10 times both. It counts
  against your plan's [allowance](https://docs.headwaters.ai/guides/billing.md#allowances) first, or is paid from credits on
  the Free plan or past the allowance.
* **The decision model** is paid from your credits on every plan, at the model's listed price
  plus 5%, on the token count it reports itself. So a decision needs credit, even when the
  steering is covered: with none, it is a `402` before any work.

Nothing is charged for a request refused before work starts (`400`, `402`, `403`, `409`,
`422`, `429`).

***

## Speed

A decision takes about 20 seconds. **Set your client timeout to at least 300 seconds.**

**A slow call is held open.** Past about 40 seconds, the response is a `200` with the header
`X-Headwaters-Held: 1`, and whitespace before the JSON. Parse the body as usual. A failure after
that point comes back inside the `200` as an error body, with `detail` and OpenAI's `error`
object carrying the real `status`, and no `answers`. When `X-Headwaters-Held` is set, check for
`error` before reading `answers`. `detail` and `error.code` are the same as the refusal
would carry without the hold. A request still working after 300 seconds is stopped and
answered `504`: retry.

***

## Failures

Every failure is JSON with a `detail` you can show.

| code | when | what to do |
| - | - | - |
| `400` | The model after the `/` is not a decision model | Name one from `GET /v1/models?kind=decision`. |
| `402` | No credit to pay for it | [Top up](https://docs.headwaters.ai/guides/billing.md). |
| `403` | The API key may not use this face, or the face is not yours to use | Use a key or face that may. |
| `404` | No such face, or not one you can use | Check the alias. |
| `409` | The face has nothing compiled | Compile a source for it. |
| `422` | `model` is not `@face:maestro-1/<decision model>` (the message shows the form to use), a removed field (`cause`, `causes`, `view`, `style`, `kind`), the body is the wrong shape (a missing field, criteria that do not fit the type, no questions), the other path's format (the message names the right path), or it is over a [limit](#limits) | Read the message. |
| `422` | An image in the request. [Images](#images) aren't supported here | Send the situation as text. |
| `429` | Over the per-minute request limit, with `Retry-After`; or Connect or Pro, the plan's allowance used and `api_fallback` off, with the reset date | Wait `Retry-After` seconds; for the allowance, turn on `api_fallback` or wait for the reset. |
| `503` | The decision model is unavailable. Nothing is charged | Retry later, or use another decision model. |
| `503` | The steering failed, or the decision model did. The message says which | Retry. |
| `503` | The decision model you named is not available right now. Refused before any work, so nothing is charged | Try another decision model, or retry later. |
| `504` | Still working after 300 seconds, so it was stopped | Retry. |

A failure never falls back to an answer without the face.


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