Run your first policy
Create invoice payment rules, keep the model, check the cutoff and test a revised discount.
Start with a $25,000 invoice. The policy allows a 2% discount for approved invoices paid within ten calendar days of the invoice date, inclusive. You will create the rules, keep the model, test a boundary and compare a 3% discount before your application adopts it.
You need an approved preview account, available credits, curl and jq.
Get an API key
Sign in to the console, open API keys and create a key. Keep the secret in your environment. Console and API calls use the same credit balance.
export AITYX_API_KEY="aityx_sk_…"
export AITYX="https://api.aityx.ai"Create the rules from questions
Ask for eligibility, the payable amount and the last eligible date. The payment terms are explicit in the
questions, and the invoice is visible in state.
cat > invoice-request.json <<'JSON'
{
"model": "aityx-gen-0.98",
"state": {
"invoice_amount": 25000,
"invoice_date": "2026-10-01",
"payment_on": "2026-10-11",
"approved": true
},
"questions": {
"payment_action": {
"type": "choice",
"instructions": "Unapproved invoices go to review. Approved invoices get 2% off if payment_on is within 10 calendar days of invoice_date (inclusive); otherwise pay in full.",
"criteria": {
"discount": "Pay at the discount rate.",
"full": "Pay the full amount.",
"review": "Needs approval."
}
},
"payable_amount": {
"type": "number",
"instructions": "Return USD payable: zero for review; 98% of invoice_amount for discount; otherwise invoice_amount. Round to cents.",
"criteria": {
"unit": "USD",
"range": ">= 0"
}
},
"discount_by": {
"type": "date",
"instructions": "Return the last discount date: invoice_date plus 10 calendar days."
}
}
}
JSON
curl --fail-with-body -sS "$AITYX/v1/systemone" \
-H "Authorization: Bearer $AITYX_API_KEY" \
-H "Content-Type: application/json" \
-d @invoice-request.json > first-run.json
jq '.model' first-run.json > invoice-model.json
jq '.receipt' first-run.json > first-receipt.json
jq '.answers' first-run.jsonFor this invoice, the policy calls for discount, $24,500 payable and an October 11 deadline. Inspect
invoice-model.json: it contains the complete content definition and its questions contract.
This questions-based call uses System Two pricing. Sending the questions again also uses System Two pricing, including when aityx reuses a cached model. To use the lower execution rate, submit the definition you kept.
Run your model with the same invoice
Build a self-contained request from the model file and invoice. No model id is needed.
jq '.state' invoice-request.json > invoice-state.json
jq -n --slurpfile model invoice-model.json --slurpfile state invoice-state.json \
'{model: $model[0], state: $state[0]}' > execution.json
curl --fail-with-body -sS "$AITYX/v1/systemone" \
-H "Authorization: Bearer $AITYX_API_KEY" \
-H "Content-Type: application/json" \
-d @execution.json > matching-run.json
jq '{answers, usage, billing}' matching-run.jsonCheck the returned input schema if your model uses different field names. A complete model with matching JSON uses System One pricing. Billing includes the model and input sent; output is free.
Check one day past the cutoff
Move payment to October 12, leaving the invoice date and approval unchanged.
jq '.state.payment_on = "2026-10-12"' execution.json > late-execution.json
curl --fail-with-body -sS "$AITYX/v1/systemone" \
-H "Authorization: Bearer $AITYX_API_KEY" \
-H "Content-Type: application/json" \
-d @late-execution.json > late-run.json
jq '.answers' late-run.jsonThe policy requires full, $25,000 payable and the same October 11 deadline. Inspect the model and receipt
if the output disagrees with the written terms. An engine can execute incorrect rules faithfully, so review
the generated definition before using it in production.
Keep the receipt with the case
The receipt is already in the execution response. Save it rather than making a lookup call.
jq '.receipt' late-run.json > late-receipt.json
jq '.receipt | {given, read, decisions}' late-run.jsonLook at the calculated deadline and the rule that fired for payment_action. Keep the model, input and full
receipt together in your application. The service does not retain a receipt history for later retrieval.
A required fact that cannot be established produces invalid_state before execution. Your application can
ask for the missing fact or route the case for review. Inspect extracted facts when a reader was needed.
Create a revised definition
Submit the current content and question contract with a change request. Your original file remains yours.
jq -n --slurpfile model invoice-model.json \
'{content: $model[0].content, output: $model[0].questions,
prompt: "Increase the early-payment discount from 2% to 3%. Qualifying approved invoices pay 97% of invoice_amount, rounded to cents. Keep the inclusive 10-calendar-day window, deadline, approval requirement and other outcomes unchanged."}' \
> revision-request.json
curl --fail-with-body -sS "$AITYX/v1/systemtwo/models" \
-H "Authorization: Bearer $AITYX_API_KEY" \
-H "Content-Type: application/json" \
-d @revision-request.json > revision.json
jq '.model' revision.json > invoice-model-revised.jsonRead the changed rules. The revised policy should pay $24,250 for the qualifying $25,000 invoice, keeping the October 11 deadline. Creating a revision with AI uses System Two pricing.
Check the change before you adopt it
Run a useful set of inputs against both definitions. Include the exact cutoff, one day late and an unapproved invoice. Compare revised rules provides a complete client-side comparison script.
Your application keeps submitting the original definition until you replace it deliberately. There is no server-managed latest-version pointer that moves your application automatically.
What you now own
An inspectable decision model, a revised definition, the test inputs and the execution receipts. Store these in your own files or repository. Download them before leaving a console session.
- Call it from JavaScript and Python.
- State: matching JSON, text extraction and missing facts.
- Pricing and limits: rates, cache hits and your available balance.