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

# Decisions

> Ask a decision model typed questions about a state and read answers with probabilities.

A decision model answers closed, typed questions about a state: text, JSON, or images. Each answer comes with its confidence and its probabilities. The model generates no text, answers in a fraction of a second, and costs a fraction of a chat completion.

`POST /api/v1/hub/decisions` runs one decision request synchronously, in the OpenRouter Decisions format.

## Send a decision request

```bash theme={null}
curl https://fanifyai.com/api/v1/hub/decisions \
  -H "Authorization: Bearer $FANIFY_API_KEY" \
  -H "Idempotency-Key: 0192f3a4-8c1e-7b2a-9f10-2b6d4e0c9a11" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "decision-model",
    "state": "Fan: Hi, I am Paul. Do you sell photos?",
    "questions": {
      "first_name": { "type": "noul", "instructions": "Did the fan give his first name?" },
      "intent": {
        "type": "choice",
        "instructions": "What does the fan want?",
        "criteria": { "buy": "Wants to buy content", "chat": "Just wants to talk", "other": null }
      },
      "interest": {
        "type": "score",
        "instructions": "How interested is the fan in buying?",
        "criteria": ["low", "medium", "high"]
      }
    }
  }'
```

Find decision models in `GET /api/v1/hub/models`: their `output_modalities` contain `decisions`. Call a decision model through this route; `chat/completions` rejects it with `400 invalid_input`, and this route rejects chat and media models the same way.

## Request

| Field | Required | Content |
| - | - | - |
| `model` | yes | Decision model `id` from the catalog |
| `state` | yes, not `null` | A string, a JSON object, or an array of parts |
| `questions` | yes, non-empty object | One entry per question: `key → { "type", "instructions", "criteria" }` |

An image in `state` is a part `{"type":"image_url","image_url":{"url":"data:image/png;base64,…"}}`. It can sit in the parts array or inside an object. Images are forwarded to the model and never stored by the Hub.

| `type` | `criteria` | Answer fields |
| - | - | - |
| `noul` (yes/no) | Optional: `{ "true": "…", "false": "…" }` | `noul`: probability from 0 to 1 that the statement is true |
| `choice` | Required: object `option → description` (description may be `null`) | `choice`: chosen option; `probabilities` per option |
| `score` | Required: array of levels, from weakest to strongest | `score`: may be decimal; `probabilities` per level index (`"0"`, `"1"`…); `legend`: index → level |

Every answer also has `type` and `confidence`.

The Hub checks only `model`, `state`, and `questions`. Other question types and additional top-level fields are forwarded unchanged: the model provider validates them.

## Response

```json theme={null}
{
  "id": "0192f3a4-8c1e-7b2a-9f10-2b6d4e0c9a11",
  "model": "decision-model",
  "answers": {
    "first_name": { "type": "noul", "noul": 0.93, "confidence": 0.93 },
    "intent": {
      "type": "choice", "choice": "buy", "confidence": 0.81,
      "probabilities": { "buy": 0.81, "chat": 0.15, "other": 0.04 }
    },
    "interest": {
      "type": "score", "score": 1.6, "confidence": 0.65,
      "probabilities": { "0": 0.05, "1": 0.3, "2": 0.65 },
      "legend": { "0": "low", "1": "medium", "2": "high" }
    }
  },
  "usage": { "input_tokens": 412, "output_tokens": 0, "cost": 0.000005 }
}
```

The model's response is forwarded as is, with four changes: `id` is the Hub generation identifier, `model` is the catalog `id`, `usage.cost` is the billed amount in EUR, and `provider` is removed. `answers` and the token counters keep their names and types.

> [!NOTE]
>
> The Hub does not check that every question was answered. Check that each requested key is present in `answers`: an incomplete response is billed like a complete one.

A `200` response also includes:

```text theme={null}
X-Fanify-Generation-Id: 0192f3a4-8c1e-7b2a-9f10-2b6d4e0c9a11
X-Fanify-Billed-Cost: 0.000005
```

`X-Fanify-Billed-Cost` is the billed amount in EUR, always written with a dot as decimal separator.

Each decision is recorded as a generation with `is_llm: true`: it appears in `GET /api/v1/hub/generations` (excluded by `media_only=true`) and triggers the `generation.running` and `generation.completed` webhooks.

## Idempotency

> [!TIP]
>
> Use one new `Idempotency-Key` per request. Keys share one space across all Hub routes: a key already used by another request replays that request's result.

* A replay with the same key and body returns the same body and headers, without a new model call or charge. A failed request replays the same error.
* A replay while the request is still running returns `503 generation_in_progress` with `Retry-After: 5`.
* The same key with a different body returns `422 idempotency_conflict`.
* After the retention period of the stored response (24 hours by default), a replay returns `410 file_expired`.

## Errors

Errors use the OpenAI-compatible envelope:

```json theme={null}
{
  "error": {
    "message": "Your available balance does not cover this generation.",
    "code": "insufficient_credits",
    "type": "invalid_request_error"
  }
}
```

`error.metadata.provider_name` is present only on a `provider_error`, when the routed model failed. Errors raised by the Hub itself (validation, credits, rate limit, pause) have no `metadata`, except the replay of a failed generation, which returns its original envelope with `metadata.provider_name`. An authentication failure returns `401 unauthorized` as Problem Details, before the decision is processed.

| HTTP | `code` | Cause |
| - | - | - |
| 400 | `invalid_input` | Invalid JSON, `model`, `state`, or `questions` missing, or the model is not a decision model |
| 402 | `insufficient_credits` | The available balance does not cover the request |
| 404 | `model_not_found` | Unknown or unavailable model |
| 410 | `file_expired` | Replay after the retention period |
| 413 | `payload_too_large` | The request body exceeds the configured limit |
| 422 | `idempotency_conflict`, `no_route_available` | Key reused with another body; no executable route |
| 429 | `rate_limited`, `capacity_exhausted` | `rate_limited`: request rate limit of the key (no `Retry-After`); `capacity_exhausted`: no slot freed within the time budget, with `Retry-After` (see [Errors](https://docs.fanifyai.com/en/hub/errors.md#capacity_exhausted)) |
| 503 | `hub_paused`, `generation_in_progress` | The Hub is not accepting new requests; same key still running |
| 503 | `interrupted` | Replay of a decision interrupted by a Hub restart |
| 500 | `internal_error` | Problem on the FanifyHub side; no internal detail is exposed |
| 4xx / 503 | `provider_error` | The routed model failed: its `4xx` status is kept, except `401` and `402` which become `503`; any other failure returns `503` |

Decisions have their own request rate limit per key, separate from the other Hub routes. A decision request has a short total time budget, 15 seconds by default, covering the wait for a concurrency slot and the model call. A failed request is never billed. See [Errors](https://docs.fanifyai.com/en/hub/errors.md) for the meaning of each code.

## Pricing

A decision is billed like a chat completion, from the input and output tokens of the routed model, at the `input_cost_per_million` and `output_cost_per_million` rates shown for your account in `GET /api/v1/hub/models`. Many decision models charge only input tokens; always read both rates. The billed amount is rounded to six decimal places.


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