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

# Synthetic Faces

> Compose faces from boolean expressions over existing faces.

# Synthetic Faces

A synthetic face is defined by a boolean formula over existing faces. It is assembled on the fly: no separate compilation, no extra training.

***

## Formula syntax

| Operator | Meaning |
| - | - |
| `a \| b` | Union |
| `a & b` | Intersection |
| `a - b` | Difference |
| `a ^ b` | Symmetric difference |

Parentheses are supported for grouping:

```
(alice | bob) & mentor
alice | (expert - academic)
```

***

## Create a synthetic face

Pass a `formula` instead of uploading documents. `name` is required, as for any face:

```bash theme={null}
curl -X POST https://api.faces.sh/v1/faces \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "alias": "alice-and-bob",
    "name": "Alice and Bob",
    "formula": "alice | bob"
  }'
```

The formula references faces by their `alias`. All referenced faces must:

* Be owned by you
* Be concrete (non-synthetic) faces

Nesting synthetic faces (referencing a face that itself has a formula) is not supported and returns `422`.

***

## Update the formula

```bash theme={null}
curl -X PATCH https://api.faces.sh/v1/faces/FACE_ALIAS \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"formula": "alice & mentor"}'
```

Changes take effect immediately on the next request.

`{"formula": ""}` removes the formula: the face reads `"formula": null` and is an ordinary face again.

A formula can be added only to a face with no sources or compiled content of its own,
and that no other synthetic face uses as an operand. Anything else is a `409` and the
face is unchanged: create a new face with the formula instead.

***

## Ask a synthetic face

The same as asking any face:

```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": "@alice-and-bob:maestro-1",
    "state": "A team wants to ship a feature on Friday without tests because the demo is Monday.",
    "instructions": "What should the team do?"
  }'
```

***

## Validation rules

* All referenced aliases must be owned by you at create/update time.
* Referenced faces must be concrete (not synthetic themselves).
* The formula must be a valid boolean expression using `|`, `&`, `-`, `^`, parentheses, and valid aliases.

Invalid formulas return `422` with a description of the problem.

***

## Use cases

* **Union**: `designer | engineer`
* **Intersection**: `alice & mentor`
* **Difference**: `senior-dev - junior-dev`
* **A/B testing**: compare `alice | bob` with `alice & bob`.

***

## Run-time composites (compose on the fly)

You don't have to create a synthetic face first. You can pass a formula **directly as the face** and have it composed for that one call:

```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": "(@alice | @bob):maestro-1",
    "state": "A student asks whether to switch from physics to philosophy in their final year.",
    "instructions": "What should the student do?"
  }'
```

The same operators apply (`|`, `&`, `-`, `^`, parentheses), on faces written `@alias`, with the maestro once after the whole expression. A composite works wherever a face does: [`/v1/choices`](https://docs.headwaters.ai/guides/choices) (`(@alice | @bob):maestro-1`), [chat](https://docs.headwaters.ai/guides/chat.md) and [decisions](https://docs.headwaters.ai/guides/decisions.md) (`(@alice | @bob):maestro-1/<model>`). See [Naming a model](https://docs.headwaters.ai/guides/models.md#composites).

Behaviorally a run-time composite is identical to a persisted one of the same operands, and there's no meaningful latency difference. Persist when you'll reuse it (and want to name it); compose on the fly for one-off blends.

### Rules

* **Operands must be concrete faces**, same as persisted formulas. A bare alias is one of your own faces. Unknown/unowned operand → `404`; referencing a synthetic face as an operand → `422` (no nesting).
* **Another account's face works in a run-time formula**, for a face you can read, such as a published one: `(@alice | @head~socrates):maestro-1/<model>`. A face you cannot read → `404`. A persisted formula takes only your own faces by bare alias.
* **Difference:** a `-` right before `@` or `(` is the difference, with or without spaces (`@alice-@bob`, `@alice - @bob`); a dash inside a name (`@news-bot`) is part of the alias, and no alias starts or ends with one. A persisted formula (`face:create`) still writes `alice - bob`, with spaces and no `@`.

### Identity: the first operand

A run-time composite answers as its **first (leftmost) operand**, taking that face's name and any [`profile_addendum`](https://docs.headwaters.ai/guides/faces#profile_addendum):

```
(alice | bob)@model   →  answers as Alice, combined with Bob
(bob | alice)@model   →  answers as Bob, combined with Alice
```

If you want a **custom** name or system prompt for the blend (rather than inheriting the first operand's), create a persisted synthetic face: you name it and set its `profile_addendum` at creation.

### An empty result

A formula whose result is empty is a `422`, and nothing is charged:

```json theme={null}
{"detail": {"error_code": "empty_composite", "message": "the intersection between these two faces is null"}}
```

With more than two faces the message is "the intersection between these faces is null". An
empty `-` or `^` result says "the result of this formula is null".


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