API reference · CAIN Trajectory
Evaluate Counterfactual
POST /fabric/trajectories/{trajectory_id}/counterfactual
Last reviewed 2026-10-02
POST /fabric/trajectories/{trajectory_id}/counterfactual
Run counterfactual trust simulation on a trajectory: - Omission: What would trust score be if step K never occurred? - Minimum evidence: What is required to permit a blocked action?
Parameters
| Name | In | Type | Meaning |
|---|---|---|---|
trajectory_id required | path | string |
Request body
CounterfactualRequest (required)
| Field | Type | Meaning |
|---|---|---|
omitted_step | integer or null | |
proposed_action | string or null | |
proposed_resource | string or null | |
proposed_risk | number or null | default 0.1 |
Responses
| Status | Meaning | Body |
|---|---|---|
200 | Successful Response | object |
422 | Validation Error | HTTPValidationError |
401 | No key, or a key that is not valid | JSON detail |
429 | Rate limit for your plan reached; retry after the Retry-After seconds | JSON detail |
Try it
This call changes data in the account the key belongs to.
The request goes from your browser straight to this site. Your key is not stored unless you tick the box, and then only in this tab's session storage.
Code
curl -sS -X POST 'https://cainstudio.online/fabric/trajectories/<trajectory_id>/counterfactual' \
-H "X-API-Key: $CAIN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"proposed_risk": 0.1}'import json, os, urllib.request
req = urllib.request.Request('https://cainstudio.online/fabric/trajectories/<trajectory_id>/counterfactual', method='POST',
headers={"X-API-Key": os.environ["CAIN_API_KEY"], "Content-Type": "application/json"},
data=json.dumps({
"proposed_risk": 0.1
}).encode())
with urllib.request.urlopen(req, timeout=60) as r:
print(r.status, json.load(r))const res = await fetch("https://cainstudio.online/fabric/trajectories/<trajectory_id>/counterfactual", {
method: "POST",
headers: {
"X-API-Key": process.env.CAIN_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify({
"proposed_risk": 0.1
}),
});
console.log(res.status, await res.json());Schemas used
HTTPValidationError · ValidationError · CounterfactualRequest
← Complete Trajectory · all 22 CAIN Trajectory calls · Make Trajectory Decision →
Try CAIN-42 on your own agents
Create a free account and every new account starts with a 7-day trial of the full platform. Or try the sandbox first, with no account at all.
Create a free account → · Try the sandbox · See the whole ecosystem