Run a Priority Analysis
This guide walks you through running an AI Eisenhower-Matrix burnout analysis on the open tasks of one of your projects. It is two HTTP calls: one to consume your daily quota and create the AI session, another to start the run.
For background on what the feature does and its limits, see Priority Analysis.
Prerequisites
- An active subscription whose plan includes Priority Analysis (otherwise the request returns
403 QUOTA_EXCEEDEDor403 ENTITLEMENT_MISSING). - A JWT bearer token for the chainer who owns the project.
- The
chainyIdof the project you want to analyse.
Step 1 — Create the run
RUN_RESPONSE=$(curl -fsS -X POST 'https://api.chainabit.com/api/v1/productivity/priority-analysis/runs' \
-H "Authorization: Bearer $JWT" \
-H 'Content-Type: application/json' \
-d '{
"chainyId": "00000000-0000-4000-8000-000000000001",
"mode": "approval",
"effortMode": "thinking"
}')
SESSION_ID=$(jq -r '.data.sessionId' <<< "$RUN_RESPONSE")
SEED_CONTENT=$(jq -r '.data.seedMessage.content' <<< "$RUN_RESPONSE")A successful response looks like this (truncated):
{
"data": {
"sessionId": "00000000-0000-4000-8000-000000000002",
"mode": "approval",
"chainyId": "00000000-0000-4000-8000-000000000001",
"scope": "chainy",
"quota": { "used": 1, "limit": 2, "remaining": 1, "periodUnit": "daily" },
"seedMessage": {
"content": "<first message to send to the session, unchanged>"
},
"accountTimezone": "Europe/Istanbul"
}
}The seedMessage.content field is the first user message you should send to start the AI run. Send it unchanged to POST /ai/sessions/:sessionId/messages.
Picking a mode
mode | Behaviour |
|---|---|
approval | (default) The AI proposes one batched change set; you approve from the standard Chao approval card. |
auto | The AI applies the proposed changes immediately. |
plan | The AI records the proposed changes as a plan; nothing is changed. |
Picking a model
You have two options:
model— pass an exact model key returned byGET /ai/models/available. Only models you are entitled to are accepted.effortMode—basic,thinking, orpro. A compatible model that you are entitled to is selected for you. This is the recommended path.
Step 2 — Start the run
Post the seed message returned by Step 1 to the standard AI session endpoint:
CREATE_RESPONSE=$(curl -fsS -X POST "https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/messages" \
-H "Authorization: Bearer $JWT" \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg content "$SEED_CONTENT" '{content: $content}')")
MESSAGE_ID=$(jq -r '.data.assistantMessage.id' <<< "$CREATE_RESPONSE")
export JWT SESSION_ID MESSAGE_IDRead data.assistantMessage.id from the Step 2 response. The JavaScript example uses eventsource v4 (npm install eventsource@4):
import { EventSource } from "eventsource";
const sessionId = process.env.SESSION_ID; // data.sessionId from Step 1
const messageId = process.env.MESSAGE_ID; // data.assistantMessage.id from Step 2
const token = process.env.JWT;
const events = new EventSource(
`https://api.chainabit.com/api/v1/ai/sessions/${sessionId}/messages/${messageId}/stream`,
{
fetch: (input, init) => fetch(input, {
...init,
headers: { ...init.headers, Authorization: `Bearer ${token}` },
}),
},
);
events.addEventListener("tool.approval_required", (event) => {
const { payload } = JSON.parse(event.data);
console.log("Approval required:", payload); // render an approval card
});
events.addEventListener("tool.completed", (event) => {
const { payload } = JSON.parse(event.data);
console.log("Tool completed:", payload);
});
["run.settlement.completed", "run.failed", "run.error", "run.cancelled", "run.degraded"]
.forEach((type) => events.addEventListener(type, () => events.close()));In approval mode the AI pauses on tool.approval_required until you call the approval endpoint with the digest and nonce from payload.approval. In auto mode the change set is applied immediately and you only see tool.completed. In plan mode you will instead see plan.step_added events and no mutation.
Common errors
| HTTP | code | What it means |
|---|---|---|
| 403 | QUOTA_EXCEEDED | You have used your daily allowance for this project. The counter resets at midnight in your account timezone. |
| 403 | ENTITLEMENT_MISSING | Your plan does not include Priority Analysis. |
| 403 | SUBSCRIPTION_REQUIRED | No active subscription was found for the chainer or account. |
| 404 | CHAINY_NOT_FOUND | The project id does not belong to your chainer. |
| 404 | MODEL_NOT_AVAILABLE | The model you requested is not active or you are not entitled to it. |
Tips
- In
approvalmode you will normally see one approval card for the whole change set, not many. - Completed tasks are excluded from the analysis — re-run it after completing items to see how your cognitive load shifts.
- The daily counter is per-project, so running an analysis on project A does not consume budget for project B.
- Expect a few tool events in the SSE stream before the final approval or completion event.