Jump to content

Gadfly/API: Difference between revisions

From MindAttic Docs
md2wiki: sync from MindAttic.Docs
 
md2wiki: sync from MindAttic.Docs
Line 20: Line 20:
|-
|-
| Format
| Format
| <code>gfk_&lt;8 hex characters&gt;_&lt;secret&gt;</code>
| <code>gfk_&lt;8 hex characters>_&lt;secret></code>
|-
|-
| Scope
| Scope
Line 50: Line 50:
|-
|-
| GET
| GET
| <code>/api/v1/collections/&#123;id&#125;</code>
| <code>/api/v1/collections/{id}</code>
| One collection: status, documents, concept map version
| One collection: status, documents, concept map version
|-
|-
| POST
| POST
| <code>/api/v1/collections/&#123;id&#125;/documents</code>
| <code>/api/v1/collections/{id}/documents</code>
| Upload documents (multipart)
| Upload documents (multipart)
|-
|-
| POST
| POST
| <code>/api/v1/collections/&#123;id&#125;/process</code>
| <code>/api/v1/collections/{id}/process</code>
| Queue processing
| Queue processing
|-
|-
| GET
| GET
| <code>/api/v1/jobs/&#123;id&#125;</code>
| <code>/api/v1/jobs/{id}</code>
| Processing job status
| Processing job status
|-
|-
| GET
| GET
| <code>/api/v1/collections/&#123;id&#125;/concepts</code>
| <code>/api/v1/collections/{id}/concepts</code>
| The collection's concept map
| The collection's concept map
|-
|-
Line 74: Line 74:
|-
|-
| POST
| POST
| <code>/api/v1/exams/&#123;id&#125;/assignments</code>
| <code>/api/v1/exams/{id}/assignments</code>
| Provision a student and assign the exam
| Provision a student and assign the exam
|-
|-
| POST
| POST
| <code>/api/v1/assignments/&#123;id&#125;/launch</code>
| <code>/api/v1/assignments/{id}/launch</code>
| A signed launch link for the student
| A signed launch link for the student
|-
|-
| GET
| GET
| <code>/api/v1/assignments/&#123;id&#125;/sessions</code>
| <code>/api/v1/assignments/{id}/sessions</code>
| The student's attempts
| The student's attempts
|-
|-
| GET
| GET
| <code>/api/v1/sessions/&#123;id&#125;/result</code>
| <code>/api/v1/sessions/{id}/result</code>
| One attempt's result and report
| One attempt's result and report
|-
|-
| GET
| GET
| <code>/api/v1/sessions/&#123;id&#125;/transcript</code>
| <code>/api/v1/sessions/{id}/transcript</code>
| One attempt's official transcript (JSON, PDF, Word, web page, text, captions)
| One attempt's official transcript (JSON, PDF, Word, web page, text, captions)
|-
|-
Line 102: Line 102:
|-
|-
| DELETE
| DELETE
| <code>/api/v1/webhooks/&#123;id&#125;</code>
| <code>/api/v1/webhooks/{id}</code>
| Deactivate a webhook
| Deactivate a webhook
|-
|-
Line 116: Line 116:
<code>POST /api/v1/collections</code>
<code>POST /api/v1/collections</code>


<pre class="md-code lang-json">&#123; "title": "Biology 101: cells" &#125;</pre>
<pre class="md-code lang-json">{ "title": "Biology 101: cells" }</pre>


<code>201 Created</code>, <code>Location: /api/v1/collections/&#123;id&#125;</code>
<code>201 Created</code>, <code>Location: /api/v1/collections/{id}</code>


<pre class="md-code lang-json">&#123; "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10", "title": "Biology 101: cells" &#125;</pre>
<pre class="md-code lang-json">{ "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10", "title": "Biology 101: cells" }</pre>


<code>400</code> <code>&#123; "error": "title is required" &#125;</code> when the title is missing or blank, or <code>&#123; "error": "title must be at most 300 characters" &#125;</code>. The title is trimmed.
<code>400</code> <code>{ "error": "title is required" }</code> when the title is missing or blank, or <code>{ "error": "title must be at most 300 characters" }</code>. The title is trimmed.


=== List collections ===
=== List collections ===
Line 128: Line 128:
<code>GET /api/v1/collections</code>
<code>GET /api/v1/collections</code>


<pre class="md-code lang-json">&#91;
<pre class="md-code lang-json">[
   &#123;
   {
     "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
     "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
     "title": "Biology 101: cells",
     "title": "Biology 101: cells",
Line 137: Line 137:
     "conceptMapVersion": 3,
     "conceptMapVersion": 3,
     "createdAt": "2026-11-28T09:12:00+00:00",
     "createdAt": "2026-11-28T09:12:00+00:00",
     "latestJob": &#123;
     "latestJob": {
       "id": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a",
       "id": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a",
       "state": "Succeeded",
       "state": "Succeeded",
Line 145: Line 145:
       "createdAt": "2026-11-28T09:13:10+00:00",
       "createdAt": "2026-11-28T09:13:10+00:00",
       "completedAt": "2026-11-28T09:15:42+00:00"
       "completedAt": "2026-11-28T09:15:42+00:00"
     &#125;
     }
   &#125;
   }
&#93;</pre>
]</pre>


Newest first. <code>status</code> is <code>Pending</code>, <code>Processing</code>, <code>Ready</code> or <code>Failed</code>. <code>documentCount</code> counts uploaded and processed documents once each; <code>conceptCount</code> leaves out archived concepts. <code>latestJob</code> is the most recent processing job (its <code>state</code> as in [[#Job status|Job status]]), or <code>null</code> if the collection was never processed. An empty array when there are none.
Newest first. <code>status</code> is <code>Pending</code>, <code>Processing</code>, <code>Ready</code> or <code>Failed</code>. <code>documentCount</code> counts uploaded and processed documents once each; <code>conceptCount</code> leaves out archived concepts. <code>latestJob</code> is the most recent processing job (its <code>state</code> as in [[#Job status|Job status]]), or <code>null</code> if the collection was never processed. An empty array when there are none.
Line 153: Line 153:
=== Get a collection ===
=== Get a collection ===


<code>GET /api/v1/collections/&#123;id&#125;</code> (the <code>Location</code> returned when the collection was created)
<code>GET /api/v1/collections/{id}</code> (the <code>Location</code> returned when the collection was created)


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
   "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
   "title": "Biology 101: cells",
   "title": "Biology 101: cells",
Line 161: Line 161:
   "conceptMapVersion": 3,
   "conceptMapVersion": 3,
   "createdAt": "2026-11-28T09:12:00+00:00",
   "createdAt": "2026-11-28T09:12:00+00:00",
   "documents": &#91;
   "documents": [
     &#123;
     {
       "fileName": "chapter1.md",
       "fileName": "chapter1.md",
       "sizeBytes": 18234,
       "sizeBytes": 18234,
Line 172: Line 172:
       "ingestedAt": "2026-11-28T09:14:02+00:00",
       "ingestedAt": "2026-11-28T09:14:02+00:00",
       "error": null
       "error": null
     &#125;
     }
   &#93;,
   ],
   "latestJob": null
   "latestJob": null
&#125;</pre>
}</pre>


{| class="wikitable"
{| class="wikitable"
Line 184: Line 184:
| Goes up whenever the concept map or a rubric changes; <code>0</code> before the first processing.
| Goes up whenever the concept map or a rubric changes; <code>0</code> before the first processing.
|-
|-
| <code>documents&#91;&#93;.uploaded</code>
| <code>documents[].uploaded</code>
| The file is in the upload folder (<code>sizeBytes</code> and <code>uploadedAt</code> are <code>null</code> otherwise).
| The file is in the upload folder (<code>sizeBytes</code> and <code>uploadedAt</code> are <code>null</code> otherwise).
|-
|-
| <code>documents&#91;&#93;.ingested</code>
| <code>documents[].ingested</code>
| The document was processed successfully.
| The document was processed successfully.
|-
|-
| <code>documents&#91;&#93;.changedSinceIngest</code>
| <code>documents[].changedSinceIngest</code>
| The uploaded file differs from what was processed; process again to pick it up.
| The uploaded file differs from what was processed; process again to pick it up.
|-
|-
| <code>documents&#91;&#93;.error</code>
| <code>documents[].error</code>
| Why processing this document failed, or <code>null</code>.
| Why processing this document failed, or <code>null</code>.
|-
|-
Line 204: Line 204:
=== Upload documents ===
=== Upload documents ===


<code>POST /api/v1/collections/&#123;id&#125;/documents</code> with <code>multipart/form-data</code>, one or more file parts.
<code>POST /api/v1/collections/{id}/documents</code> with <code>multipart/form-data</code>, one or more file parts.


<pre class="md-code lang-bash">curl -X POST https&#58;//localhost:7311/api/v1/collections/6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10/documents \
<pre class="md-code lang-bash">curl -X POST https&#58;//localhost:7311/api/v1/collections/6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10/documents \
Line 212: Line 212:
<code>200 OK</code>
<code>200 OK</code>


<pre class="md-code lang-json">&#123; "saved": &#91;"chapter1.md", "chapter2.md"&#93; &#125;</pre>
<pre class="md-code lang-json">{ "saved": ["chapter1.md", "chapter2.md"] }</pre>


* Accepted: <code>.txt</code>, <code>.text</code>, <code>.md</code>, <code>.markdown</code>, <code>.pdf</code>, <code>.docx</code>, <code>.epub</code>, <code>.html</code> and <code>.htm</code> (the same as the source library page). A scanned, image-only PDF uploads but yields no text.
* Accepted: <code>.txt</code>, <code>.text</code>, <code>.md</code>, <code>.markdown</code>, <code>.pdf</code>, <code>.docx</code>, <code>.epub</code>, <code>.html</code> and <code>.htm</code> (the same as the source library page). A scanned, image-only PDF uploads but yields no text.
Line 222: Line 222:
<code>404</code> when the collection isn't in your organization. <code>400</code> with one of:
<code>404</code> when the collection isn't in your organization. <code>400</code> with one of:


* <code>&#123; "error": "send multipart/form-data with one or more files" &#125;</code>
* <code>{ "error": "send multipart/form-data with one or more files" }</code>
* <code>&#123; "error": "&lt;file&gt;: only .txt, .text, .md, .markdown files are accepted for now" &#125;</code>
* <code>{ "error": "&lt;file>: only .txt, .text, .md, .markdown files are accepted for now" }</code>
* <code>&#123; "error": "&lt;file&gt;: CON is a reserved device name; rename the file" &#125;</code>
* <code>{ "error": "&lt;file>: CON is a reserved device name; rename the file" }</code>
* <code>&#123; "error": "&lt;file&gt;: files must be 1 byte to 20 MB" &#125;</code>
* <code>{ "error": "&lt;file>: files must be 1 byte to 20 MB" }</code>
* <code>&#123; "error": "&lt;file&gt;: the file needs a name" &#125;</code>
* <code>{ "error": "&lt;file>: the file needs a name" }</code>
* <code>&#123; "error": "the upload could not be read: ..." &#125;</code> (a malformed multipart body)
* <code>{ "error": "the upload could not be read: ..." }</code> (a malformed multipart body)


=== Process a collection ===
=== Process a collection ===


<code>POST /api/v1/collections/&#123;id&#125;/process</code>
<code>POST /api/v1/collections/{id}/process</code>


<pre class="md-code lang-json">&#123; "rebuildConceptMap": false &#125;</pre>
<pre class="md-code lang-json">{ "rebuildConceptMap": false }</pre>


The body is optional. Processing reads new and changed documents, has the AI panel extract the concept map (concepts are re-extracted only when a document changed, unless <code>rebuildConceptMap</code> is <code>true</code>), and writes a rubric per concept. Concepts and rubrics an instructor edited are kept.
The body is optional. Processing reads new and changed documents, has the AI panel extract the concept map (concepts are re-extracted only when a document changed, unless <code>rebuildConceptMap</code> is <code>true</code>), and writes a rubric per concept. Concepts and rubrics an instructor edited are kept.


<code>202 Accepted</code>, <code>Location: /api/v1/jobs/&#123;jobId&#125;</code>
<code>202 Accepted</code>, <code>Location: /api/v1/jobs/{jobId}</code>


<pre class="md-code lang-json">&#123; "jobId": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a" &#125;</pre>
<pre class="md-code lang-json">{ "jobId": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a" }</pre>


<code>404</code> when the collection isn't in your organization. <code>409</code> <code>&#123; "error": "this collection is already being processed (job &lt;jobId&gt;, Queued)" &#125;</code> while a processing job for it is <code>Queued</code> or <code>Running</code>: poll that job instead of queuing another. <code>400</code> <code>&#123; "error": "upload at least one document first (.txt, .text, .md, .markdown)" &#125;</code> when the collection has no readable, non-empty uploaded file.
<code>404</code> when the collection isn't in your organization. <code>409</code> <code>{ "error": "this collection is already being processed (job &lt;jobId>, Queued)" }</code> while a processing job for it is <code>Queued</code> or <code>Running</code>: poll that job instead of queuing another. <code>400</code> <code>{ "error": "upload at least one document first (.txt, .text, .md, .markdown)" }</code> when the collection has no readable, non-empty uploaded file.


=== Job status ===
=== Job status ===


<code>GET /api/v1/jobs/&#123;id&#125;</code>
<code>GET /api/v1/jobs/{id}</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "id": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a",
   "id": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a",
   "kind": "source.process",
   "kind": "source.process",
Line 255: Line 255:
   "error": null,
   "error": null,
   "completedAt": null
   "completedAt": null
&#125;</pre>
}</pre>


<code>state</code> is <code>Queued</code>, <code>Running</code>, <code>Succeeded</code>, <code>Failed</code> or <code>Cancelled</code>; <code>progress</code> runs from 0 to 1. A failed run is retried a few times with growing waits (the job goes back to <code>Queued</code> with the last <code>error</code>); <code>Failed</code> is final. Poll every few seconds. <code>404</code> for a job that isn't your organization's.
<code>state</code> is <code>Queued</code>, <code>Running</code>, <code>Succeeded</code>, <code>Failed</code> or <code>Cancelled</code>; <code>progress</code> runs from 0 to 1. A failed run is retried a few times with growing waits (the job goes back to <code>Queued</code> with the last <code>error</code>); <code>Failed</code> is final. Poll every few seconds. <code>404</code> for a job that isn't your organization's.
Line 261: Line 261:
=== Concept map ===
=== Concept map ===


<code>GET /api/v1/collections/&#123;id&#125;/concepts</code>
<code>GET /api/v1/collections/{id}/concepts</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "version": 3,
   "version": 3,
   "concepts": &#91;
   "concepts": [
     &#123; "key": "osmosis", "title": "Osmosis", "definition": "The movement of water across a semi-permeable membrane from lower to higher solute concentration." &#125;,
     { "key": "osmosis", "title": "Osmosis", "definition": "The movement of water across a semi-permeable membrane from lower to higher solute concentration." },
     &#123; "key": "diffusion", "title": "Diffusion", "definition": "The net movement of particles from higher to lower concentration." &#125;
     { "key": "diffusion", "title": "Diffusion", "definition": "The net movement of particles from higher to lower concentration." }
   &#93;,
   ],
   "relations": &#91;
   "relations": [
     &#123; "from": "diffusion", "to": "osmosis", "kind": "prerequisite" &#125;
     { "from": "diffusion", "to": "osmosis", "kind": "prerequisite" }
   &#93;
   ]
&#125;</pre>
}</pre>


Archived concepts are left out. <code>404</code> until the collection has been processed.
Archived concepts are left out. <code>404</code> until the collection has been processed.
Line 280: Line 280:
<code>POST /api/v1/exams</code>
<code>POST /api/v1/exams</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "collectionId": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
   "collectionId": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
   "title": "Cells: oral check",
   "title": "Cells: oral check",
   "conceptKeys": &#91;"diffusion", "osmosis"&#93;,
   "conceptKeys": ["diffusion", "osmosis"],
   "minutes": 20,
   "minutes": 20,
   "difficulty": 3,
   "difficulty": 3,
   "maxTurns": 30,
   "maxTurns": 30,
   "mode": "Voice",
   "mode": "Voice",
   "instructions": "Explain in your own words. &#39;I don&#39;t know&#39; is fine."
   "instructions": "Explain in your own words. 'I don't know' is fine."
&#125;</pre>
}</pre>


{| class="wikitable"
{| class="wikitable"
Line 331: Line 331:
The exam is <strong>published immediately</strong>, so its settings are frozen. Each concept gets up to six questions; integrity monitoring is Standard.
The exam is <strong>published immediately</strong>, so its settings are frozen. Each concept gets up to six questions; integrity monitoring is Standard.


<code>201 Created</code>, <code>Location: /api/v1/exams/&#123;id&#125;</code>
<code>201 Created</code>, <code>Location: /api/v1/exams/{id}</code>


<pre class="md-code lang-json">&#123; "id": "a4e2d5c8-0b3f-4d91-8e7a-5c6b1f2e3d40", "conceptKeys": &#91;"diffusion", "osmosis"&#93; &#125;</pre>
<pre class="md-code lang-json">{ "id": "a4e2d5c8-0b3f-4d91-8e7a-5c6b1f2e3d40", "conceptKeys": ["diffusion", "osmosis"] }</pre>


<code>400</code> with one of <code>&#123; "error": "title is required" &#125;</code>, <code>&#123; "error": "title must be at most 300 characters" &#125;</code>, <code>&#123; "error": "collectionId is required" &#125;</code>, <code>&#123; "error": "conceptKeys must not contain blank keys" &#125;</code>, <code>&#123; "error": "mode must be \"Text\" or \"Voice\"" &#125;</code>, <code>&#123; "error": "the collection has no concept map yet; process it first" &#125;</code> (also for a collection that isn't yours), <code>&#123; "error": "unknown concept keys", "unknown": &#91;"mitosis"&#93; &#125;</code>, or a settings error.
<code>400</code> with one of <code>{ "error": "title is required" }</code>, <code>{ "error": "title must be at most 300 characters" }</code>, <code>{ "error": "collectionId is required" }</code>, <code>{ "error": "conceptKeys must not contain blank keys" }</code>, <code>{ "error": "mode must be \"Text\" or \"Voice\"" }</code>, <code>{ "error": "the collection has no concept map yet; process it first" }</code> (also for a collection that isn't yours), <code>{ "error": "unknown concept keys", "unknown": ["mitosis"] }</code>, or a settings error.


=== Assign a student ===
=== Assign a student ===


<code>POST /api/v1/exams/&#123;id&#125;/assignments</code>
<code>POST /api/v1/exams/{id}/assignments</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "userName": "jsmith",
   "userName": "jsmith",
   "email": "jsmith@example.edu",
   "email": "jsmith@example.edu",
Line 347: Line 347:
   "closesAt": "2026-12-08T17:00:00Z",
   "closesAt": "2026-12-08T17:00:00Z",
   "attemptsAllowed": 1
   "attemptsAllowed": 1
&#125;</pre>
}</pre>


This assigns the exam to a student of your organization, creating the student if the user name is new:
This assigns the exam to a student of your organization, creating the student if the user name is new:
Line 362: Line 362:
<code>200 OK</code>
<code>200 OK</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
   "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
   "studentUserId": "9e3b6a1d-2c4f-4e58-b7a0-d1f6c8e2a934",
   "studentUserId": "9e3b6a1d-2c4f-4e58-b7a0-d1f6c8e2a934",
   "created": true,
   "created": true,
   "temporaryPassword": "REDACTED"
   "temporaryPassword": "REDACTED"
&#125;</pre>
}</pre>


<code>404</code> when the exam doesn't exist or isn't published. <code>400</code> <code>&#123; "error": "userName is required" &#125;</code>, <code>&#123; "error": "attemptsAllowed must be at least 1" &#125;</code>, <code>&#123; "error": "closesAt must be after opensAt" &#125;</code>, or the reason the account can't be created (for example a user name the sign-in library rejects). <code>409</code> with an <code>error</code> for the cases above, for example <code>&#123; "error": "the user name &#39;jsmith&#39; belongs to an existing Gadfly account that is not a member of your organization; use a distinct user name (...)" &#125;</code> or <code>&#123; "error": "&#39;jsmith&#39; has the Instructor role in your organization; only students can be assigned exams, and the API never changes a member&#39;s role" &#125;</code>.
<code>404</code> when the exam doesn't exist or isn't published. <code>400</code> <code>{ "error": "userName is required" }</code>, <code>{ "error": "attemptsAllowed must be at least 1" }</code>, <code>{ "error": "closesAt must be after opensAt" }</code>, or the reason the account can't be created (for example a user name the sign-in library rejects). <code>409</code> with an <code>error</code> for the cases above, for example <code>{ "error": "the user name 'jsmith' belongs to an existing Gadfly account that is not a member of your organization; use a distinct user name (...)" }</code> or <code>{ "error": "'jsmith' has the Instructor role in your organization; only students can be assigned exams, and the API never changes a member's role" }</code>.


=== Launch link ===
=== Launch link ===


<code>POST /api/v1/assignments/&#123;id&#125;/launch</code> (no body)
<code>POST /api/v1/assignments/{id}/launch</code> (no body)


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "url": "https&#58;//localhost:7311/launch?token=CfDJ8...",
   "url": "https&#58;//localhost:7311/launch?token=CfDJ8...",
   "expiresInSeconds": 900
   "expiresInSeconds": 900
&#125;</pre>
}</pre>


<code>404</code> when the assignment isn't your organization's. See [[#Launch-link flow|the launch-link flow]].
<code>404</code> when the assignment isn't your organization's. See [[#Launch-link flow|the launch-link flow]].
Line 384: Line 384:
=== Attempts ===
=== Attempts ===


<code>GET /api/v1/assignments/&#123;id&#125;/sessions</code>
<code>GET /api/v1/assignments/{id}/sessions</code>


<pre class="md-code lang-json">&#91;
<pre class="md-code lang-json">[
   &#123;
   {
     "id": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
     "id": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
     "attempt": 1,
     "attempt": 1,
Line 394: Line 394:
     "endedAt": "2026-12-02T14:19:47+00:00",
     "endedAt": "2026-12-02T14:19:47+00:00",
     "endReason": "Mastery"
     "endReason": "Mastery"
   &#125;
   }
&#93;</pre>
]</pre>


<code>state</code> is <code>Created</code> (opened, notice not yet accepted), <code>ConsentGiven</code>, <code>Running</code>, <code>Paused</code>, <code>Ended</code> or <code>Failed</code>. <code>endReason</code> is <code>Mastery</code>, <code>Aporia</code>, <code>TimeUp</code>, <code>TurnLimit</code>, <code>Abandoned</code> (the student pressed Finish) or <code>Failed</code>, and <code>null</code> while running. An empty array when there are none.
<code>state</code> is <code>Created</code> (opened, notice not yet accepted), <code>ConsentGiven</code>, <code>Running</code>, <code>Paused</code>, <code>Ended</code> or <code>Failed</code>. <code>endReason</code> is <code>Mastery</code>, <code>Aporia</code>, <code>TimeUp</code>, <code>TurnLimit</code>, <code>Abandoned</code> (the student pressed Finish) or <code>Failed</code>, and <code>null</code> while running. An empty array when there are none.
Line 401: Line 401:
=== Result ===
=== Result ===


<code>GET /api/v1/sessions/&#123;id&#125;/result</code>
<code>GET /api/v1/sessions/{id}/result</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "id": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
   "id": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
   "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
   "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
Line 411: Line 411:
   "endedAt": "2026-12-02T14:19:47+00:00",
   "endedAt": "2026-12-02T14:19:47+00:00",
   "endReason": "Mastery",
   "endReason": "Mastery",
   "objectiveLevels": &#91;
   "objectiveLevels": [
     &#123; "title": "Explain osmosis", "level": 4, "label": "Application", "insufficient": false &#125;,
     { "title": "Explain osmosis", "level": 4, "label": "Application", "insufficient": false },
     &#123; "title": "Predict water movement", "level": 0, "label": "Insufficient Evidence for Reliable Assessment", "insufficient": true &#125;
     { "title": "Predict water movement", "level": 0, "label": "Insufficient Evidence for Reliable Assessment", "insufficient": true }
   &#93;,
   ],
   "recommendation": "mastered",
   "recommendation": "mastered",
   "overallScore": 0.86,
   "overallScore": 0.86,
   "report": &#123;
   "report": {
     "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
     "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
     "subjectId": "...",
     "subjectId": "...",
Line 426: Line 426:
     "recommendation": "mastered",
     "recommendation": "mastered",
     "overallScore": 0.86,
     "overallScore": 0.86,
     "concepts": &#91;
     "concepts": [
       &#123;
       {
         "conceptId": "osmosis",
         "conceptId": "osmosis",
         "title": "Osmosis",
         "title": "Osmosis",
Line 434: Line 434:
         "turns": 3,
         "turns": 3,
         "averageScore": 0.81,
         "averageScore": 0.81,
         "evidence": &#91;
         "evidence": [
           &#123;
           {
             "turnIndex": 4,
             "turnIndex": 4,
             "move": "Apply",
             "move": "Apply",
Line 442: Line 442:
             "score": 0.9,
             "score": 0.9,
             "judgeSummary": "Correct direction and reason ...",
             "judgeSummary": "Correct direction and reason ...",
             "citations": &#91;&#123; "chunkId": "1d2e3f40a5b6c7d8e9f0a1b2c3d4e5f6", "quote": "..." &#125;&#93;
             "citations": [{ "chunkId": "1d2e3f40a5b6c7d8e9f0a1b2c3d4e5f6", "quote": "..." }]
           &#125;
           }
         &#93;,
         ],
         "disputedTurns": &#91;&#93;
         "disputedTurns": []
       &#125;
       }
     &#93;,
     ],
     "turnsJudged": 6,
     "turnsJudged": 6,
     "turnsNeedingReview": 0
     "turnsNeedingReview": 0
   &#125;,
   },
   "grade": &#123;
   "grade": {
     "grade": "A",
     "grade": "A",
     "score": 88,
     "score": 88,
     "comment": "Clear on osmosis; revisit active transport.",
     "comment": "Clear on osmosis; revisit active transport.",
     "decidedAt": "2026-12-03T10:12:00+00:00"
     "decidedAt": "2026-12-03T10:12:00+00:00"
   &#125;
   }
&#125;</pre>
}</pre>


{| class="wikitable"
{| class="wikitable"
Line 493: Line 493:
=== Transcript ===
=== Transcript ===


<code>GET /api/v1/sessions/&#123;id&#125;/transcript?format=json&amp;audience=reviewer</code>
<code>GET /api/v1/sessions/{id}/transcript?format=json&audience=reviewer</code>


The attempt's official transcript, built from the response ledger (GAD-T295): every question with its clock time, its offset from the start of the exam and the examiner's move; every answer exactly as recorded; the read-back and its outcome; meaning clarifications; every transcription correction as original and corrected text; the response delay and pauses; and the words the speech recognizer was unsure of.
The attempt's official transcript, built from the response ledger (GAD-T295): every question with its clock time, its offset from the start of the exam and the examiner's move; every answer exactly as recorded; the read-back and its outcome; meaning clarifications; every transcription correction as original and corrected text; the response delay and pauses; and the words the speech recognizer was unsure of.
Line 510: Line 510:
Every response carries the copy's <code>X-Transcript-Code</code> (the verification code, e.g. <code>7K3M-9QXA-B2CD-EFGH</code>) and <code>X-Transcript-Sha256</code> headers, and every call is recorded in the audit log as <code>transcript.issued</code>. The JSON download is:
Every response carries the copy's <code>X-Transcript-Code</code> (the verification code, e.g. <code>7K3M-9QXA-B2CD-EFGH</code>) and <code>X-Transcript-Sha256</code> headers, and every call is recorded in the audit log as <code>transcript.issued</code>. The JSON download is:


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "transcript": &#123;
   "transcript": {
     "schema": "gadfly.transcript/1",
     "schema": "gadfly.transcript/1",
     "audience": "reviewer",
     "audience": "reviewer",
Line 519: Line 519:
     "attempt": 1,
     "attempt": 1,
     "mode": "Spoken",
     "mode": "Spoken",
     "turns": &#91;
     "turns": [
       &#123;
       {
         "number": 1,
         "number": 1,
         "concept": "Osmosis",
         "concept": "Osmosis",
Line 528: Line 528:
         "offsetSeconds": 5,
         "offsetSeconds": 5,
         "question": "What is osmosis, in your own words?",
         "question": "What is osmosis, in your own words?",
         "responses": &#91;
         "responses": [
           &#123;
           {
             "kind": "Answer",
             "kind": "Answer",
             "modality": "Spoken",
             "modality": "Spoken",
Line 537: Line 537:
             "delaySeconds": 4,
             "delaySeconds": 4,
             "pauses": 2,
             "pauses": 2,
             "readBack": &#123; "prompt": "I recorded your answer as: ...", "outcome": "The student corrected the recording." &#125;,
             "readBack": { "prompt": "I recorded your answer as: ...", "outcome": "The student corrected the recording." },
             "corrections": &#91;&#123; "version": 2, "original": "Water moves a cross a membrane.", "corrected": "Water moves across a membrane.", "by": "the student" &#125;&#93;,
             "corrections": [{ "version": 2, "original": "Water moves a cross a membrane.", "corrected": "Water moves across a membrane.", "by": "the student" }],
             "unsureWords": &#91;&#123; "text": "a cross", "startSeconds": 1.1, "endSeconds": 1.6, "lowestConfidence": 0.4 &#125;&#93;,
             "unsureWords": [{ "text": "a cross", "startSeconds": 1.1, "endSeconds": 1.6, "lowestConfidence": 0.4 }],
             "words": &#91;&#123; "text": "Water", "startSeconds": 0, "endSeconds": 0.5 &#125;&#93;
             "words": [{ "text": "Water", "startSeconds": 0, "endSeconds": 0.5 }]
           &#125;
           }
         &#93;
         ]
       &#125;
       }
     &#93;,
     ],
     "leftOut": &#91;&#93;
     "leftOut": []
   &#125;,
   },
   "verification": &#123;
   "verification": {
     "sha256": "3f0c...",
     "sha256": "3f0c...",
     "code": "7K3M-9QXA-B2CD-EFGH",
     "code": "7K3M-9QXA-B2CD-EFGH",
     "generatedAt": "2026-12-03T09:00:00+00:00",
     "generatedAt": "2026-12-03T09:00:00+00:00",
     "verifyUrl": "https&#58;//exams.example.org/transcripts/verify?code=7K3M-9QXA-B2CD-EFGH"
     "verifyUrl": "https&#58;//exams.example.org/transcripts/verify?code=7K3M-9QXA-B2CD-EFGH"
   &#125;
   }
&#125;</pre>
}</pre>


The hash is the SHA-256 of the canonical JSON of <code>transcript</code> (object keys in ordinal order, nulls left out, no whitespace, UTF-8); the code is its first 80 bits in Crockford base 32. Nothing that changes between downloads is inside <code>transcript</code>, so the same record always gives the same code. Anyone can check a code or the JSON file at <code>/transcripts/verify</code> (no sign-in, rate-limited); it says only whether the copy matches the record.
The hash is the SHA-256 of the canonical JSON of <code>transcript</code> (object keys in ordinal order, nulls left out, no whitespace, UTF-8); the code is its first 80 bits in Crockford base 32. Nothing that changes between downloads is inside <code>transcript</code>, so the same record always gives the same code. Anyone can check a code or the JSON file at <code>/transcripts/verify</code> (no sign-in, rate-limited); it says only whether the copy matches the record.


The same page also recognizes a completion certificate's code (GAD-T311/GAD-T379: <code>/certificates/&#123;sessionId&#125;/pdf</code>), built the same way (a canonical, deterministic JSON record of the certificate's content, hashed and coded exactly like a transcript) and checked against a freshly-rebuilt certificate, so a later amendment to the grade shows as "the record has changed since" rather than silently matching. There is no separate <code>/certificates/verify</code> page: a typed code is checked against transcripts first, then certificates. A certificate has no JSON download, so only its code can be checked, never an uploaded file.
The same page also recognizes a completion certificate's code (GAD-T311/GAD-T379: <code>/certificates/{sessionId}/pdf</code>), built the same way (a canonical, deterministic JSON record of the certificate's content, hashed and coded exactly like a transcript) and checked against a freshly-rebuilt certificate, so a later amendment to the grade shows as "the record has changed since" rather than silently matching. There is no separate <code>/certificates/verify</code> page: a typed code is checked against transcripts first, then certificates. A certificate has no JSON download, so only its code can be checked, never an uploaded file.


=== Webhook registration ===
=== Webhook registration ===
Line 563: Line 563:
<code>POST /api/v1/webhooks</code>
<code>POST /api/v1/webhooks</code>


<pre class="md-code lang-json">&#123; "url": "https&#58;//lms.example.edu/hooks/gadfly", "events": &#91;"session.completed"&#93; &#125;</pre>
<pre class="md-code lang-json">{ "url": "https&#58;//lms.example.edu/hooks/gadfly", "events": ["session.completed"] }</pre>


<code>201 Created</code>, <code>Location: /api/v1/webhooks/&#123;id&#125;</code>
<code>201 Created</code>, <code>Location: /api/v1/webhooks/{id}</code>


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "id": "e8b4c1d6-9a2f-4b3e-8d7c-6f5a4e3d2c1b",
   "id": "e8b4c1d6-9a2f-4b3e-8d7c-6f5a4e3d2c1b",
   "url": "https&#58;//lms.example.edu/hooks/gadfly",
   "url": "https&#58;//lms.example.edu/hooks/gadfly",
   "events": &#91;"session.completed"&#93;,
   "events": ["session.completed"],
   "secret": "REDACTED"
   "secret": "REDACTED"
&#125;</pre>
}</pre>


Store <code>secret</code>: it is shown only here. A runnable receiver that verifies the signature is [https://github.com/mindattic/Gadfly/tree/main/samples/HostedApi samples/HostedApi]. For local development only, a server running in the Development environment accepts <code>https&#58;//localhost</code> and other private targets when <code>Gadfly:Webhooks:AllowPrivateTargets</code> is <code>true</code>; production never does. <code>400</code> <code>&#123; "error": "Webhook URLs must be absolute https URLs." &#125;</code>, <code>&#123; "error": "Webhook URLs must be at most 1000 characters." &#125;</code>, <code>&#123; "error": "Webhook URLs must name a public host." &#125;</code> (localhost, <code>.local</code>, <code>.internal</code> and single-label names), <code>&#123; "error": "Webhook URLs must not point at private, loopback or link-local addresses." &#125;</code> or <code>&#123; "error": "Subscribe to at least one of: session.completed." &#125;</code> (also when <code>events</code> is missing). Unknown event names are ignored.
Store <code>secret</code>: it is shown only here. A runnable receiver that verifies the signature is [https://github.com/mindattic/Gadfly/tree/main/samples/HostedApi samples/HostedApi]. For local development only, a server running in the Development environment accepts <code>https&#58;//localhost</code> and other private targets when <code>Gadfly:Webhooks:AllowPrivateTargets</code> is <code>true</code>; production never does. <code>400</code> <code>{ "error": "Webhook URLs must be absolute https URLs." }</code>, <code>{ "error": "Webhook URLs must be at most 1000 characters." }</code>, <code>{ "error": "Webhook URLs must name a public host." }</code> (localhost, <code>.local</code>, <code>.internal</code> and single-label names), <code>{ "error": "Webhook URLs must not point at private, loopback or link-local addresses." }</code> or <code>{ "error": "Subscribe to at least one of: session.completed." }</code> (also when <code>events</code> is missing). Unknown event names are ignored.


<code>GET /api/v1/webhooks</code>
<code>GET /api/v1/webhooks</code>


<pre class="md-code lang-json">&#91;
<pre class="md-code lang-json">[
   &#123;
   {
     "id": "e8b4c1d6-9a2f-4b3e-8d7c-6f5a4e3d2c1b",
     "id": "e8b4c1d6-9a2f-4b3e-8d7c-6f5a4e3d2c1b",
     "url": "https&#58;//lms.example.edu/hooks/gadfly",
     "url": "https&#58;//lms.example.edu/hooks/gadfly",
     "events": &#91;"session.completed"&#93;,
     "events": ["session.completed"],
     "isActive": true,
     "isActive": true,
     "createdAt": "2026-11-28T09:30:00+00:00"
     "createdAt": "2026-11-28T09:30:00+00:00"
   &#125;
   }
&#93;</pre>
]</pre>


Oldest first, including deactivated webhooks (<code>isActive: false</code>). <code>events</code> is an array, as everywhere in the API. Secrets are never listed.
Oldest first, including deactivated webhooks (<code>isActive: false</code>). <code>events</code> is an array, as everywhere in the API. Secrets are never listed.


<code>DELETE /api/v1/webhooks/&#123;id&#125;</code> deactivates the webhook: <code>204 No Content</code>, or <code>404</code>. Deliveries still waiting for it are dropped.
<code>DELETE /api/v1/webhooks/{id}</code> deactivates the webhook: <code>204 No Content</code>, or <code>404</code>. Deliveries still waiting for it are dropped.


== Launch-link flow ==
== Launch-link flow ==
Line 596: Line 596:
A launch link takes a student from your app straight to the exam's get-ready page.
A launch link takes a student from your app straight to the exam's get-ready page.


# Your app assigns the exam (<code>POST /api/v1/exams/&#123;id&#125;/assignments</code>) and keeps the <code>assignmentId</code>.
# Your app assigns the exam (<code>POST /api/v1/exams/{id}/assignments</code>) and keeps the <code>assignmentId</code>.
# When the student clicks "Start exam" in your app, call <code>POST /api/v1/assignments/&#123;assignmentId&#125;/launch</code> and redirect the student's browser to the returned <code>url</code>. Ask for a fresh link each time: it is signed by the server and <strong>expires after 15 minutes</strong>.
# When the student clicks "Start exam" in your app, call <code>POST /api/v1/assignments/{assignmentId}/launch</code> and redirect the student's browser to the returned <code>url</code>. Ask for a fresh link each time: it is signed by the server and <strong>expires after 15 minutes</strong>.
# Gadfly checks the link at <code>/launch</code>:
# Gadfly checks the link at <code>/launch</code>:
#* not signed in: the student is sent to the sign-in page and then on to the exam;
#* not signed in: the student is sent to the sign-in page and then on to the exam;
#* signed in as the student the link was made for: straight to the exam's get-ready page (<code>/my-exams/&#123;assignmentId&#125;/start</code>);
#* signed in as the student the link was made for: straight to the exam's get-ready page (<code>/my-exams/{assignmentId}/start</code>);
#* signed in as someone else: "This exam link belongs to a different student";
#* signed in as someone else: "This exam link belongs to a different student";
#* expired or altered: "This exam link has expired or is not valid. Ask for a new one."
#* expired or altered: "This exam link has expired or is not valid. Ask for a new one."
# The student runs the system check, accepts the notice and takes the exam.
# The student runs the system check, accepts the notice and takes the exam.
# When the attempt ends you receive <code>session.completed</code>, then read <code>GET /api/v1/sessions/&#123;sessionId&#125;/result</code>.
# When the attempt ends you receive <code>session.completed</code>, then read <code>GET /api/v1/sessions/{sessionId}/result</code>.


The student still signs in with their Gadfly user name and password; one-click sign-in from an API launch link needs trusted-launch support in MindAttic.Authentication and is not built. For one-click launch from an LMS, use the LTI 1.3 connection below, which signs the student in.
The student still signs in with their Gadfly user name and password; one-click sign-in from an API launch link needs trusted-launch support in MindAttic.Authentication and is not built. For one-click launch from an LMS, use the LTI 1.3 connection below, which signs the student in.
Line 623: Line 623:
| <code>POST /lti/launch</code>
| <code>POST /lti/launch</code>
| the platform (form post of <code>id_token</code> and <code>state</code>)
| the platform (form post of <code>id_token</code> and <code>state</code>)
| The redirect URI, target link URI and deep-linking URL. Validates the launch (below), then: a deep-linking request shows instructors the exam picker; a resource-link request signs a student in and opens <code>/my-exams/&#123;assignmentId&#125;/start</code> (inside a frame it offers an "open in a new window" button instead); an instructor is told the placement is linked and pointed at the normal MFA sign-in.
| The redirect URI, target link URI and deep-linking URL. Validates the launch (below), then: a deep-linking request shows instructors the exam picker; a resource-link request signs a student in and opens <code>/my-exams/{assignmentId}/start</code> (inside a frame it offers an "open in a new window" button instead); an instructor is told the placement is linked and pointed at the normal MFA sign-in.
|-
|-
| <code>GET /lti/jwks.json</code>
| <code>GET /lti/jwks.json</code>
| the platform
| the platform
| Gadfly's public key set (<code>&#123;"keys":&#91;&#123;"kty":"RSA","kid":…,"use":"sig","alg":"RS256","n":…,"e":…&#125;&#93;&#125;</code>), for verifying the deep-linking response and the client assertion. Cached 5 minutes.
| Gadfly's public key set (<code>{"keys":[{"kty":"RSA","kid":…,"use":"sig","alg":"RS256","n":…,"e":…}]}</code>), for verifying the deep-linking response and the client assertion. Cached 5 minutes.
|-
|-
| <code>POST /lti/deep-link/submit</code>
| <code>POST /lti/deep-link/submit</code>
Line 654: Line 654:
<strong>Roster (NRPS).</strong> An admin syncs a placement's course roster from the LMS connection page, and each connection also refreshes its rosters through the job queue every <code>RosterRefreshHours</code> (24 by default, 0 for on request only); Gadfly reads every page of the membership container (following <code>Link: rel="next"</code>), skips inactive and deleted members, and maps the rest exactly as a launch would.
<strong>Roster (NRPS).</strong> An admin syncs a placement's course roster from the LMS connection page, and each connection also refreshes its rosters through the job queue every <code>RosterRefreshHours</code> (24 by default, 0 for on request only); Gadfly reads every page of the membership container (following <code>Link: rel="next"</code>), skips inactive and deleted members, and maps the rest exactly as a launch would.


<strong>Grades (AGS).</strong> Within about two minutes of a result being released to the student (finalized and published with approval), Gadfly posts the latest attempt's final percentage to the placement's line item: <code>POST &#123;lineitem&#125;/scores</code>, <code>application/vnd.ims.lis.v1.score+json</code>, <code>scoreGiven</code> 0 to 100, <code>scoreMaximum</code> 100, <code>activityProgress</code> <code>Completed</code>, <code>gradingProgress</code> <code>FullyGraded</code>. If the launch gave only a line-items collection, Gadfly creates the line item first. An amended grade is sent again; an unchanged one never is. Integrity notes are never sent. A send the platform refuses or doesn't answer is retried after 2 minutes, then 4, 8 and so on (at most 12 hours apart), up to 8 tries; then it is marked failed on the LMS connection page until an admin retries it or the grade changes. Service tokens come from the platform's token endpoint with a signed RS256 client assertion (RFC 7523), audience the token URL or the connection's token audience (Brightspace).
<strong>Grades (AGS).</strong> Within about two minutes of a result being released to the student (finalized and published with approval), Gadfly posts the latest attempt's final percentage to the placement's line item: <code>POST {lineitem}/scores</code>, <code>application/vnd.ims.lis.v1.score+json</code>, <code>scoreGiven</code> 0 to 100, <code>scoreMaximum</code> 100, <code>activityProgress</code> <code>Completed</code>, <code>gradingProgress</code> <code>FullyGraded</code>. If the launch gave only a line-items collection, Gadfly creates the line item first. An amended grade is sent again; an unchanged one never is. Integrity notes are never sent. A send the platform refuses or doesn't answer is retried after 2 minutes, then 4, 8 and so on (at most 12 hours apart), up to 8 tries; then it is marked failed on the LMS connection page until an admin retries it or the grade changes. Service tokens come from the platform's token endpoint with a signed RS256 client assertion (RFC 7523), audience the token URL or the connection's token audience (Brightspace).


All outgoing calls (key set, token, roster, gradebook) go only to public https hosts, checked after DNS resolution, without following redirects.
All outgoing calls (key set, token, roster, gradebook) go only to public https hosts, checked after DNS resolution, without following redirects.
Line 666: Line 666:
Each delivery is a <code>POST</code> with a JSON body:
Each delivery is a <code>POST</code> with a JSON body:


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "type": "session.completed",
   "type": "session.completed",
   "createdAt": "2026-12-02T14:19:48.1234567+00:00",
   "createdAt": "2026-12-02T14:19:48.1234567+00:00",
   "data": &#123;
   "data": {
     "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
     "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
     "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
     "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
Line 675: Line 675:
     "examId": "a4e2d5c8-0b3f-4d91-8e7a-5c6b1f2e3d40",
     "examId": "a4e2d5c8-0b3f-4d91-8e7a-5c6b1f2e3d40",
     "endReason": "Mastery",
     "endReason": "Mastery",
     "objectiveLevels": &#91;&#123; "title": "Explain osmosis", "level": 4, "label": "Application", "insufficient": false &#125;&#93;,
     "objectiveLevels": [{ "title": "Explain osmosis", "level": 4, "label": "Application", "insufficient": false }],
     "recommendation": "mastered",
     "recommendation": "mastered",
     "overallScore": 0.86
     "overallScore": 0.86
   &#125;
   }
&#125;</pre>
}</pre>


<code>session.completed</code> is sent once per attempt, when it ends for any reason. <code>objectiveLevels</code> is the AI's result per learning objective; <code>recommendation</code> and <code>overallScore</code> are deprecated steering values, not a score, proposed for removal in V4 (see Result). The instructor's grade comes later; read it from the result endpoint.
<code>session.completed</code> is sent once per attempt, when it ends for any reason. <code>objectiveLevels</code> is the AI's result per learning objective; <code>recommendation</code> and <code>overallScore</code> are deprecated steering values, not a score, proposed for removal in V4 (see Result). The instructor's grade comes later; read it from the result endpoint.
Line 697: Line 697:
|-
|-
| <code>X-Gadfly-Signature</code>
| <code>X-Gadfly-Signature</code>
| <code>t=&lt;unix seconds&gt;,v1=&lt;hex HMAC-SHA256&gt;</code>
| <code>t=&lt;unix seconds>,v1=&lt;hex HMAC-SHA256></code>
|-
|-
| <code>User-Agent</code>
| <code>User-Agent</code>
Line 707: Line 707:
=== Verifying the signature ===
=== Verifying the signature ===


<code>v1</code> is the lowercase hex HMAC-SHA256 of the string <code>"&lt;t&gt;.&lt;body&gt;"</code>, keyed with the webhook's secret (the whole <code>whsec_...</code> string, as UTF-8). <code>t</code> is the time the attempt was signed. To verify:
<code>v1</code> is the lowercase hex HMAC-SHA256 of the string <code>"&lt;t>.&lt;body>"</code>, keyed with the webhook's secret (the whole <code>whsec_...</code> string, as UTF-8). <code>t</code> is the time the attempt was signed. To verify:


# Read the <strong>raw</strong> request body, exactly as received, before any JSON parsing.
# Read the <strong>raw</strong> request body, exactly as received, before any JSON parsing.
Line 720: Line 720:


static bool VerifyGadflySignature(string secret, string header, string rawBody, int toleranceSeconds = 300)
static bool VerifyGadflySignature(string secret, string header, string rawBody, int toleranceSeconds = 300)
&#123;
{
     var fields = header.Split(&#39;,&#39;)
     var fields = header.Split(',')
         .Select(p =&gt; p.Split(&#39;=&#39;, 2))
         .Select(p => p.Split('=', 2))
         .Where(p =&gt; p.Length == 2)
         .Where(p => p.Length == 2)
         .ToDictionary(p =&gt; p&#91;0&#93;.Trim(), p =&gt; p&#91;1&#93;.Trim());
         .ToDictionary(p => p[0].Trim(), p => p[1].Trim());
     if (!fields.TryGetValue("t", out var t) &#124;&#124; !fields.TryGetValue("v1", out var v1)) return false;
     if (!fields.TryGetValue("t", out var t) &#124;&#124; !fields.TryGetValue("v1", out var v1)) return false;
     if (!long.TryParse(t, out var ts) &#124;&#124; Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) &gt; toleranceSeconds) return false;
     if (!long.TryParse(t, out var ts) &#124;&#124; Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) > toleranceSeconds) return false;


     using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
     using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
     var expected = Convert.ToHexString(hmac.ComputeHash(Encoding.UTF8.GetBytes($"&#123;t&#125;.&#123;rawBody&#125;"))).ToLowerInvariant();
     var expected = Convert.ToHexString(hmac.ComputeHash(Encoding.UTF8.GetBytes($"{t}.{rawBody}"))).ToLowerInvariant();
     return CryptographicOperations.FixedTimeEquals(Encoding.ASCII.GetBytes(expected), Encoding.ASCII.GetBytes(v1));
     return CryptographicOperations.FixedTimeEquals(Encoding.ASCII.GetBytes(expected), Encoding.ASCII.GetBytes(v1));
&#125;</pre>
}</pre>


Node.js:
Node.js:
Line 737: Line 737:
<pre class="md-code lang-js">import crypto from "node:crypto";
<pre class="md-code lang-js">import crypto from "node:crypto";


export function verifyGadflySignature(secret, header, rawBody, toleranceSeconds = 300) &#123;
export function verifyGadflySignature(secret, header, rawBody, toleranceSeconds = 300) {
   const fields = &#123;&#125;;
   const fields = {};
   for (const part of header.split(",")) &#123;
   for (const part of header.split(",")) {
     const i = part.indexOf("=");
     const i = part.indexOf("=");
     if (i &gt; 0) fields&#91;part.slice(0, i).trim()&#93; = part.slice(i + 1).trim();
     if (i > 0) fields[part.slice(0, i).trim()] = part.slice(i + 1).trim();
   &#125;
   }
   const &#123; t, v1 &#125; = fields;
   const { t, v1 } = fields;
   if (!t &#124;&#124; !v1 &#124;&#124; Math.abs(Date.now() / 1000 - Number(t)) &gt; toleranceSeconds) return false;
   if (!t &#124;&#124; !v1 &#124;&#124; Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;


   const expected = crypto.createHmac("sha256", secret).update(`$&#123;t&#125;.$&#123;rawBody&#125;`, "utf8").digest("hex");
   const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`, "utf8").digest("hex");
   const a = Buffer.from(expected, "utf8");
   const a = Buffer.from(expected, "utf8");
   const b = Buffer.from(v1, "utf8");
   const b = Buffer.from(v1, "utf8");
   return a.length === b.length &amp;&amp; crypto.timingSafeEqual(a, b);
   return a.length === b.length && crypto.timingSafeEqual(a, b);
&#125;
}


// Express: keep the raw body for verification.
// Express: keep the raw body for verification.
// app.post("/hooks/gadfly", express.raw(&#123; type: "application/json" &#125;), (req, res) =&gt; &#123;
// app.post("/hooks/gadfly", express.raw({ type: "application/json" }), (req, res) => {
//  const ok = verifyGadflySignature(process.env.GADFLY_WEBHOOK_SECRET, req.get("X-Gadfly-Signature"), req.body.toString("utf8"));
//  const ok = verifyGadflySignature(process.env.GADFLY_WEBHOOK_SECRET, req.get("X-Gadfly-Signature"), req.body.toString("utf8"));
//  if (!ok) return res.sendStatus(401);
//  if (!ok) return res.sendStatus(401);
//  const event = JSON.parse(req.body.toString("utf8"));
//  const event = JSON.parse(req.body.toString("utf8"));
//  res.sendStatus(204);
//  res.sendStatus(204);
// &#125;);</pre>
// });</pre>


== Errors ==
== Errors ==
Line 769: Line 769:
| <code>400 Bad Request</code>
| <code>400 Bad Request</code>
| A rule above isn't met
| A rule above isn't met
| <code>&#123; "error": "&lt;what to fix&gt;" &#125;</code>; unknown concept keys add <code>"unknown": &#91;...&#93;</code>
| <code>{ "error": "&lt;what to fix>" }</code>; unknown concept keys add <code>"unknown": [...]</code>
|-
|-
| <code>400 Bad Request</code>
| <code>400 Bad Request</code>
Line 785: Line 785:
| <code>409 Conflict</code>
| <code>409 Conflict</code>
| The request clashes with current state: processing already queued or running; assigning a non-student, a deactivated member, or an account outside your organization
| The request clashes with current state: processing already queued or running; assigning a non-student, a deactivated member, or an account outside your organization
| <code>&#123; "error": "&lt;what to do&gt;" &#125;</code>
| <code>{ "error": "&lt;what to do>" }</code>
|-
|-
| <code>429 Too Many Requests</code>
| <code>429 Too Many Requests</code>
Line 813: Line 813:


<pre class="md-code">GET /grading/actions/antiforgery
<pre class="md-code">GET /grading/actions/antiforgery
→ 200 &#123; "headerName": "RequestVerificationToken", "token": "CfDJ8..." &#125;</pre>
→ 200 { "headerName": "RequestVerificationToken", "token": "CfDJ8..." }</pre>


A missing or wrong token answers <code>400</code> with <code>&#123; "ok": false, "message": "Missing or invalid antiforgery token: ..." &#125;</code>.
A missing or wrong token answers <code>400</code> with <code>{ "ok": false, "message": "Missing or invalid antiforgery token: ..." }</code>.


=== Actions ===
=== Actions ===


Every path below starts with <code>/grading/actions/&#123;sessionId&#125;</code>. Bodies are JSON. Each action answers <code>&#123; "ok": true&#124;false, "message": "&lt;what happened, in words&gt;", "status": "&lt;grade status after the call&gt;" &#125;</code>.
Every path below starts with <code>/grading/actions/{sessionId}</code>. Bodies are JSON. Each action answers <code>{ "ok": true&#124;false, "message": "&lt;what happened, in words>", "status": "&lt;grade status after the call>" }</code>.


{| class="wikitable"
{| class="wikitable"
Line 829: Line 829:
| <code>POST .../ai-grading</code>
| <code>POST .../ai-grading</code>
| Examiner, Teacher, Admin, Owner
| Examiner, Teacher, Admin, Owner
| <code>&#123;&#125;</code>
| <code>{}</code>
| Starts (or retries) AI grading of an ended session
| Starts (or retries) AI grading of an ended session
|-
|-
| <code>POST .../human-grades</code>
| <code>POST .../human-grades</code>
| Examiner, Teacher (EnterHumanScore)
| Examiner, Teacher (EnterHumanScore)
| <code>&#123; "grades": &#91; &#123; "objectiveKey" or "objectiveId", "level", "score", "comment"?, "evidenceNote"? &#125; &#93; &#125;</code>
| <code>{ "grades": [ { "objectiveKey" or "objectiveId", "level", "score", "comment"?, "evidenceNote"? } ] }</code>
| Human Review Pending → Reconciliation Required or Awaiting Final Approval. One grade per objective, every objective required; earlier grades are kept and superseded
| Human Review Pending → Reconciliation Required or Awaiting Final Approval. One grade per objective, every objective required; earlier grades are kept and superseded
|-
|-
| <code>POST .../human-grades/reopen</code>
| <code>POST .../human-grades/reopen</code>
| Examiner, Teacher
| Examiner, Teacher
| <code>&#123; "reason" &#125;</code>
| <code>{ "reason" }</code>
| Back to Human Review Pending, to adjust the human grades
| Back to Human Review Pending, to adjust the human grades
|-
|-
| <code>POST .../second-review</code>
| <code>POST .../second-review</code>
| Teacher, Admin, Owner, Second Reviewer (ReconcileDisagreement)
| Teacher, Admin, Owner, Second Reviewer (ReconcileDisagreement)
| <code>&#123; "disagreementId", "reviewerUserId" &#125;</code>
| <code>{ "disagreementId", "reviewerUserId" }</code>
| Asks a member holding the Second Reviewer role to reconcile
| Asks a member holding the Second Reviewer role to reconcile
|-
|-
| <code>POST .../reconciliations</code>
| <code>POST .../reconciliations</code>
| ReconcileDisagreement or ActAsSecondReviewer
| ReconcileDisagreement or ActAsSecondReviewer
| <code>&#123; "disagreementId", "cause", "resolution", "resolvedAiScore"?, "resolvedHumanScore"?, "secondReviewerUserId"? &#125;</code>
| <code>{ "disagreementId", "cause", "resolution", "resolvedAiScore"?, "resolvedHumanScore"?, "secondReviewerUserId"? }</code>
| Documents the resolution and recalculates; Awaiting Final Approval once no mandatory disagreement is open. <code>cause</code> is one of <code>error-in-ai</code>, <code>error-in-human</code>, <code>transcript-ambiguity</code>, <code>rubric-interpretation</code>, <code>both-defensible</code>. A second reviewer who acts is recorded as the second reviewer. Refused (<code>409</code>) for the person who entered this grade's human score (separation of duties)
| Documents the resolution and recalculates; Awaiting Final Approval once no mandatory disagreement is open. <code>cause</code> is one of <code>error-in-ai</code>, <code>error-in-human</code>, <code>transcript-ambiguity</code>, <code>rubric-interpretation</code>, <code>both-defensible</code>. A second reviewer who acts is recorded as the second reviewer. Refused (<code>409</code>) for the person who entered this grade's human score (separation of duties)
|-
|-
| <code>POST .../approve</code>
| <code>POST .../approve</code>
| Teacher, Admin, Owner (ApproveFinalGrade)
| Teacher, Admin, Owner (ApproveFinalGrade)
| <code>&#123; "label"?, "note"? &#125;</code>
| <code>{ "label"?, "note"? }</code>
| Awaiting Final Approval → Finalized, with a Finalize approval record. Refused (<code>409</code>) while a mandatory disagreement is open, and for the person who entered this grade's human score (separation of duties)
| Awaiting Final Approval → Finalized, with a Finalize approval record. Refused (<code>409</code>) while a mandatory disagreement is open, and for the person who entered this grade's human score (separation of duties)
|-
|-
| <code>POST .../publish</code>
| <code>POST .../publish</code>
| Teacher, Admin, Owner (PublishGrade)
| Teacher, Admin, Owner (PublishGrade)
| <code>&#123; "note"? &#125;</code>
| <code>{ "note"? }</code>
| Finalized → Published, with a Publish record. Refused (<code>409</code>) without a Finalize record
| Finalized → Published, with a Publish record. Refused (<code>409</code>) without a Finalize record
|-
|-
| <code>POST .../appeals</code>
| <code>POST .../appeals</code>
| The student whose published result it is (AppealOwnResult)
| The student whose published result it is (AppealOwnResult)
| <code>&#123; "reason" &#125;</code>
| <code>{ "reason" }</code>
| Published or Amended → Under Appeal
| Published or Amended → Under Appeal
|-
|-
| <code>POST .../appeals/&#123;appealId&#125;/resolve</code>
| <code>POST .../appeals/{appealId}/resolve</code>
| Teacher, Admin, Owner (ResolveAppeal)
| Teacher, Admin, Owner (ResolveAppeal)
| <code>&#123; "outcome": "Upheld" or "Dismissed", "resolution" &#125;</code>
| <code>{ "outcome": "Upheld" or "Dismissed", "resolution" }</code>
| The grade stands: back to Published
| The grade stands: back to Published
|-
|-
| <code>POST .../amend</code>
| <code>POST .../amend</code>
| Teacher, Admin, Owner (AmendGrade, plus ResolveAppeal with <code>appealId</code>)
| Teacher, Admin, Owner (AmendGrade, plus ResolveAppeal with <code>appealId</code>)
| <code>&#123; "grades": &#91; changed objectives &#93;, "reason", "appealId"? &#125;</code>
| <code>{ "grades": [ changed objectives ], "reason", "appealId"? }</code>
| Published or Under Appeal → Amended: new human grades supersede the old ones, the combined score is recalculated under the frozen policy, and the appeal (if given) is resolved as Amended. While an appeal is open, <code>appealId</code> is required: an amendment that doesn't name it is refused, so the appeal is never left open behind an amended grade
| Published or Under Appeal → Amended: new human grades supersede the old ones, the combined score is recalculated under the frozen policy, and the appeal (if given) is resolved as Amended. While an appeal is open, <code>appealId</code> is required: an amendment that doesn't name it is refused, so the appeal is never left open behind an amended grade
|}
|}


<strong>Separation of duties (GAD-T285).</strong> Reconciliation and approval are refused (<code>409</code>, <code>"Refused: you entered this grade&#39;s human score, ..."</code>, audited as <code>grade.separation-of-duties.refused</code>) when the caller entered any human score of that session's grade. An organization that has turned on <strong>Allow a single grader</strong> in its settings (off by default) lets them through, and each one is audited as <code>grade.separation-of-duties.waived</code>. The status read says where the caller stands in <code>separationOfDuties</code>.
<strong>Separation of duties (GAD-T285).</strong> Reconciliation and approval are refused (<code>409</code>, <code>"Refused: you entered this grade's human score, ..."</code>, audited as <code>grade.separation-of-duties.refused</code>) when the caller entered any human score of that session's grade. An organization that has turned on <strong>Allow a single grader</strong> in its settings (off by default) lets them through, and each one is audited as <code>grade.separation-of-duties.waived</code>. The status read says where the caller stands in <code>separationOfDuties</code>.


<code>level</code> is a mastery level by name or number: <code>InsufficientEvidence</code> (0), <code>Recognition</code> (1), <code>BasicExplanation</code> (2), <code>ConceptualUnderstanding</code> (3), <code>Application</code> (4), <code>TransferAndCriticalReasoning</code> (5). <code>score</code> is on the objective's own scale (0 to its <code>maxScore</code>).
<code>level</code> is a mastery level by name or number: <code>InsufficientEvidence</code> (0), <code>Recognition</code> (1), <code>BasicExplanation</code> (2), <code>ConceptualUnderstanding</code> (3), <code>Application</code> (4), <code>TransferAndCriticalReasoning</code> (5). <code>score</code> is on the objective's own scale (0 to its <code>maxScore</code>).
Line 908: Line 908:
Content-Type: application/json
Content-Type: application/json


&#123; "grades": &#91;
{ "grades": [
     &#123; "objectiveKey": "equal-groups", "level": "BasicExplanation", "score": 4, "comment": "Repeated addition only." &#125;,
     { "objectiveKey": "equal-groups", "level": "BasicExplanation", "score": 4, "comment": "Repeated addition only." },
     &#123; "objectiveKey": "factor-roles", "level": "BasicExplanation", "score": 5 &#125;,
     { "objectiveKey": "factor-roles", "level": "BasicExplanation", "score": 5 },
     &#123; "objectiveKey": "scaling", "level": 2, "score": 5 &#125; &#93; &#125;
     { "objectiveKey": "scaling", "level": 2, "score": 5 } ] }


→ 200 &#123; "ok": true, "status": "ReconciliationRequired",
→ 200 { "ok": true, "status": "ReconciliationRequired",
         "message": "Human grades saved. The AI and human scores disagree substantially: reconciliation is required before this grade can be finalized." &#125;</pre>
         "message": "Human grades saved. The AI and human scores disagree substantially: reconciliation is required before this grade can be finalized." }</pre>


=== Status ===
=== Status ===


<code>GET /grading/actions/&#123;sessionId&#125;</code>, for a reviewer (ViewTranscripts):
<code>GET /grading/actions/{sessionId}</code>, for a reviewer (ViewTranscripts):


<pre class="md-code lang-json">&#123;
<pre class="md-code lang-json">{
   "sessionId": "6b72ef45-...", "examTitle": "Demo: Understanding multiplication", "student": "demo.student", "attempt": 1,
   "sessionId": "6b72ef45-...", "examTitle": "Demo: Understanding multiplication", "student": "demo.student", "attempt": 1,
   "status": "ReconciliationRequired", "statusLabel": "Reconciliation Required",
   "status": "ReconciliationRequired", "statusLabel": "Reconciliation Required",
   "aiVisible": true, "isMock": true, "finalPercent": 46.67, "label": null,
   "aiVisible": true, "isMock": true, "finalPercent": 46.67, "label": null,
   "separationOfDuties": &#123; "youScoredThisGrade": false, "singleGraderAllowed": false, "blocksYou": false &#125;,
   "separationOfDuties": { "youScoredThisGrade": false, "singleGraderAllowed": false, "blocksYou": false },
   "policy": &#123; "aiWeight": 0.4, "humanWeight": 0.6, "additionalReviewAt": 10, "mandatoryReconciliationAt": 20, "blindHumanGrading": true, "source": "exam-policy" &#125;,
   "policy": { "aiWeight": 0.4, "humanWeight": 0.6, "additionalReviewAt": 10, "mandatoryReconciliationAt": 20, "blindHumanGrading": true, "source": "exam-policy" },
   "aiGradingJob": &#123; "state": "Succeeded", "error": null &#125;,
   "aiGradingJob": { "state": "Succeeded", "error": null },
   "responsesNeedingHuman": 0,
   "responsesNeedingHuman": 0,
   "objectives": &#91; &#123;
   "objectives": [ {
     "id": "...", "key": "equal-groups", "title": "...", "maxScore": 10, "weight": 1, "aiRecorded": true,
     "id": "...", "key": "equal-groups", "title": "...", "maxScore": 10, "weight": 1, "aiRecorded": true,
     "ai": &#123; "level": "Application", "levelNumber": 4, "score": 8, "maxScore": 10, "confidence": "...", "isMock": true, "explanation": "&#91;MOCK&#93; ...", "excluded": false &#125;,
     "ai": { "level": "Application", "levelNumber": 4, "score": 8, "maxScore": 10, "confidence": "...", "isMock": true, "explanation": "[MOCK] ...", "excluded": false },
     "human": &#123; "id": "...", "level": "BasicExplanation", "levelNumber": 2, "score": 4, "maxScore": 10, "wasBlind": true, "reviewer": "demo.examiner",
     "human": { "id": "...", "level": "BasicExplanation", "levelNumber": 2, "score": 4, "maxScore": 10, "wasBlind": true, "reviewer": "demo.examiner",
               "reviewerRole": "Examiner", "comment": "...", "submittedAt": "...", "supersedes": null &#125;,
               "reviewerRole": "Examiner", "comment": "...", "submittedAt": "...", "supersedes": null },
     "humanHistory": 1,
     "humanHistory": 1,
     "combined": &#123; "aiScore": 8, "humanScore": 4, "combined": 5.6, "differencePoints": 40, "band": "MandatoryReconciliation" &#125; &#125; &#93;,
     "combined": { "aiScore": 8, "humanScore": 4, "combined": 5.6, "differencePoints": 40, "band": "MandatoryReconciliation" } } ],
   "disagreements": &#91; &#123; "id": "...", "objectiveId": "...", "objectiveKey": "equal-groups", "aiScore": 8, "humanScore": 4, "differencePoints": 40,
   "disagreements": [ { "id": "...", "objectiveId": "...", "objectiveKey": "equal-groups", "aiScore": 8, "humanScore": 4, "differencePoints": 40,
                       "band": "MandatoryReconciliation", "resolved": false, "resolvedAt": null, "needsReconciliation": true, "reconciliations": &#91;&#93; &#125; &#93;,
                       "band": "MandatoryReconciliation", "resolved": false, "resolvedAt": null, "needsReconciliation": true, "reconciliations": [] } ],
   "approvals": &#91; &#123; "action": "Finalize", "actor": "demo.teacher", "role": "Instructor", "note": "...", "at": "..." &#125; &#93;,
   "approvals": [ { "action": "Finalize", "actor": "demo.teacher", "role": "Instructor", "note": "...", "at": "..." } ],
   "appeals": &#91; &#123; "id": "...", "state": "Open", "reason": "...", "resolution": null, "openedAt": "...", "resolvedAt": null &#125; &#93;,
   "appeals": [ { "id": "...", "state": "Open", "reason": "...", "resolution": null, "openedAt": "...", "resolvedAt": null } ],
   "secondReviewers": &#91; &#123; "userId": "...", "name": "demo.reviewer" &#125; &#93;
   "secondReviewers": [ { "userId": "...", "name": "demo.reviewer" } ]
&#125;</pre>
}</pre>


<strong>Blind grading.</strong> While the policy is blind and the grade has not passed the human evaluation (Human Review Pending or earlier), <code>aiVisible</code> is <code>false</code> and nothing derived from the AI is returned: every objective's <code>ai</code> and <code>combined</code> are <code>null</code>, <code>finalPercent</code> is <code>null</code>, <code>disagreements</code> is empty and <code>isMock</code> is <code>false</code>. <code>aiRecorded</code> says only that an AI grade exists. Once the human grades are submitted, reviewers see the AI's evaluation.
<strong>Blind grading.</strong> While the policy is blind and the grade has not passed the human evaluation (Human Review Pending or earlier), <code>aiVisible</code> is <code>false</code> and nothing derived from the AI is returned: every objective's <code>ai</code> and <code>combined</code> are <code>null</code>, <code>finalPercent</code> is <code>null</code>, <code>disagreements</code> is empty and <code>isMock</code> is <code>false</code>. <code>aiRecorded</code> says only that an AI grade exists. Once the human grades are submitted, reviewers see the AI's evaluation.
Line 946: Line 946:
A <strong>student</strong> asking for their own session gets <code>404</code> until the grade is approved <em>and</em> published (the attempt is audited as <code>access.denied</code>). After that they get their result as the student's assessment report shows it, without reviewer names, voters or audit detail:
A <strong>student</strong> asking for their own session gets <code>404</code> until the grade is approved <em>and</em> published (the attempt is audited as <code>access.denied</code>). After that they get their result as the student's assessment report shows it, without reviewer names, voters or audit detail:


<pre class="md-code lang-json">&#123; "sessionId": "...", "examTitle": "...", "attempt": 1, "status": "Published", "statusLabel": "Published",
<pre class="md-code lang-json">{ "sessionId": "...", "examTitle": "...", "attempt": 1, "status": "Published", "statusLabel": "Published",
   "finalPercent": 60, "label": "Tour", "isMock": true,
   "finalPercent": 60, "label": "Tour", "isMock": true,
   "objectives": &#91; &#123; "key": "...", "title": "...", "maxScore": 10, "aiScore": 8, "aiLevel": "...", "humanScore": 8, "humanLevel": "...", "combined": 8 &#125; &#93;,
   "objectives": [ { "key": "...", "title": "...", "maxScore": 10, "aiScore": 8, "aiLevel": "...", "humanScore": 8, "humanLevel": "...", "combined": 8 } ],
   "knowledgeGaps": &#91; "..." &#93;, "approvals": &#91; "2026-11-20 20:03 UTC · Final grade approved by Teacher" &#93;,
   "knowledgeGaps": [ "..." ], "approvals": [ "2026-11-20 20:03 UTC · Final grade approved by Teacher" ],
   "appeals": &#91; &#123; "id": "...", "state": "Open", "resolution": null, "openedAt": "...", "resolvedAt": null &#125; &#93; &#125;</pre>
   "appeals": [ { "id": "...", "state": "Open", "resolution": null, "openedAt": "...", "resolvedAt": null } ] }</pre>


Other members without a reviewer permission get <code>403</code> (audited). The per-objective assessment report downloads at <code>/grading/&#123;sessionId&#125;/report.md</code>, <code>/grading/&#123;sessionId&#125;/report.csv</code> and <code>/grading/&#123;sessionId&#125;/report.pdf</code> (reviewers) and <code>/my-results/&#123;sessionId&#125;/report.md</code> and <code>/my-results/&#123;sessionId&#125;/report.pdf</code> (the student, once published). The PDF (GAD-T311/GAD-T377) says the same thing in the same order as the Markdown (per objective: the AI and examiner levels, what was missing, the next level's descriptor), laid out with the same hand-written PDF engine the transcript downloads use (GAD-T295) rather than a new PDF dependency.
Other members without a reviewer permission get <code>403</code> (audited). The per-objective assessment report downloads at <code>/grading/{sessionId}/report.md</code>, <code>/grading/{sessionId}/report.csv</code> and <code>/grading/{sessionId}/report.pdf</code> (reviewers) and <code>/my-results/{sessionId}/report.md</code> and <code>/my-results/{sessionId}/report.pdf</code> (the student, once published). The PDF (GAD-T311/GAD-T377) says the same thing in the same order as the Markdown (per objective: the AI and examiner levels, what was missing, the next level's descriptor), laid out with the same hand-written PDF engine the transcript downloads use (GAD-T295) rather than a new PDF dependency.


<code>GET /grading/exam/&#123;examId&#125;/class-summary.pdf</code> (reviewers, ViewTranscripts; GAD-T311/GAD-T378): a class summary PDF for instructors, aggregated over every student assigned to that exam — score distribution (mean, median, a 10-point histogram), each learning objective's class average and who hasn't completed the exam yet. Only released results (published to the student) feed the distribution and averages; an attempt that has ended but is still awaiting grading or release is counted separately and never named, and a student with no ended attempt is listed by name so the instructor can follow up.
<code>GET /grading/exam/{examId}/class-summary.pdf</code> (reviewers, ViewTranscripts; GAD-T311/GAD-T378): a class summary PDF for instructors, aggregated over every student assigned to that exam — score distribution (mean, median, a 10-point histogram), each learning objective's class average and who hasn't completed the exam yet. Only released results (published to the student) feed the distribution and averages; an attempt that has ended but is still awaiting grading or release is counted separately and never named, and a student with no ended attempt is listed by name so the instructor can follow up.


<code>GET /certificates/&#123;sessionId&#125;/pdf</code> (GAD-T311/GAD-T379): a student's completion certificate once their result is released (<code>409</code> with a plain-English reason before then; the same entitlement check as the transcript download, so a session id from elsewhere looks like <code>404</code> either way). Carries its own verification code and SHA-256, checked at the transcript's own verify page (next section) rather than a separate one.
<code>GET /certificates/{sessionId}/pdf</code> (GAD-T311/GAD-T379): a student's completion certificate once their result is released (<code>409</code> with a plain-English reason before then; the same entitlement check as the transcript download, so a session id from elsewhere looks like <code>404</code> either way). Carries its own verification code and SHA-256, checked at the transcript's own verify page (next section) rather than a separate one.


=== Reconciliation triggers ===
=== Reconciliation triggers ===
Line 964: Line 964:
=== Research export ===
=== Research export ===


<code>GET /admin/research/export.zip&#91;?exam=&#123;examId&#125;&#93;</code> (owners and admins, <code>GadflyPolicies.OrgAdmin</code>; GAD-T451) returns a ZIP of CSV files for a study of the organization's exams (docs/PILOT.md, "Research export", lists every file and column), with <code>README.txt</code> and <code>manifest.json</code> (counts, the smallest group used, what was held back). <code>404</code> with a plain reason when research has never been set up on <strong>Research</strong> (<code>/org/research</code>).
<code>GET /admin/research/export.zip[?exam={examId}]</code> (owners and admins, <code>GadflyPolicies.OrgAdmin</code>; GAD-T451) returns a ZIP of CSV files for a study of the organization's exams (docs/PILOT.md, "Research export", lists every file and column), with <code>README.txt</code> and <code>manifest.json</code> (counts, the smallest group used, what was held back). <code>404</code> with a plain reason when research has never been set up on <strong>Research</strong> (<code>/org/research</code>).


* Only students whose current research choice is "agreed" are included (GAD-T452). Declined, never answered, withdrawn and erased students are left out and only counted in the manifest.
* Only students whose current research choice is "agreed" are included (GAD-T452). Declined, never answered, withdrawn and erased students are left out and only counted in the manifest.
Line 976: Line 976:
A grading panel is accepted for an exam only after a blind, double-marked calibration set meets the thresholds (Williamson et al. 2012, as reported in research note 05): panel-human QWK at least .70, no more than .10 below the human-human QWK, and &#124;SMD&#124; under .15, on at least 30 answers. The panel is compared with each marker and the weaker comparison counts. Levels are the rubric's mastery levels 0..5.
A grading panel is accepted for an exam only after a blind, double-marked calibration set meets the thresholds (Williamson et al. 2012, as reported in research note 05): panel-human QWK at least .70, no more than .10 below the human-human QWK, and &#124;SMD&#124; under .15, on at least 30 answers. The panel is compared with each marker and the weaker comparison counts. Levels are the rubric's mastery levels 0..5.


<code>POST /grading/calibration/&#123;examId&#125;</code> (ApproveGradingPolicyChange; antiforgery token as above):
<code>POST /grading/calibration/{examId}</code> (ApproveGradingPolicyChange; antiforgery token as above):


<pre class="md-code lang-json">&#123; "panel": "claude-sonnet-5, gpt-5, gemini-3 (majority of levels)",
<pre class="md-code lang-json">{ "panel": "claude-sonnet-5, gpt-5, gemini-3 (majority of levels)",
   "items": &#91; &#123; "itemId": "s01-equal-groups", "panelLevel": 3, "humanALevel": 3, "humanBLevel": 2 &#125; &#93; &#125;
   "items": [ { "itemId": "s01-equal-groups", "panelLevel": 3, "humanALevel": 3, "humanBLevel": 2 } ] }


→ 200 &#123; "ok": false, "accepted": false, "message": "Panel not accepted for this exam. ...",
→ 200 { "ok": false, "accepted": false, "message": "Panel not accepted for this exam. ...",
         "report": &#123; "items": 12, "humanHumanQwk": 0.81, "panelHumanQwk": 0.66, "degradation": 0.15, "smd": 0.21,
         "report": { "items": 12, "humanHumanQwk": 0.81, "panelHumanQwk": 0.66, "degradation": 0.15, "smd": 0.21,
                     "accepted": false, "failures": &#91; "..." &#93;, "thresholds": &#123; "minQwk": 0.7, "maxDegradation": 0.1, "maxAbsSmd": 0.15, "minItems": 30 &#125; &#125; &#125;</pre>
                     "accepted": false, "failures": [ "..." ], "thresholds": { "minQwk": 0.7, "maxDegradation": 0.1, "maxAbsSmd": 0.15, "minItems": 30 } } }</pre>


<code>panel</code> is optional: it defaults to the configured members and their models. The model id of every member is stored with the evaluation (GAD-T429), and so is the grading prompt-set version (GAD-T469). A calibration of the mock panel is never accepted.
<code>panel</code> is optional: it defaults to the configured members and their models. The model id of every member is stored with the evaluation (GAD-T429), and so is the grading prompt-set version (GAD-T469). A calibration of the mock panel is never accepted.


Every evaluation, passing or failing, is recorded as an audit event (<code>panel.calibration.evaluated</code>), and the latest one is the exam's status: <code>GET /grading/calibration/&#123;examId&#125;</code> (ViewTranscripts) returns it, or <code>404</code> when none is recorded:
Every evaluation, passing or failing, is recorded as an audit event (<code>panel.calibration.evaluated</code>), and the latest one is the exam's status: <code>GET /grading/calibration/{examId}</code> (ViewTranscripts) returns it, or <code>404</code> when none is recorded:


<pre class="md-code lang-json">&#123; "examId": "…", "panel": "claude: claude-sonnet-5, openai: gpt-5", "accepted": true, "report": &#123; … &#125;, "at": "…",
<pre class="md-code lang-json">{ "examId": "…", "panel": "claude: claude-sonnet-5, openai: gpt-5", "accepted": true, "report": { … }, "at": "…",
   "models": &#123; "claude": "claude-sonnet-5", "openai": "gpt-5" &#125;, "gradingPromptVersion": 1, "source": "double-marking",
   "models": { "claude": "claude-sonnet-5", "openai": "gpt-5" }, "gradingPromptVersion": 1, "source": "double-marking",
   "expired": false, "expiryReasons": &#91;&#93;, "recheckDue": false, "effective": true &#125;</pre>
   "expired": false, "expiryReasons": [], "recheckDue": false, "effective": true }</pre>


<code>expired</code> is true when any panel member's model id now differs from those the calibration covered (a member swapped, added or removed, or a calibration recorded before model ids were kept), or when the grading prompts' version differs from <code>gradingPromptVersion</code> (GAD-T469; a calibration recorded before versions were kept counts as version 1); <code>expiryReasons</code> says which. <code>effective</code> is <code>accepted &amp;&amp; !expired</code>. <code>recheckDue</code> is true once the calibration is older than <code>Gadfly:Grading:RecalibrateAfterDays</code> (default 180): a prompt to re-run it and the bias probes; nothing re-runs by itself. <code>source</code> is <code>api</code> (posted here) or <code>double-marking</code> (built in the app from blind second marks, GAD-T428; only answers whose AI grade came from the models the panel runs now and the current grading prompt-set version count, GAD-T480/GAD-T484 — every AI grade records its version, and grades made before versions were kept count as version 1).
<code>expired</code> is true when any panel member's model id now differs from those the calibration covered (a member swapped, added or removed, or a calibration recorded before model ids were kept), or when the grading prompts' version differs from <code>gradingPromptVersion</code> (GAD-T469; a calibration recorded before versions were kept counts as version 1); <code>expiryReasons</code> says which. <code>effective</code> is <code>accepted && !expired</code>. <code>recheckDue</code> is true once the calibration is older than <code>Gadfly:Grading:RecalibrateAfterDays</code> (default 180): a prompt to re-run it and the bias probes; nothing re-runs by itself. <code>source</code> is <code>api</code> (posted here) or <code>double-marking</code> (built in the app from blind second marks, GAD-T428; only answers whose AI grade came from the models the panel runs now and the current grading prompt-set version count, GAD-T480/GAD-T484 — every AI grade records its version, and grades made before versions were kept count as version 1).


When AI grading of a session starts, the status is frozen into its policy snapshot (<code>panel</code>, with <code>expired</code>). An exam set to <strong>human-only until calibrated</strong> (GAD-T427) also freezes <code>gate</code>: <code>&#123; "applied": true, "reason": "…" &#125;</code> when the session is graded with AI weight 0 and human weight 1 because the calibration is missing, not accepted or expired. The grading page describes what the calibration measured, never just "calibrated". The AI grade is never final either way. Double marking, the gate setting, bias probes and the self-preference check are pages, not API endpoints (<code>/grading/panel</code>, <code>/grading/second-mark/&#123;examId&#125;</code>, <code>/grading/bias/&#123;examId&#125;</code>, <code>/grading/self-preference/&#123;examId&#125;</code>); their records are audit events (<code>panel.settings.updated</code>, <code>grade.second-mark.recorded</code>, <code>panel.bias-probe.*</code>, <code>bias.human-probe.*</code>) readable through the audit log.
When AI grading of a session starts, the status is frozen into its policy snapshot (<code>panel</code>, with <code>expired</code>). An exam set to <strong>human-only until calibrated</strong> (GAD-T427) also freezes <code>gate</code>: <code>{ "applied": true, "reason": "…" }</code> when the session is graded with AI weight 0 and human weight 1 because the calibration is missing, not accepted or expired. The grading page describes what the calibration measured, never just "calibrated". The AI grade is never final either way. Double marking, the gate setting, bias probes and the self-preference check are pages, not API endpoints (<code>/grading/panel</code>, <code>/grading/second-mark/{examId}</code>, <code>/grading/bias/{examId}</code>, <code>/grading/self-preference/{examId}</code>); their records are audit events (<code>panel.settings.updated</code>, <code>grade.second-mark.recorded</code>, <code>panel.bias-probe.*</code>, <code>bias.human-probe.*</code>) readable through the audit log.


<div class="md2wiki-crumb">Part of [[Gadfly]].</div>
<div class="md2wiki-crumb">Part of [[Gadfly]].</div>

Revision as of 20:18, 29 November 2026

Platform API v1

The Gadfly platform API lets another application use Gadfly's Socratic exams: upload source material, have it processed into concepts, create exams, provision and assign students, send each student a signed launch link into the exam room, read results, and receive a signed webhook when an attempt ends.

Everything is under /api/v1, speaks JSON (camelCase), and acts inside one organization: the one that owns the API key. A machine-readable description is at /openapi/v1.json.

Every exam, however it was created, is taken in the spoken exam room, on camera: the student answers aloud to the talking examiner (see VOICE.md); typed answers exist only as an accommodation staff grant per student and exam. The examples use a local server; the Azure-hosted instance was decommissioned on 2026-11-26 (GAD-T804).

Authentication

Send the organization's API key as a bearer token on every call:

Authorization: Bearer gfk_3f9a1c07_q2mJ0b4Xw6...
Fact Detail
Format gfk_<8 hex characters>_<secret>
Scope The whole organization. The key is not a person; it can do everything listed on this page within its organization and nothing outside it.
Storage Only a SHA-256 hash is stored. The key is shown once at creation.
Refused A missing, unknown or revoked key, or a key of a deactivated organization: 401 Unauthorized with no body.

Organization admins create and revoke keys at /org/api-keys in the admin console. See the Admin guide.

Endpoints

Method Path Does
GET /api/v1/collections List source collections
POST /api/v1/collections Create a source collection
GET /api/v1/collections/{id} One collection: status, documents, concept map version
POST /api/v1/collections/{id}/documents Upload documents (multipart)
POST /api/v1/collections/{id}/process Queue processing
GET /api/v1/jobs/{id} Processing job status
GET /api/v1/collections/{id}/concepts The collection's concept map
POST /api/v1/exams Create and publish an exam
POST /api/v1/exams/{id}/assignments Provision a student and assign the exam
POST /api/v1/assignments/{id}/launch A signed launch link for the student
GET /api/v1/assignments/{id}/sessions The student's attempts
GET /api/v1/sessions/{id}/result One attempt's result and report
GET /api/v1/sessions/{id}/transcript One attempt's official transcript (JSON, PDF, Word, web page, text, captions)
POST /api/v1/webhooks Register a webhook
GET /api/v1/webhooks List webhooks
DELETE /api/v1/webhooks/{id} Deactivate a webhook
GET /launch?token=... The student-facing end of a launch link (not an API call)

Ids are GUIDs. Times are ISO 8601 with an offset (UTC).

Create a collection

POST /api/v1/collections

{ "title": "Biology 101: cells" }

201 Created, Location: /api/v1/collections/{id}

{ "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10", "title": "Biology 101: cells" }

400 { "error": "title is required" } when the title is missing or blank, or { "error": "title must be at most 300 characters" }. The title is trimmed.

List collections

GET /api/v1/collections

[
  {
    "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
    "title": "Biology 101: cells",
    "status": "Ready",
    "documentCount": 2,
    "conceptCount": 9,
    "conceptMapVersion": 3,
    "createdAt": "2026-11-28T09:12:00+00:00",
    "latestJob": {
      "id": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a",
      "state": "Succeeded",
      "progress": 1,
      "progressMessage": "9 concepts ready",
      "error": null,
      "createdAt": "2026-11-28T09:13:10+00:00",
      "completedAt": "2026-11-28T09:15:42+00:00"
    }
  }
]

Newest first. status is Pending, Processing, Ready or Failed. documentCount counts uploaded and processed documents once each; conceptCount leaves out archived concepts. latestJob is the most recent processing job (its state as in Job status), or null if the collection was never processed. An empty array when there are none.

Get a collection

GET /api/v1/collections/{id} (the Location returned when the collection was created)

{
  "id": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
  "title": "Biology 101: cells",
  "status": "Ready",
  "conceptMapVersion": 3,
  "createdAt": "2026-11-28T09:12:00+00:00",
  "documents": [
    {
      "fileName": "chapter1.md",
      "sizeBytes": 18234,
      "uploaded": true,
      "ingested": true,
      "changedSinceIngest": false,
      "passageCount": 14,
      "uploadedAt": "2026-11-28T09:12:30+00:00",
      "ingestedAt": "2026-11-28T09:14:02+00:00",
      "error": null
    }
  ],
  "latestJob": null
}
Field Meaning
conceptMapVersion Goes up whenever the concept map or a rubric changes; 0 before the first processing.
documents[].uploaded The file is in the upload folder (sizeBytes and uploadedAt are null otherwise).
documents[].ingested The document was processed successfully.
documents[].changedSinceIngest The uploaded file differs from what was processed; process again to pick it up.
documents[].error Why processing this document failed, or null.
latestJob As in List collections.

404 when the collection isn't in your organization.

Upload documents

POST /api/v1/collections/{id}/documents with multipart/form-data, one or more file parts.

curl -X POST https://localhost:7311/api/v1/collections/6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10/documents \
  -H "Authorization: Bearer $GADFLY_KEY" \
  -F "file=@chapter1.md" -F "file=@chapter2.md"

200 OK

{ "saved": ["chapter1.md", "chapter2.md"] }
  • Accepted: .txt, .text, .md, .markdown, .pdf, .docx, .epub, .html and .htm (the same as the source library page). A scanned, image-only PDF uploads but yields no text.
  • Each file must be 1 byte to 20 MB. Keep each request under the server's request size limit (about 28 MB by default); send large sets in several requests.
  • Reserved Windows device names are refused whatever the extension: CON, PRN, AUX, NUL, COM1-COM9 and LPT1-LPT9 (so con.txt and com1.notes.md are refused too).
  • File names are cleaned: folder parts are dropped and characters not allowed in file names become _. A file with the same name as one already uploaded replaces it.
  • Every file in the request is checked before any is saved: if one is refused, nothing from that request is stored. Each file is written under a temporary name and then moved into place, so processing never reads a half-written file.

404 when the collection isn't in your organization. 400 with one of:

  • { "error": "send multipart/form-data with one or more files" }
  • { "error": "<file>: only .txt, .text, .md, .markdown files are accepted for now" }
  • { "error": "<file>: CON is a reserved device name; rename the file" }
  • { "error": "<file>: files must be 1 byte to 20 MB" }
  • { "error": "<file>: the file needs a name" }
  • { "error": "the upload could not be read: ..." } (a malformed multipart body)

Process a collection

POST /api/v1/collections/{id}/process

{ "rebuildConceptMap": false }

The body is optional. Processing reads new and changed documents, has the AI panel extract the concept map (concepts are re-extracted only when a document changed, unless rebuildConceptMap is true), and writes a rubric per concept. Concepts and rubrics an instructor edited are kept.

202 Accepted, Location: /api/v1/jobs/{jobId}

{ "jobId": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a" }

404 when the collection isn't in your organization. 409 { "error": "this collection is already being processed (job <jobId>, Queued)" } while a processing job for it is Queued or Running: poll that job instead of queuing another. 400 { "error": "upload at least one document first (.txt, .text, .md, .markdown)" } when the collection has no readable, non-empty uploaded file.

Job status

GET /api/v1/jobs/{id}

{
  "id": "0d6c2b9e-41f7-4b55-9a5e-8c3d7f210b6a",
  "kind": "source.process",
  "state": "Running",
  "progress": 0.62,
  "progressMessage": "Writing rubric: Osmosis",
  "error": null,
  "completedAt": null
}

state is Queued, Running, Succeeded, Failed or Cancelled; progress runs from 0 to 1. A failed run is retried a few times with growing waits (the job goes back to Queued with the last error); Failed is final. Poll every few seconds. 404 for a job that isn't your organization's.

Concept map

GET /api/v1/collections/{id}/concepts

{
  "version": 3,
  "concepts": [
    { "key": "osmosis", "title": "Osmosis", "definition": "The movement of water across a semi-permeable membrane from lower to higher solute concentration." },
    { "key": "diffusion", "title": "Diffusion", "definition": "The net movement of particles from higher to lower concentration." }
  ],
  "relations": [
    { "from": "diffusion", "to": "osmosis", "kind": "prerequisite" }
  ]
}

Archived concepts are left out. 404 until the collection has been processed.

Create an exam

POST /api/v1/exams

{
  "collectionId": "6b1f0a52-7c1e-4a43-9d8e-2f1c5b7e9a10",
  "title": "Cells: oral check",
  "conceptKeys": ["diffusion", "osmosis"],
  "minutes": 20,
  "difficulty": 3,
  "maxTurns": 30,
  "mode": "Voice",
  "instructions": "Explain in your own words. 'I don't know' is fine."
}
Field Default Rules
collectionId required A processed collection of your organization.
title required 1–300 characters after trimming.
conceptKeys every current concept In the order they should be examined; no blank keys; duplicates are dropped.
minutes 20 Clamped to 1–240.
difficulty 3 Clamped to 1–5 (gentle to rigorous).
maxTurns 30 Questions in the whole exam, clamped to 1–200.
mode "Voice" "Text" or "Voice" (any case). Kept for compatibility and stored, but it no longer changes anything: every exam is taken spoken, on camera.
instructions none Shown to students.

The exam is published immediately, so its settings are frozen. Each concept gets up to six questions; integrity monitoring is Standard.

201 Created, Location: /api/v1/exams/{id}

{ "id": "a4e2d5c8-0b3f-4d91-8e7a-5c6b1f2e3d40", "conceptKeys": ["diffusion", "osmosis"] }

400 with one of { "error": "title is required" }, { "error": "title must be at most 300 characters" }, { "error": "collectionId is required" }, { "error": "conceptKeys must not contain blank keys" }, { "error": "mode must be \"Text\" or \"Voice\"" }, { "error": "the collection has no concept map yet; process it first" } (also for a collection that isn't yours), { "error": "unknown concept keys", "unknown": ["mitosis"] }, or a settings error.

Assign a student

POST /api/v1/exams/{id}/assignments

{
  "userName": "jsmith",
  "email": "jsmith@example.edu",
  "opensAt": "2026-12-01T09:00:00Z",
  "closesAt": "2026-12-08T17:00:00Z",
  "attemptsAllowed": 1
}

This assigns the exam to a student of your organization, creating the student if the user name is new:

  • An unknown userName creates an account, adds it to your organization as a Student, and returns a temporary password once in the response. The student must change it at first sign-in.
  • A userName that is already an active Student of your organization is assigned as is; its password is unchanged and temporaryPassword is null.
  • The API never changes anyone's role and never pulls an existing account into your organization:
    • a member of your organization with another role (Owner, Admin, Instructor) answers 409;
    • a deactivated member answers 409 (an admin reactivates them in the console first);
    • a user name that belongs to an existing Gadfly account that is not a member of your organization answers 409. Accounts are shared across organizations, and membership is granted only by your organization's admins (an invitation by email from the Members page), so pick a distinct user name, for example one prefixed with your app or school.
  • Assigning a student who already has this exam updates that assignment: opensAt and closesAt are set to what you send (left out or null means no limit), and attemptsAllowed is changed when you send it (left out keeps the current number). created tells you which happened.
  • opensAt and closesAt are optional; closesAt must be after opensAt. attemptsAllowed defaults to 1 for a new assignment and must be at least 1. email is used only when an account is created.

200 OK

{
  "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
  "studentUserId": "9e3b6a1d-2c4f-4e58-b7a0-d1f6c8e2a934",
  "created": true,
  "temporaryPassword": "REDACTED"
}

404 when the exam doesn't exist or isn't published. 400 { "error": "userName is required" }, { "error": "attemptsAllowed must be at least 1" }, { "error": "closesAt must be after opensAt" }, or the reason the account can't be created (for example a user name the sign-in library rejects). 409 with an error for the cases above, for example { "error": "the user name 'jsmith' belongs to an existing Gadfly account that is not a member of your organization; use a distinct user name (...)" } or { "error": "'jsmith' has the Instructor role in your organization; only students can be assigned exams, and the API never changes a member's role" }.

POST /api/v1/assignments/{id}/launch (no body)

{
  "url": "https://localhost:7311/launch?token=CfDJ8...",
  "expiresInSeconds": 900
}

404 when the assignment isn't your organization's. See the launch-link flow.

Attempts

GET /api/v1/assignments/{id}/sessions

[
  {
    "id": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
    "attempt": 1,
    "state": "Ended",
    "startedAt": "2026-12-02T14:03:11+00:00",
    "endedAt": "2026-12-02T14:19:47+00:00",
    "endReason": "Mastery"
  }
]

state is Created (opened, notice not yet accepted), ConsentGiven, Running, Paused, Ended or Failed. endReason is Mastery, Aporia, TimeUp, TurnLimit, Abandoned (the student pressed Finish) or Failed, and null while running. An empty array when there are none.

Result

GET /api/v1/sessions/{id}/result

{
  "id": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
  "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
  "studentUserId": "9e3b6a1d-2c4f-4e58-b7a0-d1f6c8e2a934",
  "state": "Ended",
  "startedAt": "2026-12-02T14:03:11+00:00",
  "endedAt": "2026-12-02T14:19:47+00:00",
  "endReason": "Mastery",
  "objectiveLevels": [
    { "title": "Explain osmosis", "level": 4, "label": "Application", "insufficient": false },
    { "title": "Predict water movement", "level": 0, "label": "Insufficient Evidence for Reliable Assessment", "insufficient": true }
  ],
  "recommendation": "mastered",
  "overallScore": 0.86,
  "report": {
    "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
    "subjectId": "...",
    "promptSetSha256": "...",
    "startedAt": "2026-12-02T14:03:11+00:00",
    "endedAt": "2026-12-02T14:19:47+00:00",
    "endReason": "Mastery",
    "recommendation": "mastered",
    "overallScore": 0.86,
    "concepts": [
      {
        "conceptId": "osmosis",
        "title": "Osmosis",
        "mastery": 0.84,
        "status": "settled-conceptual-or-above",
        "turns": 3,
        "averageScore": 0.81,
        "evidence": [
          {
            "turnIndex": 4,
            "move": "Apply",
            "question": "A cell is placed in very salty water. What happens to it, and why?",
            "quote": "Water leaves the cell because ...",
            "score": 0.9,
            "judgeSummary": "Correct direction and reason ...",
            "citations": [{ "chunkId": "1d2e3f40a5b6c7d8e9f0a1b2c3d4e5f6", "quote": "..." }]
          }
        ],
        "disputedTurns": []
      }
    ],
    "turnsJudged": 6,
    "turnsNeedingReview": 0
  },
  "grade": {
    "grade": "A",
    "score": 88,
    "comment": "Clear on osmosis; revisit active transport.",
    "decidedAt": "2026-12-03T10:12:00+00:00"
  }
}
Field Meaning
objectiveLevels The AI report's result: the level the evidence supports for each learning objective, 1 to 5, with its label. Level 0 (insufficient: true) means the evidence was insufficient to assess reliably, never zero understanding. Empty until the attempt ends, and for reports written before learning objectives. Use this, not the two fields below, wherever you show an AI result.
recommendation Deprecated; not a score. The examiner's running-estimate band (mastered, partial, not-demonstrated), which only steers which question comes next. Kept so existing integrations don't break; do not show it as the student's result. null until the attempt ends.
overallScore Deprecated; not a score. The mean of the examiner's running estimate over the examined concepts, 0 to 1: a steering aid, never a grade.
report The full AI report (per-concept mastery and status, quoted evidence with source citations, disputed turns), or null until the attempt ends. Concept status is not-examined, not-started, open, settled-conceptual-or-above (sufficient evidence at Level 3 or above), settled-below-conceptual (sufficient evidence below Level 3) or insufficient-evidence (GAD-T823); reports saved earlier may say mastered, aporia or exhausted. Like mastery, it describes the examiner's steering, not the result.
grade The latest decision of the older single-grader review, or null. The graded result comes from the grading workflow (see "Grading workflow" below): AI grades are preliminary, and a final grade exists only after human grading and approval.

When recommendation and overallScore go away

Both fields are deprecated from V2, the first release that carries objectiveLevels (GAD-T425). Gadfly itself no longer uses them: since GAD-T460 the review pages' "(override)" flag and the student's released result compare with the objective levels too. They stay in this result, in the top-level fields and inside report, and in the session.completed webhook, unchanged until they are removed.

Proposed removal: V4, two releases after V2. Proposed, not yet confirmed by the product owner. Release numbers count deployments (see DEPLOY.md), so the owner may instead set a date; this section will name whichever is agreed, and the release notes of the version before the removal will repeat it. Until then:

  • read objectiveLevels (and insufficient for Level 0) wherever you show an AI result;
  • treat recommendation and overallScore as optional now: after the removal they are simply absent from the JSON, so code that ignores unknown or missing fields keeps working;
  • there is no replacement for overallScore: no average stands in for the per-objective levels.

This endpoint returns the result whether or not the grade has been published to the student. Show students only what your own release rules allow.

Transcript

GET /api/v1/sessions/{id}/transcript?format=json&audience=reviewer

The attempt's official transcript, built from the response ledger (GAD-T295): every question with its clock time, its offset from the start of the exam and the examiner's move; every answer exactly as recorded; the read-back and its outcome; meaning clarifications; every transcription correction as original and corrected text; the response delay and pauses; and the words the speech recognizer was unsure of.

Parameter Values
format json (default), pdf, docx, html (print-ready page), txt, vtt (WebVTT captions), srt
audience reviewer (default): everything, including integrity notes, voice measurements, the examiner's reason for each question and the AI panel's exam-time reading. blind-grader: none of those. student: none of those, and only once the result has been published to the student (409 before).

Every response carries the copy's X-Transcript-Code (the verification code, e.g. 7K3M-9QXA-B2CD-EFGH) and X-Transcript-Sha256 headers, and every call is recorded in the audit log as transcript.issued. The JSON download is:

{
  "transcript": {
    "schema": "gadfly.transcript/1",
    "audience": "reviewer",
    "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
    "examTitle": "Cell biology oral",
    "studentName": "ada01",
    "attempt": 1,
    "mode": "Spoken",
    "turns": [
      {
        "number": 1,
        "concept": "Osmosis",
        "move": "Opening question",
        "moveKind": "Elicit",
        "askedAt": "2026-12-02T14:03:16+00:00",
        "offsetSeconds": 5,
        "question": "What is osmosis, in your own words?",
        "responses": [
          {
            "kind": "Answer",
            "modality": "Spoken",
            "asRecorded": "Water moves a cross a membrane.",
            "verified": "Water moves across a membrane.",
            "recordStatus": "Corrected by the student",
            "delaySeconds": 4,
            "pauses": 2,
            "readBack": { "prompt": "I recorded your answer as: ...", "outcome": "The student corrected the recording." },
            "corrections": [{ "version": 2, "original": "Water moves a cross a membrane.", "corrected": "Water moves across a membrane.", "by": "the student" }],
            "unsureWords": [{ "text": "a cross", "startSeconds": 1.1, "endSeconds": 1.6, "lowestConfidence": 0.4 }],
            "words": [{ "text": "Water", "startSeconds": 0, "endSeconds": 0.5 }]
          }
        ]
      }
    ],
    "leftOut": []
  },
  "verification": {
    "sha256": "3f0c...",
    "code": "7K3M-9QXA-B2CD-EFGH",
    "generatedAt": "2026-12-03T09:00:00+00:00",
    "verifyUrl": "https://exams.example.org/transcripts/verify?code=7K3M-9QXA-B2CD-EFGH"
  }
}

The hash is the SHA-256 of the canonical JSON of transcript (object keys in ordinal order, nulls left out, no whitespace, UTF-8); the code is its first 80 bits in Crockford base 32. Nothing that changes between downloads is inside transcript, so the same record always gives the same code. Anyone can check a code or the JSON file at /transcripts/verify (no sign-in, rate-limited); it says only whether the copy matches the record.

The same page also recognizes a completion certificate's code (GAD-T311/GAD-T379: /certificates/{sessionId}/pdf), built the same way (a canonical, deterministic JSON record of the certificate's content, hashed and coded exactly like a transcript) and checked against a freshly-rebuilt certificate, so a later amendment to the grade shows as "the record has changed since" rather than silently matching. There is no separate /certificates/verify page: a typed code is checked against transcripts first, then certificates. A certificate has no JSON download, so only its code can be checked, never an uploaded file.

Webhook registration

POST /api/v1/webhooks

{ "url": "https://lms.example.edu/hooks/gadfly", "events": ["session.completed"] }

201 Created, Location: /api/v1/webhooks/{id}

{
  "id": "e8b4c1d6-9a2f-4b3e-8d7c-6f5a4e3d2c1b",
  "url": "https://lms.example.edu/hooks/gadfly",
  "events": ["session.completed"],
  "secret": "REDACTED"
}

Store secret: it is shown only here. A runnable receiver that verifies the signature is samples/HostedApi. For local development only, a server running in the Development environment accepts https://localhost and other private targets when Gadfly:Webhooks:AllowPrivateTargets is true; production never does. 400 { "error": "Webhook URLs must be absolute https URLs." }, { "error": "Webhook URLs must be at most 1000 characters." }, { "error": "Webhook URLs must name a public host." } (localhost, .local, .internal and single-label names), { "error": "Webhook URLs must not point at private, loopback or link-local addresses." } or { "error": "Subscribe to at least one of: session.completed." } (also when events is missing). Unknown event names are ignored.

GET /api/v1/webhooks

[
  {
    "id": "e8b4c1d6-9a2f-4b3e-8d7c-6f5a4e3d2c1b",
    "url": "https://lms.example.edu/hooks/gadfly",
    "events": ["session.completed"],
    "isActive": true,
    "createdAt": "2026-11-28T09:30:00+00:00"
  }
]

Oldest first, including deactivated webhooks (isActive: false). events is an array, as everywhere in the API. Secrets are never listed.

DELETE /api/v1/webhooks/{id} deactivates the webhook: 204 No Content, or 404. Deliveries still waiting for it are dropped.

A launch link takes a student from your app straight to the exam's get-ready page.

  1. Your app assigns the exam (POST /api/v1/exams/{id}/assignments) and keeps the assignmentId.
  2. When the student clicks "Start exam" in your app, call POST /api/v1/assignments/{assignmentId}/launch and redirect the student's browser to the returned url. Ask for a fresh link each time: it is signed by the server and expires after 15 minutes.
  3. Gadfly checks the link at /launch:
    • not signed in: the student is sent to the sign-in page and then on to the exam;
    • signed in as the student the link was made for: straight to the exam's get-ready page (/my-exams/{assignmentId}/start);
    • signed in as someone else: "This exam link belongs to a different student";
    • expired or altered: "This exam link has expired or is not valid. Ask for a new one."
  4. The student runs the system check, accepts the notice and takes the exam.
  5. When the attempt ends you receive session.completed, then read GET /api/v1/sessions/{sessionId}/result.

The student still signs in with their Gadfly user name and password; one-click sign-in from an API launch link needs trusted-launch support in MindAttic.Authentication and is not built. For one-click launch from an LMS, use the LTI 1.3 connection below, which signs the student in.

LMS connection (LTI 1.3)

Gadfly is an LTI 1.3 / LTI Advantage tool (Core 1.3, Deep Linking 2.0, Names and Role Provisioning 2.0, Assignment and Grade Services 2.0), set up per organization on Organization → LMS connection (/org/lti); the step-by-step guide for Canvas, Moodle, Blackboard and Brightspace is docs/guides/lti-setup.md. These are the addresses a platform calls. None takes an API key: each is checked on LTI's own terms.

Endpoint Called by What it does
GET or POST /lti/login the platform (OIDC third-party-initiated login) Takes iss, login_hint, and optionally client_id, lti_deployment_id, lti_message_hint, target_link_uri. Finds the one enabled connection they name, records a single-use state and nonce (10 minutes), sets them in a SameSite=None; Secure; Partitioned cookie on /lti, and redirects to the platform's authorization endpoint (response_type=id_token, response_mode=form_post, prompt=none). An unknown or ambiguous platform gets a plain error page.
POST /lti/launch the platform (form post of id_token and state) The redirect URI, target link URI and deep-linking URL. Validates the launch (below), then: a deep-linking request shows instructors the exam picker; a resource-link request signs a student in and opens /my-exams/{assignmentId}/start (inside a frame it offers an "open in a new window" button instead); an instructor is told the placement is linked and pointed at the normal MFA sign-in.
GET /lti/jwks.json the platform Gadfly's public key set ({"keys":[{"kty":"RSA","kid":…,"use":"sig","alg":"RS256","n":…,"e":…}]}), for verifying the deep-linking response and the client assertion. Cached 5 minutes.
POST /lti/deep-link/submit the picker page Turns the chosen exam(s) into a signed LtiDeepLinkingResponse and posts it to the platform's deep_link_return_url. Carries a protected 30-minute continuation token, never a session.
POST /lti/continue the "open in a new window" button Exchanges a protected, single-use, two-minute hand-off token for the student's sign-in. Single use is recorded in the database, so it holds across server instances.
POST /lti/link/send the "Email me a link to connect it" button Emails a single-use, 24-hour link to an existing account's verified address and sets a cookie binding that link to this browser (see People and roles).
GET, POST /lti/link the emailed link GET only shows what will happen; the POST links the LMS identity to the account, when the token is valid and the browser has the matching cookie.

Launch validation. A launch is accepted only when all of these hold: the state is one Gadfly issued, unused and under 10 minutes old (it is consumed atomically, so a launch posts at most once); the browser presents the same state in its cookie (so someone else's launch can't be posted into your browser); the id_token is a JWS signed with RS256 (never none or HMAC) by a key in the platform's JWKS (fetched over https, cached 10 minutes, re-fetched once when the kid is unknown); iss is the connection's issuer; aud contains its client id and azp, when present or when there are several audiences, equals it; exp and iat are present and current (60 seconds of skew); the nonce matches the one issued with this state; the LTI version is 1.3.0; the deployment_id is the connection's; and a message type and sub are present. A launch that passes every check but arrives without the state cookie (browsers that block every cookie inside a frame) is not accepted in that browser context: Gadfly answers with an "Open in a new window" page whose button sends the platform's own iss, client_id, lti_deployment_id, login_hint, lti_message_hint and target_link_uri to /lti/login in a new top-level window, where the cookie works. A cookie that comes back with a different state is refused.

People and roles. A platform user (sub, per connection) maps to one Gadfly account, created on first sight with the name and email the platform sent and a random password nobody is told. Course roles map as: Instructor, Teaching Assistant, Content Developer and course Administrator → Instructor; Learner → Student; anything else is refused. The LMS can move a student up to instructor, never down, never to Owner or Admin, and never restore a member an admin removed. New members take a seat under the organization's plan. An LTI sign-in (amr=lti) never satisfies MFA, so it only ever reaches student pages. When the platform's email equals exactly one active member's, no account is created and nothing is linked until it is confirmed, by an admin on the LMS connection page or by the person through a link emailed to that account's verified address (it works only in the browser that asked for it); never by the email alone.

Deep linking. Each exam chosen becomes an ltiResourceLink content item with custom.examId and a lineItem (scoreMaximum 100, labelled with the exam title). The first launch of that placement records it.

Roster (NRPS). An admin syncs a placement's course roster from the LMS connection page, and each connection also refreshes its rosters through the job queue every RosterRefreshHours (24 by default, 0 for on request only); Gadfly reads every page of the membership container (following Link: rel="next"), skips inactive and deleted members, and maps the rest exactly as a launch would.

Grades (AGS). Within about two minutes of a result being released to the student (finalized and published with approval), Gadfly posts the latest attempt's final percentage to the placement's line item: POST {lineitem}/scores, application/vnd.ims.lis.v1.score+json, scoreGiven 0 to 100, scoreMaximum 100, activityProgress Completed, gradingProgress FullyGraded. If the launch gave only a line-items collection, Gadfly creates the line item first. An amended grade is sent again; an unchanged one never is. Integrity notes are never sent. A send the platform refuses or doesn't answer is retried after 2 minutes, then 4, 8 and so on (at most 12 hours apart), up to 8 tries; then it is marked failed on the LMS connection page until an admin retries it or the grade changes. Service tokens come from the platform's token endpoint with a signed RS256 client assertion (RFC 7523), audience the token URL or the connection's token audience (Brightspace).

All outgoing calls (key set, token, roster, gradebook) go only to public https hosts, checked after DNS resolution, without following redirects.

Webhooks

Deliveries go only to public addresses: the host is resolved at each delivery and a name that resolves to a private, loopback, link-local or reserved address is refused (no request is sent), and redirects are not followed (a 3xx answer counts as a failed attempt and is retried).

Payload

Each delivery is a POST with a JSON body:

{
  "type": "session.completed",
  "createdAt": "2026-12-02T14:19:48.1234567+00:00",
  "data": {
    "sessionId": "5a7d9c2e-3f1b-4e6a-8c0d-b2e4f6a8c1d3",
    "assignmentId": "c2f7e1a9-5d64-4b0e-9f3a-71b8d2c4e605",
    "studentUserId": "9e3b6a1d-2c4f-4e58-b7a0-d1f6c8e2a934",
    "examId": "a4e2d5c8-0b3f-4d91-8e7a-5c6b1f2e3d40",
    "endReason": "Mastery",
    "objectiveLevels": [{ "title": "Explain osmosis", "level": 4, "label": "Application", "insufficient": false }],
    "recommendation": "mastered",
    "overallScore": 0.86
  }
}

session.completed is sent once per attempt, when it ends for any reason. objectiveLevels is the AI's result per learning objective; recommendation and overallScore are deprecated steering values, not a score, proposed for removal in V4 (see Result). The instructor's grade comes later; read it from the result endpoint.

Header Value
Content-Type application/json; charset=utf-8
X-Gadfly-Event The event type, e.g. session.completed
X-Gadfly-Delivery The delivery id. Retries of the same delivery carry the same id: use it to ignore duplicates.
X-Gadfly-Signature t=<unix seconds>,v1=<hex HMAC-SHA256>
User-Agent Gadfly-Webhooks/1

Answer with any 2xx within 15 seconds. Anything else (or no answer) is retried with growing waits (15 seconds, doubling, at most an hour apart), up to 8 attempts in all.

Verifying the signature

v1 is the lowercase hex HMAC-SHA256 of the string "<t>.<body>", keyed with the webhook's secret (the whole whsec_... string, as UTF-8). t is the time the attempt was signed. To verify:

  1. Read the raw request body, exactly as received, before any JSON parsing.
  2. Split the header on , and each part on the first = to get t and v1.
  3. Reject the request if t is more than five minutes from your clock.
  4. Compute the HMAC over t + "." + body and compare it with v1 in constant time.

C#:

using System.Security.Cryptography;
using System.Text;

static bool VerifyGadflySignature(string secret, string header, string rawBody, int toleranceSeconds = 300)
{
    var fields = header.Split(',')
        .Select(p => p.Split('=', 2))
        .Where(p => p.Length == 2)
        .ToDictionary(p => p[0].Trim(), p => p[1].Trim());
    if (!fields.TryGetValue("t", out var t) || !fields.TryGetValue("v1", out var v1)) return false;
    if (!long.TryParse(t, out var ts) || Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) > toleranceSeconds) return false;

    using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
    var expected = Convert.ToHexString(hmac.ComputeHash(Encoding.UTF8.GetBytes($"{t}.{rawBody}"))).ToLowerInvariant();
    return CryptographicOperations.FixedTimeEquals(Encoding.ASCII.GetBytes(expected), Encoding.ASCII.GetBytes(v1));
}

Node.js:

import crypto from "node:crypto";

export function verifyGadflySignature(secret, header, rawBody, toleranceSeconds = 300) {
  const fields = {};
  for (const part of header.split(",")) {
    const i = part.indexOf("=");
    if (i > 0) fields[part.slice(0, i).trim()] = part.slice(i + 1).trim();
  }
  const { t, v1 } = fields;
  if (!t || !v1 || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;

  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`, "utf8").digest("hex");
  const a = Buffer.from(expected, "utf8");
  const b = Buffer.from(v1, "utf8");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

// Express: keep the raw body for verification.
// app.post("/hooks/gadfly", express.raw({ type: "application/json" }), (req, res) => {
//   const ok = verifyGadflySignature(process.env.GADFLY_WEBHOOK_SECRET, req.get("X-Gadfly-Signature"), req.body.toString("utf8"));
//   if (!ok) return res.sendStatus(401);
//   const event = JSON.parse(req.body.toString("utf8"));
//   res.sendStatus(204);
// });

Errors

Status When Body
400 Bad Request A rule above isn't met { "error": "<what to fix>" }; unknown concept keys add "unknown": [...]
400 Bad Request The body isn't valid JSON or is missing No JSON body
401 Unauthorized Missing, unknown or revoked key; deactivated organization Empty
404 Not Found The id doesn't exist in your organization Empty
409 Conflict The request clashes with current state: processing already queued or running; assigning a non-student, a deactivated member, or an account outside your organization { "error": "<what to do>" }
429 Too Many Requests More than the rate limit (below) Empty; Retry-After gives the seconds to wait
500 Internal Server Error An unexpected server error No stable shape

Every id is checked against your organization, so another organization's ids answer 404, never their data. There is no pagination. Each API key may make 120 calls a minute, in bursts of up to 60; past that the API answers 429 with Retry-After. Launch links are limited to 30 a minute per IP address.

OpenAPI

The OpenAPI document is served anonymously at /openapi/v1.json (for example https://localhost:7311/openapi/v1.json). It lists every /api/v1 route with its request body and its response bodies as named schemas (CollectionDetail, JobStatus, ExamCreated, AssignmentResult, WebhookView, ApiError and so on). It declares the API key as an HTTP bearer security scheme named ApiKey (components.securitySchemes.ApiKey) and requires it on every /api/v1 operation, so generated clients send Authorization: Bearer gfk_.... The result endpoint is not given a named schema; its shape is documented above. /launch is a browser page and is not in the document.

Grading workflow

The human grading workflow (master plan Parts 8-11) can be driven over HTTP as well as from the Grading pages: blind human grades, reconciliation, approval, publication, appeals and amendments, plus a status read. These are not /api/v1 calls: each one is an accountable act by a person, so they take the signed-in cookie of a member of the organization (the API key is not accepted) and act in that member's role. The demo tour (docs/TOUR.md) drives the whole workflow through them; an integrator can use them on behalf of a person who has signed in.

Every rule is the grading service's, the same one the pages use: the role permission from the permission matrix (Part 16.2), with every refused attempt written to the audit log as access.denied; the grade-status machine (an invalid move is refused and audited as grade.transition.refused); the blind rule; and an audit event for every change (grade.human.recorded, grade.disagreement.detected, grade.reconciled, grade.approved, grade.published, grade.appeal.opened, grade.amended, and so on).

Antiforgery

Every POST needs the antiforgery request token in the RequestVerificationToken header, sent with the cookies of the same signed-in session:

GET /grading/actions/antiforgery
→ 200 { "headerName": "RequestVerificationToken", "token": "CfDJ8..." }

A missing or wrong token answers 400 with { "ok": false, "message": "Missing or invalid antiforgery token: ..." }.

Actions

Every path below starts with /grading/actions/{sessionId}. Bodies are JSON. Each action answers { "ok": true|false, "message": "<what happened, in words>", "status": "<grade status after the call>" }.

Method and path Who (permission) Body Effect
POST .../ai-grading Examiner, Teacher, Admin, Owner {} Starts (or retries) AI grading of an ended session
POST .../human-grades Examiner, Teacher (EnterHumanScore) { "grades": [ { "objectiveKey" or "objectiveId", "level", "score", "comment"?, "evidenceNote"? } ] } Human Review Pending → Reconciliation Required or Awaiting Final Approval. One grade per objective, every objective required; earlier grades are kept and superseded
POST .../human-grades/reopen Examiner, Teacher { "reason" } Back to Human Review Pending, to adjust the human grades
POST .../second-review Teacher, Admin, Owner, Second Reviewer (ReconcileDisagreement) { "disagreementId", "reviewerUserId" } Asks a member holding the Second Reviewer role to reconcile
POST .../reconciliations ReconcileDisagreement or ActAsSecondReviewer { "disagreementId", "cause", "resolution", "resolvedAiScore"?, "resolvedHumanScore"?, "secondReviewerUserId"? } Documents the resolution and recalculates; Awaiting Final Approval once no mandatory disagreement is open. cause is one of error-in-ai, error-in-human, transcript-ambiguity, rubric-interpretation, both-defensible. A second reviewer who acts is recorded as the second reviewer. Refused (409) for the person who entered this grade's human score (separation of duties)
POST .../approve Teacher, Admin, Owner (ApproveFinalGrade) { "label"?, "note"? } Awaiting Final Approval → Finalized, with a Finalize approval record. Refused (409) while a mandatory disagreement is open, and for the person who entered this grade's human score (separation of duties)
POST .../publish Teacher, Admin, Owner (PublishGrade) { "note"? } Finalized → Published, with a Publish record. Refused (409) without a Finalize record
POST .../appeals The student whose published result it is (AppealOwnResult) { "reason" } Published or Amended → Under Appeal
POST .../appeals/{appealId}/resolve Teacher, Admin, Owner (ResolveAppeal) { "outcome": "Upheld" or "Dismissed", "resolution" } The grade stands: back to Published
POST .../amend Teacher, Admin, Owner (AmendGrade, plus ResolveAppeal with appealId) { "grades": [ changed objectives ], "reason", "appealId"? } Published or Under Appeal → Amended: new human grades supersede the old ones, the combined score is recalculated under the frozen policy, and the appeal (if given) is resolved as Amended. While an appeal is open, appealId is required: an amendment that doesn't name it is refused, so the appeal is never left open behind an amended grade

Separation of duties (GAD-T285). Reconciliation and approval are refused (409, "Refused: you entered this grade's human score, ...", audited as grade.separation-of-duties.refused) when the caller entered any human score of that session's grade. An organization that has turned on Allow a single grader in its settings (off by default) lets them through, and each one is audited as grade.separation-of-duties.waived. The status read says where the caller stands in separationOfDuties.

level is a mastery level by name or number: InsufficientEvidence (0), Recognition (1), BasicExplanation (2), ConceptualUnderstanding (3), Application (4), TransferAndCriticalReasoning (5). score is on the objective's own scale (0 to its maxScore).

Status When
200 Done (ok: true)
400 A missing or invalid field, an unknown objective or level, a missing antiforgery token, or another rule of the action (the message says which)
403 The caller's role lacks the permission (audited as access.denied), or a student appeals a result that isn't their own published one
404 (status read) The session isn't in the organization, or a student's result isn't published yet
409 The grade-status machine refused the move ("Refused: ...", audited as grade.transition.refused), or separation of duties did (audited as grade.separation-of-duties.refused)

Example: the examiner submits blind grades.

POST /grading/actions/6b72ef45-.../human-grades
RequestVerificationToken: CfDJ8...
Content-Type: application/json

{ "grades": [
    { "objectiveKey": "equal-groups", "level": "BasicExplanation", "score": 4, "comment": "Repeated addition only." },
    { "objectiveKey": "factor-roles", "level": "BasicExplanation", "score": 5 },
    { "objectiveKey": "scaling", "level": 2, "score": 5 } ] }

→ 200 { "ok": true, "status": "ReconciliationRequired",
        "message": "Human grades saved. The AI and human scores disagree substantially: reconciliation is required before this grade can be finalized." }

Status

GET /grading/actions/{sessionId}, for a reviewer (ViewTranscripts):

{
  "sessionId": "6b72ef45-...", "examTitle": "Demo: Understanding multiplication", "student": "demo.student", "attempt": 1,
  "status": "ReconciliationRequired", "statusLabel": "Reconciliation Required",
  "aiVisible": true, "isMock": true, "finalPercent": 46.67, "label": null,
  "separationOfDuties": { "youScoredThisGrade": false, "singleGraderAllowed": false, "blocksYou": false },
  "policy": { "aiWeight": 0.4, "humanWeight": 0.6, "additionalReviewAt": 10, "mandatoryReconciliationAt": 20, "blindHumanGrading": true, "source": "exam-policy" },
  "aiGradingJob": { "state": "Succeeded", "error": null },
  "responsesNeedingHuman": 0,
  "objectives": [ {
    "id": "...", "key": "equal-groups", "title": "...", "maxScore": 10, "weight": 1, "aiRecorded": true,
    "ai": { "level": "Application", "levelNumber": 4, "score": 8, "maxScore": 10, "confidence": "...", "isMock": true, "explanation": "[MOCK] ...", "excluded": false },
    "human": { "id": "...", "level": "BasicExplanation", "levelNumber": 2, "score": 4, "maxScore": 10, "wasBlind": true, "reviewer": "demo.examiner",
               "reviewerRole": "Examiner", "comment": "...", "submittedAt": "...", "supersedes": null },
    "humanHistory": 1,
    "combined": { "aiScore": 8, "humanScore": 4, "combined": 5.6, "differencePoints": 40, "band": "MandatoryReconciliation" } } ],
  "disagreements": [ { "id": "...", "objectiveId": "...", "objectiveKey": "equal-groups", "aiScore": 8, "humanScore": 4, "differencePoints": 40,
                       "band": "MandatoryReconciliation", "resolved": false, "resolvedAt": null, "needsReconciliation": true, "reconciliations": [] } ],
  "approvals": [ { "action": "Finalize", "actor": "demo.teacher", "role": "Instructor", "note": "...", "at": "..." } ],
  "appeals": [ { "id": "...", "state": "Open", "reason": "...", "resolution": null, "openedAt": "...", "resolvedAt": null } ],
  "secondReviewers": [ { "userId": "...", "name": "demo.reviewer" } ]
}

Blind grading. While the policy is blind and the grade has not passed the human evaluation (Human Review Pending or earlier), aiVisible is false and nothing derived from the AI is returned: every objective's ai and combined are null, finalPercent is null, disagreements is empty and isMock is false. aiRecorded says only that an AI grade exists. Once the human grades are submitted, reviewers see the AI's evaluation.

A student asking for their own session gets 404 until the grade is approved and published (the attempt is audited as access.denied). After that they get their result as the student's assessment report shows it, without reviewer names, voters or audit detail:

{ "sessionId": "...", "examTitle": "...", "attempt": 1, "status": "Published", "statusLabel": "Published",
  "finalPercent": 60, "label": "Tour", "isMock": true,
  "objectives": [ { "key": "...", "title": "...", "maxScore": 10, "aiScore": 8, "aiLevel": "...", "humanScore": 8, "humanLevel": "...", "combined": 8 } ],
  "knowledgeGaps": [ "..." ], "approvals": [ "2026-11-20 20:03 UTC · Final grade approved by Teacher" ],
  "appeals": [ { "id": "...", "state": "Open", "resolution": null, "openedAt": "...", "resolvedAt": null } ] }

Other members without a reviewer permission get 403 (audited). The per-objective assessment report downloads at /grading/{sessionId}/report.md, /grading/{sessionId}/report.csv and /grading/{sessionId}/report.pdf (reviewers) and /my-results/{sessionId}/report.md and /my-results/{sessionId}/report.pdf (the student, once published). The PDF (GAD-T311/GAD-T377) says the same thing in the same order as the Markdown (per objective: the AI and examiner levels, what was missing, the next level's descriptor), laid out with the same hand-written PDF engine the transcript downloads use (GAD-T295) rather than a new PDF dependency.

GET /grading/exam/{examId}/class-summary.pdf (reviewers, ViewTranscripts; GAD-T311/GAD-T378): a class summary PDF for instructors, aggregated over every student assigned to that exam — score distribution (mean, median, a 10-point histogram), each learning objective's class average and who hasn't completed the exam yet. Only released results (published to the student) feed the distribution and averages; an attempt that has ended but is still awaiting grading or release is counted separately and never named, and a student with no ended attempt is listed by name so the instructor can follow up.

GET /certificates/{sessionId}/pdf (GAD-T311/GAD-T379): a student's completion certificate once their result is released (409 with a plain-English reason before then; the same entitlement check as the transcript download, so a session id from elsewhere looks like 404 either way). Carries its own verification code and SHA-256, checked at the transcript's own verify page (next section) rather than a separate one.

Reconciliation triggers

Besides the AI-human difference bands, an objective goes to reconciliation (band MandatoryReconciliation, status ReconciliationRequired) when its panel is split (members' rubric levels differ by more than maxPanelSpreadLevels, default 1) or its score sits on a boundary (the AI and human scores fall on opposite sides of one of scoreBoundaries, default 50% of the objective's maximum, or the combined score is within boundaryMarginPoints, default 2.5, of one). An objective already reconciled once is not sent again by these triggers. The grade.disagreement.detected audit event lists the triggers that fired (GAD-T270; research note 05).

Research export

GET /admin/research/export.zip[?exam={examId}] (owners and admins, GadflyPolicies.OrgAdmin; GAD-T451) returns a ZIP of CSV files for a study of the organization's exams (docs/PILOT.md, "Research export", lists every file and column), with README.txt and manifest.json (counts, the smallest group used, what was held back). 404 with a plain reason when research has never been set up on Research (/org/research).

  • Only students whose current research choice is "agreed" are included (GAD-T452). Declined, never answered, withdrawn and erased students are left out and only counted in the manifest.
  • No name, email, user name, answer or question text, audio, video, free-text comment, appeal text or database id. Ids become keyed pseudonyms (S- student, X- session, E- exam, O- objective, R- rater, A- arm; HMAC-SHA256 with the organization's research key, stable across exports until the key is replaced). Times are relative to the session.
  • Voice measurements are blank wherever they were off, and always for an EU/EEA organization or student.
  • An exam with fewer consenting students than the organization's smallest group (default 5) is held back; a rarer accommodation within an exam is written suppressed.
  • Each download is audited as research.exported (who, which exam, counts; no data).

Panel calibration

A grading panel is accepted for an exam only after a blind, double-marked calibration set meets the thresholds (Williamson et al. 2012, as reported in research note 05): panel-human QWK at least .70, no more than .10 below the human-human QWK, and |SMD| under .15, on at least 30 answers. The panel is compared with each marker and the weaker comparison counts. Levels are the rubric's mastery levels 0..5.

POST /grading/calibration/{examId} (ApproveGradingPolicyChange; antiforgery token as above):

{ "panel": "claude-sonnet-5, gpt-5, gemini-3 (majority of levels)",
  "items": [ { "itemId": "s01-equal-groups", "panelLevel": 3, "humanALevel": 3, "humanBLevel": 2 } ] }

→ 200 { "ok": false, "accepted": false, "message": "Panel not accepted for this exam. ...",
        "report": { "items": 12, "humanHumanQwk": 0.81, "panelHumanQwk": 0.66, "degradation": 0.15, "smd": 0.21,
                    "accepted": false, "failures": [ "..." ], "thresholds": { "minQwk": 0.7, "maxDegradation": 0.1, "maxAbsSmd": 0.15, "minItems": 30 } } }

panel is optional: it defaults to the configured members and their models. The model id of every member is stored with the evaluation (GAD-T429), and so is the grading prompt-set version (GAD-T469). A calibration of the mock panel is never accepted.

Every evaluation, passing or failing, is recorded as an audit event (panel.calibration.evaluated), and the latest one is the exam's status: GET /grading/calibration/{examId} (ViewTranscripts) returns it, or 404 when none is recorded:

{ "examId": "…", "panel": "claude: claude-sonnet-5, openai: gpt-5", "accepted": true, "report": { … }, "at": "…",
  "models": { "claude": "claude-sonnet-5", "openai": "gpt-5" }, "gradingPromptVersion": 1, "source": "double-marking",
  "expired": false, "expiryReasons": [], "recheckDue": false, "effective": true }

expired is true when any panel member's model id now differs from those the calibration covered (a member swapped, added or removed, or a calibration recorded before model ids were kept), or when the grading prompts' version differs from gradingPromptVersion (GAD-T469; a calibration recorded before versions were kept counts as version 1); expiryReasons says which. effective is accepted && !expired. recheckDue is true once the calibration is older than Gadfly:Grading:RecalibrateAfterDays (default 180): a prompt to re-run it and the bias probes; nothing re-runs by itself. source is api (posted here) or double-marking (built in the app from blind second marks, GAD-T428; only answers whose AI grade came from the models the panel runs now and the current grading prompt-set version count, GAD-T480/GAD-T484 — every AI grade records its version, and grades made before versions were kept count as version 1).

When AI grading of a session starts, the status is frozen into its policy snapshot (panel, with expired). An exam set to human-only until calibrated (GAD-T427) also freezes gate: { "applied": true, "reason": "…" } when the session is graded with AI weight 0 and human weight 1 because the calibration is missing, not accepted or expired. The grading page describes what the calibration measured, never just "calibrated". The AI grade is never final either way. Double marking, the gate setting, bias probes and the self-preference check are pages, not API endpoints (/grading/panel, /grading/second-mark/{examId}, /grading/bias/{examId}, /grading/self-preference/{examId}); their records are audit events (panel.settings.updated, grade.second-mark.recorded, panel.bias-probe.*, bias.human-probe.*) readable through the audit log.

Part of Gadfly.
From Gadfly/docs/API.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.