# Call it from your code

> Ask decisio from curl, Python, JavaScript or TypeScript, or the framework you already use. Every way sends the same JSON to one route.

Source: https://opendecisio.com/docs/use-from/

Call decisio from any language with one HTTP request, and get a [probability](https://opendecisio.com/docs/glossary/#probability) for every [option](https://opendecisio.com/docs/glossary/#option) back. Each script below sends the same support ticket with a choice, a yes or no [question](https://opendecisio.com/docs/glossary/#question) and a score. For a smaller first request, start with the [quickstart](https://opendecisio.com/docs/).

 

curl

shell

```
curl http://127.0.0.1:8000/v1/systemone \
  -H 'Content-Type: application/json' \
  -d '{
  "state": "I was charged twice for October. Both charges are 49.00 EUR, same day. Please refund one.",
  "questions": {
    "urgent": {
      "type": "noul",
      "instructions": "Does this ticket need a response within the hour?"
    },
    "queue": {
      "type": "choice",
      "instructions": "Which team should handle this ticket?",
      "criteria": {
        "billing": "Invoices, payments, refunds, prices, VAT",
        "access": "Login, passwords, two-factor, SSO, permissions, invitations, account security",
        "bug": "The product behaves wrongly: errors, crashes, wrong numbers, lost data",
        "feature": "A request for something the product does not do yet",
        "cancellation": "Cancelling, pausing or closing an account, deleting data",
        "other": "Press, partners, jobs, sales pitches, wrong address, thanks, general questions"
      }
    },
    "impact": {
      "type": "score",
      "instructions": "Rate the business impact using only the reported facts.",
      "criteria": [
        "No function impaired",
        "One user impaired, with a workaround",
        "Many users blocked from a core function",
        "Data loss or legal exposure"
      ]
    }
  }
}'
```

The answers come from a small test model, not the default model.

Python

Python’s standard library is all it needs. Save it as `ask.py` and run `python3 ask.py` (Python 3.12 or later). Set `DECISIO_BASE_URL` to your decisio endpoint; it defaults to `http://127.0.0.1:8000`.

python

```
import json
import urllib.request
import os

body = {
    "state": "I was charged twice for October. Both charges are 49.00 EUR, same day. Please refund one.",
    "questions": {
        "urgent": {
            "type": "noul",
            "instructions": "Does this ticket need a response within the hour?"
        },
        "queue": {
            "type": "choice",
            "instructions": "Which team should handle this ticket?",
            "criteria": {
                "billing": "Invoices, payments, refunds, prices, VAT",
                "access": "Login, passwords, two-factor, SSO, permissions, invitations, account security",
                "bug": "The product behaves wrongly: errors, crashes, wrong numbers, lost data",
                "feature": "A request for something the product does not do yet",
                "cancellation": "Cancelling, pausing or closing an account, deleting data",
                "other": "Press, partners, jobs, sales pitches, wrong address, thanks, general questions"
            }
        },
        "impact": {
            "type": "score",
            "instructions": "Rate the business impact using only the reported facts.",
            "criteria": [
                "No function impaired",
                "One user impaired, with a workaround",
                "Many users blocked from a core function",
                "Data loss or legal exposure"
            ]
        }
    }
}

request = urllib.request.Request(
    os.environ.get("DECISIO_BASE_URL", "http://127.0.0.1:8000").rstrip("/") + "/v1/systemone",
    data=json.dumps(body).encode(),
    headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(request, timeout=60) as response:
    answers = json.load(response)["answers"]

for name, answer in answers.items():
    if answer["type"] == "noul":
        print(name, round(answer["noul"], 3))
    else:
        top = max(answer["probabilities"], key=answer["probabilities"].get)
        print(name, top, round(answer["probabilities"][top], 3))
# urgent 0.159
# queue billing 0.962
# impact 1 0.648
```

The answers come from a small test model, not the default model.

TypeSafe SDK

Install TypeSafe’s SDK on its own: `pip install typesafe-sdk==0.7.2`, the version checked. It needs a key; any string works. Save the script as `ask-sdk.py` and run `python3 ask-sdk.py` in the environment where you installed the SDK.

python

```
from typesafe_sdk import TypeSafeClient
import os

client = TypeSafeClient(
    base_url=os.environ.get("DECISIO_BASE_URL", "http://127.0.0.1:8000").rstrip("/"),
    timeout=60,
    # the SDK requires one; the server ignores it
    api_key="unused",
    # the name GET /v1/models lists
    model="decisio-gemma-4-31b-it-letters",
)
body = {
    "state": "I was charged twice for October. Both charges are 49.00 EUR, same day. Please refund one.",
    "questions": {
        "urgent": {
            "type": "noul",
            "instructions": "Does this ticket need a response within the hour?"
        },
        "queue": {
            "type": "choice",
            "instructions": "Which team should handle this ticket?",
            "criteria": {
                "billing": "Invoices, payments, refunds, prices, VAT",
                "access": "Login, passwords, two-factor, SSO, permissions, invitations, account security",
                "bug": "The product behaves wrongly: errors, crashes, wrong numbers, lost data",
                "feature": "A request for something the product does not do yet",
                "cancellation": "Cancelling, pausing or closing an account, deleting data",
                "other": "Press, partners, jobs, sales pitches, wrong address, thanks, general questions"
            }
        },
        "impact": {
            "type": "score",
            "instructions": "Rate the business impact using only the reported facts.",
            "criteria": [
                "No function impaired",
                "One user impaired, with a workaround",
                "Many users blocked from a core function",
                "Data loss or legal exposure"
            ]
        }
    }
}

response = client.system_one(state=body["state"], questions=body["questions"])

for name, answer in response.nouls.items():
    print(name, round(answer.noul, 3))
for name, answer in response.choices.items():
    print(name, answer.choice, round(answer.probabilities[answer.choice], 3))
for name, answer in response.scores.items():
    top = max(answer.probabilities, key=answer.probabilities.get)
    print(name, top, round(answer.probabilities[top], 3))
# The server's name for the model, and the tokens it counted:
print(response.model, response.usage.input_tokens)
```

With TypeSafe's Python SDK 0.7.2. Its comments are shown above their commands.

JavaScript

Set `DECISIO_BASE_URL` to your decisio endpoint, or leave the local default. Save it as `ask.mjs` and run `node ask.mjs` (Node 22 or later; no package).

js

```
const body = {
  "state": "I was charged twice for October. Both charges are 49.00 EUR, same day. Please refund one.",
  "questions": {
    "urgent": {
      "type": "noul",
      "instructions": "Does this ticket need a response within the hour?"
    },
    "queue": {
      "type": "choice",
      "instructions": "Which team should handle this ticket?",
      "criteria": {
        "billing": "Invoices, payments, refunds, prices, VAT",
        "access": "Login, passwords, two-factor, SSO, permissions, invitations, account security",
        "bug": "The product behaves wrongly: errors, crashes, wrong numbers, lost data",
        "feature": "A request for something the product does not do yet",
        "cancellation": "Cancelling, pausing or closing an account, deleting data",
        "other": "Press, partners, jobs, sales pitches, wrong address, thanks, general questions"
      }
    },
    "impact": {
      "type": "score",
      "instructions": "Rate the business impact using only the reported facts.",
      "criteria": [
        "No function impaired",
        "One user impaired, with a workaround",
        "Many users blocked from a core function",
        "Data loss or legal exposure"
      ]
    }
  }
};

const baseUrl = (process.env.DECISIO_BASE_URL ?? "http://127.0.0.1:8000").replace(/\/$/, "");
const response = await fetch(baseUrl + "/v1/systemone", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify(body),
  signal: AbortSignal.timeout(60_000),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
const { answers } = await response.json();

for (const [name, answer] of Object.entries(answers)) {
  if (answer.type === "noul") {
    console.log(name, Number(answer.noul.toFixed(3)));
  } else {
    const [top, p] = Object.entries(answer.probabilities).sort((a, b) => b[1] - a[1])[0];
    console.log(name, top, Number(p.toFixed(3)));
  }
}
// urgent 0.159
// queue billing 0.962
// impact 1 0.648
```

The answers come from a small test model, not the default model.

TypeScript

Set `DECISIO_BASE_URL` to your decisio endpoint, or leave the local default. Save it as `ask.ts` and run `node --experimental-strip-types ask.ts` (Node 22.6 or later; no package).

ts

```
const body: { state: string; questions: Record&#x3C;string, unknown> } = {
  "state": "I was charged twice for October. Both charges are 49.00 EUR, same day. Please refund one.",
  "questions": {
    "urgent": {
      "type": "noul",
      "instructions": "Does this ticket need a response within the hour?"
    },
    "queue": {
      "type": "choice",
      "instructions": "Which team should handle this ticket?",
      "criteria": {
        "billing": "Invoices, payments, refunds, prices, VAT",
        "access": "Login, passwords, two-factor, SSO, permissions, invitations, account security",
        "bug": "The product behaves wrongly: errors, crashes, wrong numbers, lost data",
        "feature": "A request for something the product does not do yet",
        "cancellation": "Cancelling, pausing or closing an account, deleting data",
        "other": "Press, partners, jobs, sales pitches, wrong address, thanks, general questions"
      }
    },
    "impact": {
      "type": "score",
      "instructions": "Rate the business impact using only the reported facts.",
      "criteria": [
        "No function impaired",
        "One user impaired, with a workaround",
        "Many users blocked from a core function",
        "Data loss or legal exposure"
      ]
    }
  }
};

const baseUrl = (process.env.DECISIO_BASE_URL ?? "http://127.0.0.1:8000").replace(/\/$/, "");
const response = await fetch(baseUrl + "/v1/systemone", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify(body),
  signal: AbortSignal.timeout(60_000),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
type Answer = { type: string; noul?: number; probabilities?: Record&#x3C;string, number> };
const { answers } = (await response.json()) as { answers: Record&#x3C;string, Answer> };

for (const [name, answer] of Object.entries(answers)) {
  if (answer.type === "noul") {
    console.log(name, Number(answer.noul!.toFixed(3)));
  } else {
    const [top, p] = Object.entries(answer.probabilities!).sort((a, b) => b[1] - a[1])[0];
    console.log(name, top, Number(p.toFixed(3)));
  }
}
// urgent 0.159
// queue billing 0.962
// impact 1 0.648
```

The answers come from a small test model, not the default model.

 

In the Python, JavaScript and TypeScript tabs, the comment lines are what the default model answered.

 

Recorded decision: Gemma 4 31B, decisio 0.17.0, RTX PRO 6000 at 600 W, 2026-10-19, on the plain layout; record 1 of 60 of decisio-examples' support-routing run, sent again on that release; the printed probabilities are rounded to three places.

 

## Handle errors

 

Every server error comes back with a `detail` that names the problem. Save this example as `check-error.py` and run `python3 check-error.py` with a server running.

  

| Status | What it means |
| --- | --- |
| 422 | the server cannot read the request: a missing field, more than 255 options, a text longer than the context |
| 400 | the model cannot answer this request |
| 415 | the body is not sent as `Content-Type: application/json` |

 

With the standard library, an error is an `HTTPError` whose body holds the `detail`:

 python

```
import json
import urllib.error
import urllib.request

request = urllib.request.Request(
    "http://127.0.0.1:8000/v1/systemone",
    data=json.dumps({"state": "No questions asked.", "questions": {}}).encode(),
    headers={"Content-Type": "application/json"},
)
try:
    urllib.request.urlopen(request)
except urllib.error.HTTPError as error:
    print(error.code, "detail" in json.load(error))
# 422 True
```

 

- In JavaScript, check `response.ok` before reading the answer, as the script does.
- TypeSafe’s SDK raises `TypeSafeUnprocessableEntityError` for a 422 and `TypeSafeBadRequestError` for a 400.

 

## Set a timeout

 

- The first request after a server starts warms the model and takes longer than the rest; allow for it.
- TypeSafe’s SDK gives up after 10 s by default; raise its `timeout`.
- `fetch` has no timeout of its own; pass `signal: AbortSignal.timeout(ms)` to stop sooner.
- The server sets no rate limit, so the SDK’s retries on 429 never fire; it still retries 408 and 5xx.

 

## Use a framework

 

LangChain, the Vercel AI SDK, n8n, TanStack AI and Pipecat work with decisio once they point at the server. [Call it from a framework](https://opendecisio.com/docs/use-from/frameworks/) has a checked program for each.

 

## Use a coding assistant

 

[Install the decisio skills](https://opendecisio.com/docs/ai-skills/) to have Claude Code or Codex prepare your setup, request or backend integration. Choose the workflow for your [task](https://opendecisio.com/docs/glossary/#task) and include your hardware or endpoint in the prompt.

 

## Keep the server private

 

- The server has no authentication: it accepts the `Authorization` header and any API key, and ignores them.
- Run it on `127.0.0.1`, or behind a reverse proxy that authenticates the caller.
- Call it from your backend, not from a web page: the server sets no CORS headers, so a browser cannot call it.

 

## What next

 

- [Move from System One](https://opendecisio.com/docs/migrating/): point a client you already have at decisio, and what changes.
- [Teach a task](https://opendecisio.com/docs/tasks/): teach a question you ask again and again, and certify its answers.
- [The HTTP API](https://opendecisio.com/docs/api/): every route, request field and response field.
