---
title: Define a model by hand
description: Write the native Decision JSON yourself and execute it. This is the only way models are created.
icon: pencil-ruler
---

A model is readable JSON. Writing it yourself — by hand or with your own development tools — is how every Decision is created: aityx has no model-generation endpoint and the console has no AI assistant. Native execution needs only the model and matching state.

This small example calculates an early-payment amount and deadline. Save it as `payment-model.json`:

```json
{
  "name": "Early payment",
  "inputs": {
    "amount": { "type": "number > 0", "desc": "Invoice amount in USD" },
    "invoice_date": { "type": "date", "desc": "Invoice date" },
    "payment_on": { "type": "date", "desc": "Planned payment date" }
  },
  "decisions": {
    "discount_by": { "type": "date", "expr": "invoice_date + duration(\"P10D\")" },
    "payable_amount": {
      "type": "number",
      "expr": "if payment_on >= invoice_date and payment_on <= discount_by then decimal(amount * 0.98, 2) else amount"
    }
  }
}
```

Submit the bare definition in `decision`; do not add a nested wrapper or repeat questions:

```bash
jq -n --slurpfile model payment-model.json \
  '{decision: $model[0], state: {amount: 25000, invoice_date: "2026-10-01", payment_on: "2026-10-11"}}' \
  > payment-request.json

curl --fail-with-body -sS https://api.aityx.ai/v1/systemone \
  -H "Authorization: Bearer $AITYX_API_KEY" \
  -H "Content-Type: application/json" \
  -d @payment-request.json
```

Under these example terms, payment on October 11 qualifies for **$24,500**, with an **October 11** discount deadline. These are worked expectations for the small model, not a separate recorded timing benchmark. The [invoice guide](/docs/guides/invoice-example) has the complete recorded approval example.

## Check the definition

Native execution validates the model before evaluating the state. An invalid definition returns `422 invalid_model`; mismatching facts return `422 invalid_state`.

The console’s free **Check** reports **Ready to run** or **Cannot run**, with blocking details. It is a console operation, not a public validation route; do not call console/internal endpoints from your application.

See [Model format](/docs/resources/model-format) for tables, types, functions and expressions. To change a model, edit the JSON and [compare the revised rules](/docs/guides/revise-and-replay) against known cases before switching.
