---
title: Call it from JavaScript and Python
description: Execute matching facts, or read a customer message with Jev, using the same native model and endpoint.
icon: code
---

Download `cancellation-model.json` using the [quickstart](/docs/quickstart). Both clients call the one endpoint, `POST /v1/systemone`. Passing Jev `questions` is optional: without them the Decision runs alone; with them Jev reads the evidence first and the Decision returns the consolidated result.

```js JavaScript
import { readFile } from "node:fs/promises";

const AITYX = "https://api.aityx.ai";
const model = JSON.parse(await readFile("cancellation-model.json", "utf8"));

// Jev supplies the one fact the message carries; the Decision does the rest.
const intentQuestion = {
  customer_intent: {
    type: "choice",
    instructions:
      "Identify the customer request from message. Choose cancel_refund when they ask to cancel their subscription and refund unused time; cancel_only when they ask to cancel without a refund; otherwise other. Do not calculate eligibility, amount or deadline.",
    criteria: {
      cancel_refund: "Cancel subscription and refund unused time.",
      cancel_only: "Cancel without requesting a refund.",
      other: "Another request.",
    },
  },
};

export async function answerCancellation(state, { readMessage = false } = {}) {
  const res = await fetch(`${AITYX}/v1/systemone`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.AITYX_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      decision: model,
      ...(readMessage ? { questions: intentQuestion } : {}),
      state,
    }),
  });
  const result = await res.json();
  if (!res.ok) {
    if (result.code === "invalid_state") {
      return { outcome: "needs_facts", missing: (result.errors ?? []).map(e => e.path) };
    }
    throw new Error(`aityx ${res.status}: ${result.detail ?? "request failed"}`);
  }
  if (result.decision_error) {
    // Jev completed; the Decision did not. Native answers are unavailable.
    return { outcome: "needs_facts", error: result.decision_error, answers: result.answers };
  }
  return {
    requestType: result.answers.request_type.choice,
    eligible: result.answers.refund_eligible.noul === 1,
    refundUsd: result.answers.refund_amount.number,
    processingDeadline: result.answers.processing_deadline.date,
    receipt: result.receipt,
    usage: result.usage,
  };
}
```

```python Python
import json
import os
import requests

AITYX = "https://api.aityx.ai"
with open("cancellation-model.json") as file:
    model = json.load(file)

# Jev supplies the one fact the message carries; the Decision does the rest.
INTENT_QUESTION = {
    "customer_intent": {
        "type": "choice",
        "instructions": (
            "Identify the customer request from message. Choose cancel_refund when they ask "
            "to cancel their subscription and refund unused time; cancel_only when they ask "
            "to cancel without a refund; otherwise other. Do not calculate eligibility, "
            "amount or deadline."
        ),
        "criteria": {
            "cancel_refund": "Cancel subscription and refund unused time.",
            "cancel_only": "Cancel without requesting a refund.",
            "other": "Another request.",
        },
    }
}


def answer_cancellation(state: dict, *, read_message: bool = False) -> dict:
    payload = {"decision": model, "state": state}
    if read_message:
        payload["questions"] = INTENT_QUESTION
    res = requests.post(
        f"{AITYX}/v1/systemone",
        headers={"Authorization": f"Bearer {os.environ['AITYX_API_KEY']}"},
        json=payload,
        timeout=60,
    )
    result = res.json()
    if not res.ok:
        if result.get("code") == "invalid_state":
            return {"outcome": "needs_facts", "missing": [e["path"] for e in result.get("errors", [])]}
        res.raise_for_status()
    if result.get("decision_error"):
        # Jev completed; the Decision did not. Native answers are unavailable.
        return {"outcome": "needs_facts", "error": result["decision_error"], "answers": result["answers"]}
    return {
        "request_type": result["answers"]["request_type"]["choice"],
        "eligible": result["answers"]["refund_eligible"]["noul"] == 1,
        "refund_usd": result["answers"]["refund_amount"]["number"],
        "processing_deadline": result["answers"]["processing_deadline"]["date"],
        "receipt": result["receipt"],
        "usage": result["usage"],
    }
```

## Your application already knows the facts

```js
const result = await answerCancellation({
  customer_intent: "cancel_refund",
  plan_amount: 60, period_days: 30, unused_days: 10,
  accepted_on: "2026-10-21", refundable: true,
});
// result.refundUsd === 20
// result.processingDeadline === "2026-10-28"
```

Without `questions`, the Decision runs locally at $0.042 per 1M input tokens, with output free. Native schema mismatches return `422 invalid_state`; nothing reads the state for you.

## Your application has a customer message

```js
const result = await answerCancellation({
  message: "Please cancel my subscription and refund the days I have not used.",
  plan_amount: 60, period_days: 30, unused_days: 10,
  accepted_on: "2026-10-21", refundable: true,
}, { readMessage: true });
```

Same endpoint, same rate. Jev establishes `customer_intent` from the message, then the Decision calculates the amount and date in the same call and returns the consolidated result. If Jev completes but the Decision cannot run, the response is HTTP `200` with `decision_error` — check it before reading native answers.

The model is [your own JSON](/docs/guides/define-by-hand); there is no authoring call. You do not send a repeated answer contract. Every native decision, including helpers, appears in `answers`.

## Keep the result your application needs

Your application performs any cancellation or refund. Keep the model, original state and returned receipt when you need evidence. Execution does not echo your submitted data or return a receipt-history identifier.

For Jev-only calls — questions with no Decision, where Jev’s answers are the result — see [Using Jev with aityx](/docs/coming-from-jev).
