# `Nous.DecisionModel.Backend.SystemOne`
[🔗](https://github.com/nyo16/nous/blob/v0.21.1/lib/nous/decision_model/backend/system_one.ex#L1)

HTTP backend for the TypeSafe-compatible **System One** API
(`POST /v1/systemone`), plus a Cloudflare **Workers AI** preset.

Servers: vLLM, SGLang (Clef), llama-server, Jev / OpenRouter, LiteLLM.

    # Self-hosted (vLLM, SGLang, llama-server)
    Nous.DecisionModel.parse("systemone:Cloudflare/clef-flash", base_url: "http://localhost:8000")

    # Cloudflare Workers AI (reads CLOUDFLARE_ACCOUNT_ID / CLOUDFLARE_API_TOKEN)
    Nous.DecisionModel.parse("workers_ai:clef-flash")

## Wire format

Request (key order is kept: questions and options are sent in the order
declared, never re-sorted):

    {"model": "clef-flash",
     "state": ...,
     "questions": {"<id>": {"type": "noul", "instructions": "...",
                            "criteria": {"true": "...", "false": "..."}}}}

No top-level `instructions` is ever sent: Clef-on-vLLM and Decision 3.0
answer it with HTTP 400. Answers come back keyed by question id; Workers AI
wraps them in its `{"result": ..., "success": true}` envelope, which is
unwrapped.

## Options

  * `:base_url` - server root, e.g. `"http://localhost:8000"` (a trailing
    `/v1` is accepted). Required unless `preset: :workers_ai`, where it
    defaults to `"https://api.cloudflare.com/client/v4"`.
  * `:preset` - `:workers_ai` for Cloudflare Workers AI.
  * `:api_key` - bearer token. Workers AI default: `CLOUDFLARE_API_TOKEN`.
  * `:account_id` - Workers AI account. Default: `CLOUDFLARE_ACCOUNT_ID`.
  * `:timeout` - request timeout in ms. Default `5_000` (decisions are
    short; HTTP's 180 s default would stall a guard).
  * `:allow_private_hosts` - allow a private-network `base_url`. Loopback
    URLs (`localhost`, `127.0.0.1`, `::1`) are always allowed; any other URL
    goes through `Nous.UrlGuard`'s SSRF checks.
  * `:max_state_tokens` - token budget for state plus questions. Default
    65,536 for Workers AI, 16,384 otherwise (the self-hosted Clef
    reference). Servers truncate an over-long state silently, so callers
    should chunk before that.
  * `:http_backend` - a `Nous.HTTP.Backend` module for this backend's
    requests.

## Errors

  * 429 → `reason: :http`, `retryable?: true`, `retry_after_ms` from
    `Nous.Errors.RetryInfo`
  * 400 / 413 whose body says the request is too long → `:oversize`
  * other 4xx → `:http`; 5xx → `:http`, `retryable?: true`
  * transport timeout → `:timeout`; connection failures → `:unavailable`
  * a response with an undeclared id, option or level → `:unknown_label`

vLLM's logprob-read models are batch-nondeterministic unless the server
runs with `VLLM_BATCH_INVARIANT=1`; set it for security use.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
