The budget tree API
The budget tree arranges your organization's courses by year, faculty, and department, and shows what each course spent on AI. This article covers how to read the tree and how to build and change it through the API.
The tree is read-only for money: nothing in it allocates, caps, or moves a dollar.
How the tree is built
Each node has a kind:
kind |
Sits under | Notes |
|---|---|---|
year |
The top of the tree | |
faculty |
A year | |
department |
A year or a faculty | |
course |
A year, faculty, department, or Unassigned | Tied to one Cesura space by space_id. |
unassigned |
The top of the tree | One per organization. Cesura creates and keeps it. |
A node may skip a level, so a course can sit right under a faculty.
External IDs
external_id is your own code for a node, as your student information system or LMS knows it, for example NEG-101. It is optional, at most 100 characters with no spaces, and unique in your organization. Every endpoint that takes a node takes either its Cesura ID or ext:EXTERNAL_ID, so you can work with your own codes and never store Cesura's IDs.
Courses from your LMS
When a course is first launched from Moodle or another LMS, Cesura places its space in the tree. It binds the space to the course node whose external_id matches the LMS course's SIS ID, or failing that its short name, and that has no space yet. With no match, Cesura creates a course node under Unassigned and records the LMS IDs in lti_course_refs. An org admin moves those courses to their place on the Course budgets page. An API key cannot: a key limited to a node cannot see Unassigned, and a key without budgets.read cannot read the tree to find them.
To have courses land in the right place, create their course nodes ahead of time with the LMS course's SIS ID as external_id.
Find a space ID
No endpoint lists your spaces. To find a space's ID, open the space in Cesura: the ID is the part of the address after /spaces/. A space that already has a counted run is also listed, with its space_id, in the courses of your license usage.
Base path
Every endpoint is under:
https://app.cesura.ai/api/v1/organizations/ORG_ID/budget
Keys and what they can do
| Key's scopes | Reads | Writes |
|---|---|---|
budgets.read, limited to a node |
That node and everything under it, with spend | Nothing |
budgets.read and budgets.categories.write |
That node and everything under it, with spend | Only under that node. See Write limits. |
budgets.categories.write alone |
Nothing | The whole tree |
To create a key, see Organization API keys and scopes.
The node object
{
"id": "4f0c2a1e-6b3d-4e8a-9c1f-2d5b7a9e0c13",
"kind": "course",
"name": "Negotiation",
"external_id": "NEG-101",
"parent_id": "9a7b3c2d-1e4f-4a6b-8c9d-0e1f2a3b4c5d",
"space_id": "SPACE_ID",
"lti_course_refs": [],
"your_roles": [],
"spend": {"available": true, "visible": true, "currency": "USD", "spent": "41.27"},
"child_count": 0,
"children": null
}
| Field | Meaning |
|---|---|
id |
The node's Cesura ID. |
kind |
year, faculty, department, course, or unassigned. |
name |
The name people see, 1 to 200 characters. |
external_id |
Your own code for the node, or null. |
parent_id |
The parent node's ID, or null at the top of the tree. |
space_id |
Courses only: the Cesura space the course is. null for other kinds, and for a course not bound yet. See Find a space ID. |
lti_course_refs |
The LMS course IDs of a course Cesura placed from a launch. |
your_roles |
Why a person sees the node. Always [] for an API key. |
spend |
What the node and everything under it spent. See Spend. |
child_count |
How many nodes sit directly under this one. |
children |
The nodes under this one, as far as the request's depth reaches. null beyond it. |
Spend
availableistruewhen your organization uses its own OpenRouter key. Spend is what OpenRouter charged that key. For any other organization,availableisfalseandspentisnull.visibleistruefor an API key that reads.spentis US dollars as a decimal string, rounded to cents. A parent's spend is the sum of the courses under it.- A course's spend covers every AI call made in its space, whenever it was made: learner runs, grading, and authoring. There is no date range.
- The tree's spend does not add up to what your OpenRouter key used. The key also pays for calls outside any course in the tree, for example in spaces not bound to a course node, or not tied to a space at all.
Read the tree
Check access
GET /access
{"can_view": true, "can_manage": true, "roles": []}
can_view says whether the key sees any of the tree. can_manage is true when the key also holds budgets.categories.write: use it to show or hide your edit controls. /access and /tree need budgets.read, so a write-only key gets 403 INSUFFICIENT_SCOPE from both.
Get the whole tree
GET /tree
{
"organization_id": "ORG_ID",
"roots": [ /* node objects, each with all its children */ ],
"can_manage": true,
"spend_available": true
}
For a key limited to a node, roots holds that node, with everything under it.
Get one node
GET /nodes/NODE?depth=1
NODE is a node ID or ext:EXTERNAL_ID. depth is 0 for the node alone (the default), 1 for the node and its children, or all for its whole subtree.
Change the tree
These endpoints need a key with budgets.categories.write.
Create a node
POST /nodes
Content-Type: application/json
{
"kind": "course",
"name": "Negotiation",
"external_id": "NEG-101",
"parent": "ext:LAW",
"space_id": "SPACE_ID"
}
| Field | Required | Meaning |
|---|---|---|
kind |
Yes | year, faculty, department, or course. |
name |
Yes | 1 to 200 characters. |
external_id |
No | Your own code, unique in the organization. |
parent |
No | A node ID or ext:EXTERNAL_ID. Leave it out, or send null, to put a year at the top. |
space_id |
No | Courses only: the space to bind. |
The response is 201 with the node object.
Rename, move, or bind a node
PATCH /nodes/NODE
Content-Type: application/json
{"parent": "ext:MEDICINE"}
Send only the fields you change. A field you leave out stays as it is.
| Field | What it does |
|---|---|
name |
Renames the node. |
external_id |
Sets a new external ID. null clears it. |
parent |
Moves the node, with everything under it, under another node. null moves a year to the top. |
space_id |
Binds a course to a space. null unbinds it. |
The response is 200 with the node object.
Delete a node
DELETE /nodes/NODE
The response is 204 with no body. A node with anything under it cannot be deleted: move or delete its children first. Deleting a course node leaves its space as it is.
Write limits
A key with both budgets.read and budgets.categories.write writes only inside its node. It can create, change, move, and delete nodes under its node, and rename its node. It cannot:
- Create a node at the top of the tree.
- Write to a node outside its node.
- Move a node out of its part of the tree.
- Move or delete its own node.
Each of these answers 403 BUDGET_OUTSIDE_YOUR_NODE and changes nothing.
Nobody can create, rename, move, or delete the Unassigned node.
Budget owners
The /owners endpoints, which manage who sees the money, take an org admin's session only. An API key gets 401 ORG_KEY_NOT_ALLOWED.
Errors
| Status | code |
When |
|---|---|---|
400 |
BUDGET_INVALID_PARENT |
The parent cannot hold a node of this kind, or a move would put a node under itself. details holds kind and parent_kind. |
400 |
BUDGET_SPACE_NOT_COURSE |
space_id is set on a node that is not a course. |
403 |
BUDGET_ACCESS_DENIED |
The caller sees no part of the tree. |
403 |
INSUFFICIENT_SCOPE |
The key lacks the scope the endpoint needs: budgets.read to read, budgets.categories.write to write. details.required names it. |
403 |
BUDGET_OUTSIDE_YOUR_NODE |
The node is outside the part of the tree the key can read or write. |
404 |
BUDGET_NODE_NOT_FOUND |
No node in the organization has this ID or external ID. |
404 |
BUDGET_SPACE_NOT_FOUND |
The space is missing, deleted, or in another organization. |
404 |
ORGANIZATION_NOT_FOUND |
ORG_ID is not the API key's organization. |
409 |
BUDGET_EXTERNAL_ID_TAKEN |
Another node has this external ID. |
409 |
BUDGET_SPACE_ALREADY_PLACED |
The space is already bound to another course node. |
409 |
BUDGET_NODE_NOT_EMPTY |
A delete of a node that has nodes under it. |
409 |
BUDGET_UNASSIGNED_MANAGED |
A create with kind unassigned, or a rename, move, or delete of the Unassigned node. |
422 |
VALIDATION_ERROR |
A field failed validation, for example a name over 200 characters. errors lists the fields. |
For the error body, see Errors.