Audit
Audit endpoints of the MedHook engine API: 24 operations with parameters, schemas and a curl example for each.
On this page
- PHI access: today's figures and the latest views
- Who viewed a patient's PHI
- PHI access report for one patient (PDF)
- Query the audit log
- Verify the audit log hash chain
- People of the workspace
- One person's audit figures
- Flags of the workspace
- One flag with its rule, context and related events
- Mark a flag reviewed
- Assign a flag to an admin
- Open an incident from a flag
- Legal holds
- Add a legal hold (a draft)
- Edit or start a draft legal hold
- Release a legal hold, or discard a draft
- How long records are kept
- Who the HIPAA access report goes to, and when
- HIPAA access report for a month (PDF)
- Send the HIPAA access report to the privacy officer now
- The Audit log header: retention and the log exporter
- The latest daily audit anchor
- Ask the audit log
- Open the document an audit event holds
- Schemas
The audit log and its hash chain.
PHI access: today's figures and the latest views
get/api/audit/phi-access
Reads every PHI view of the caller's workspace: the phi.revealed events (written whenever someone shows PHI with a reason), and the message.viewed (a message opened, with the screen it was opened from) and ai.chat.tool_call (the Agent's masked read of a message, shown as the Agent, from engine) events that name a patient. Each event lists the patients shown by a keyed hash of the MRN (HMAC under the engine's auth secret, of the MRN trimmed, cut at its first ^ and upper-cased), never the MRN. Rotating the auth secret changes every hash. Returns the PHI access tab's figures for today (views, people, flagged views, views by identities outside the workspace) and the latest 50 views of the last 90 days. One person's run of ACK queue Edit & replay views of one patient (each within 5 minutes of the next, at most 30 minutes) is one row, "{n} messages in the ACK queue", flagged when any of its views is. Support identities (MedHook staff) count as outside the workspace whatever their role or grant. An mrn query parameter is refused with 400: look a patient up with POST so the MRN never goes in a URL. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getPhiAccess
Parameters
| Name | In | Type | Description |
|---|---|---|---|
since | query | string (date-time) | Where today starts (the viewer's local midnight), within the last 2 days; default UTC midnight. |
Responses
- 200Figures and rows.
Response fields
application/json · object
kpisobject4 fields
viewsTodayintegerpeopleintegerPeople who viewed PHI today (not API clients).
flaggedintegerBursts today: one per identity and patient with more than 20 views within 5 minutes.
outsideWorkspaceinteger
rowsarray of object8 fields
idstringAudit event id.
atstring (date-time)userIdstring | nullWho: the recorded identity.
whatstringWhat they saw, e.g. "MSG00412 · fields and raw" or "38 messages in Messages". Message ids only, never content.
reasonstringTroubleshooting, Patient request or Audit.
fromstringThe client IP, or "engine" for a reveal without one.
flaggedbooleanMore than 20 views of one patient by one person within 5 minutes.
outsideWorkspacebooleanThe identity doesn't belong to this workspace: neither a member nor an admin (a removed user), an API client scoped elsewhere or unknown, or the desktop app.
windowobject2 fields
fromstring (date-time)tostring (date-time)
dayStartstring (date-time)
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/phi-access" \
-H "Authorization: Bearer $TOKEN"Who viewed a patient's PHI
post/api/audit/phi-access
Reads every PHI view of the caller's workspace: the phi.revealed events (written whenever someone shows PHI with a reason), and the message.viewed (a message opened, with the screen it was opened from) and ai.chat.tool_call (the Agent's masked read of a message, shown as the Agent, from engine) events that name a patient. Each event lists the patients shown by a keyed hash of the MRN (HMAC under the engine's auth secret, of the MRN trimmed, cut at its first ^ and upper-cased), never the MRN. Rotating the auth secret changes every hash. Matches the MRN in the body through its keyed hash and returns that patient's views in the window (up to 500, newest first; at most 2190 days). The lookup is audited as audit.phi_access_searched with the hash; nothing is returned if that record can't be written. 503 PATIENT_KEY_UNAVAILABLE when the engine has no auth secret. Rate limited to 30 requests per minute.
Minimum role: operator.
Auth: Bearer token (how to get one) · Operation: lookupPhiAccess
Request body (required)
application/json · object
mrnstringrequiredThe patient's MRN (letters, digits, . _ ^ -; at most 64). Used only to compute its keyed hash; never stored, logged or returned.
fromstring (date-time)Window start; default 90 days before
to.tostring (date-time)Window end; default now.
Responses
- 200The patient's views.
Response fields
application/json · object
patientobject2 fields
viewsintegernotestring"last 90 days · 4 views". The patient's name is never stored.
rowsarray of object8 fields
idstringAudit event id.
atstring (date-time)userIdstring | nullWho: the recorded identity.
whatstringWhat they saw, e.g. "MSG00412 · fields and raw" or "38 messages in Messages". Message ids only, never content.
reasonstringTroubleshooting, Patient request or Audit.
fromstringThe client IP, or "engine" for a reveal without one.
flaggedbooleanMore than 20 views of one patient by one person within 5 minutes.
outsideWorkspacebooleanThe identity doesn't belong to this workspace: neither a member nor an admin (a removed user), an API client scoped elsewhere or unknown, or the desktop app.
cappedbooleanMore than 500 views.
windowobject2 fields
fromstring (date-time)tostring (date-time)
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/phi-access" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"mrn": "string",
"from": "2026-01-01T00:00:00Z",
"to": "2026-01-01T00:00:00Z"
}'PHI access report for one patient (PDF)
post/api/audit/phi-access/report
Reads every PHI view of the caller's workspace: the phi.revealed events (written whenever someone shows PHI with a reason), and the message.viewed (a message opened, with the screen it was opened from) and ai.chat.tool_call (the Agent's masked read of a message, shown as the Agent, from engine) events that name a patient. Each event lists the patients shown by a keyed hash of the MRN (HMAC under the engine's auth secret, of the MRN trimmed, cut at its first ^ and upper-cased), never the MRN. Rotating the auth secret changes every hash. The same lookup as POST /api/audit/phi-access, as a US Letter PDF for the privacy officer: when, who, what they saw (message ids), reason and IP, flagged views marked. The patient appears only as a masked MRN (55••••) and the filename carries the date only; no message content. Audited as audit.phi_access_report with the hash; no PDF is served if that record can't be written. Rate limited to 10 requests per minute.
Minimum role: operator.
Auth: Bearer token (how to get one) · Operation: phiAccessReport
Request body (required)
application/json · object
mrnstringrequiredThe patient's MRN (letters, digits, . _ ^ -; at most 64). Used only to compute its keyed hash; never stored, logged or returned.
fromstring (date-time)Window start; default 90 days before
to.tostring (date-time)Window end; default now.
Responses
- 200The report.
application/pdf · string (binary)
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/phi-access/report" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"mrn": "string",
"from": "2026-01-01T00:00:00Z",
"to": "2026-01-01T00:00:00Z"
}'Query the audit log
get/api/audit-log
Audit events for the caller's workspace, newest first. A viewer can read and search the log. export=csv downloads up to 10,000 rows and needs the admin role. Cells that a spreadsheet would run as a formula are written as text. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: queryAuditLog
Parameters
| Name | In | Type | Description |
|---|---|---|---|
from | query | string (date-time) | Only events at or after this ISO 8601 time. |
to | query | string (date-time) | Only events at or before this ISO 8601 time. |
eventType | query | string | One event type, or several separated by commas. |
resourceType | query | string | One resource type. |
q | query | string | Search the actor, resource, event type, IP address or id. |
category | query | string | An Activity chip: |
page | query | integer | Page number, from 1. |
limit | query | integer | Entries per page. |
export | query | string | Set to |
counts | query | string | Set to |
Responses
- 200A page of events, or a CSV file when `export=csv`.
Response fields
application/json · object
entriesarray of object11 fields
idstringtimestampstring (date-time)eventTypestringresourceTypestringresourceIdstringactionstringuserIdstring | nullipAddressstring | nulluserAgentstring | nullmetadataobjectEvent details. Values under keys such as
password,secret,tokenandkeyare replaced by[redacted].flaggedbooleanAn open or assigned flag holds this event (the Activity tab's FLAG marker). JSON list only.
paginationobject4 fields
pageintegerlimitintegertotalintegertotalPagesinteger
retentionDaysintegerAUDIT_LOG_RETENTION_DAYS, 2190 by default.actorsmap of objectThe people this page names, keyed by the identity the events record (
userId, or an Agent proposal'smetadata.approvedBy): an email or a user id. The detail panel's Who reads "Chris J. · Admin" from it. One query over engine users for the page, never per row. The Agent, the engine, the desktop app and API clients are never listed, nor identities with no engine user. Empty when the names can't be read.categoryCountsobjectWith
counts=1only: per chip, the events that match every other filter.7 fields
allintegerchangesintegerphiintegersigninsintegeragentintegeraccessintegersysteminteger
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit-log" \
-H "Authorization: Bearer $TOKEN"Verify the audit log hash chain
get/api/audit-log/verify
Walks every chained audit row in order, recomputes each hash and checks each link. 200 with ok: true when the chain is intact. 409 with brokenAt (id, chainSeq and a reason of hash, link or gap) at the first bad row. unchained counts rows written before chaining existed. The oldest retained row is the anchor, so pruning by retention is not reported as tampering. The daily anchors (GET /api/audit-log/anchor) are checked too: an anchored row whose hash differs, or an anchor past the head, is a 409 with anchorMismatch (date, lastSeq) and brokenAt.reason anchor; anchorsChecked counts the anchors inside the retained chain. The walk runs as a background job, so no request has to outlast it: this request starts a walk (or joins the one already running on any engine) and walks it for up to 3 seconds (AUDIT_VERIFY_REQUEST_BUDGET_MS). Finished by then, it answers the result with its jobId. Otherwise 202 with {jobId, status: "running", joined, progress} and a Location to poll; the engine walks on in the background, resuming from its stored place after a restart, and jobId= answers 202 with progress until the result (200 or 409 as above, or 500 when the walk gave up after repeated failures). Each walk's result, its anchorMismatch included, is stored for cached=1 when the walk ends, and the Audit log badge reads it on page load. Starting a walk is rate limited to 5 per minute; polling jobId= to 300 per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: verifyAuditLog
Parameters
| Name | In | Type | Description |
|---|---|---|---|
pageSize | query | integer | Rows read per step, 1 to 5000. |
jobId | query | string (uuid) | A running walk's |
cached | query | string | Set to |
Responses
- 200The chain is intact.
Response fields
application/json · object
okboolean | nullnullwithcached=1when no walk is stored.cachedbooleanPresent with
cached=1.checkedintegereventCountintegerEvery retained audit event, chained and unchained (absent on walks stored before it).
unchainedintegerAbsent with
cached=1.firstSeqinteger | nulllastSeqinteger | nullheadHashstring | nullbrokenAtany | nullverifiedAtstring (date-time)jobIdstring (uuid)The walk's id. Absent with
cached=1.
- 202The walk is still running (it outlived this request): poll the `Location`.
Response fields
application/json · object
jobIdstring (uuid)statusstringOne of: "running"
joinedbooleanTrue when this request joined a walk already running. Absent on a poll.
progressobject4 fields
checkedintegerRows verified so far.
percentinteger0 to 99 while the walk runs.
lastSeqinteger | nullheadSeqinteger | nullThe chain head when the walk began.
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit-log/verify" \
-H "Authorization: Bearer $TOKEN"People of the workspace
get/api/audit/people
Every member of the workspace and every global admin, with the effective role, last seen and open flags, most recently seen first. The Agent is listed too, as a service actor, once it has acted in the workspace (last seen from its newest ai.chat.* row). Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: listAuditPeople
Responses
- 200The people.
Response fields
application/json · object
peoplearray of object10 fields
idstringEngine user id, or
agentfor the Agent.namestringemailstringEmpty for the Agent.
rolestringThe effective role in the workspace; the Agent's service role.
One of: "Admin", "Operator", "Viewer", "Service · acts with approvals"
servicebooleanOnly on the Agent: a service actor, not an engine user. It acts only through proposals a person approves.
initialsstringThe avatar letters when not derived from the email ("AI").
supportbooleanA MedHook support identity (the support group's domain).
disabledbooleanlastSeenstring (date-time) | nullThe newer of the last sign-in and the newest audit row here.
openFlagsintegerFlags on this person still open or assigned.
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/people" \
-H "Authorization: Bearer $TOKEN"One person's audit figures
get/api/audit/people/{id}
Last seen, PHI views and changes in the last 30 days, open flags, and the 6 newest audit events as sentences. For a MedHook support identity, the newest support access grant (null when revoked). agent is the Agent: its PHI views are masked only, its changes the workflows people saved from its drafts in that window (the workflow.created events that carry proposedBy: "agent", see fromAgent on POST /api/workflows), its open flags 0. 404 when the user isn't a person of this workspace (or the Agent never acted in it). Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAuditPerson
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Engine user id, or |
Responses
- 200The person.
Response fields
application/json · object
personobject8 fields
idstringnamestringemailstringrolestringservicebooleanOnly on the Agent.
initialsstringOnly on the Agent.
supportbooleandisabledboolean
kpisobject6 fields
lastSeenstring (date-time) | nullphiViews30dintegerPHI views in the window, as the PHI access tab counts them under this person: reveals, and plain message views that name a patient (the Agent's reads are the Agent's).
exported30dintegerMessage rows exported in the window (ACK queue and message exports).
maskedOnlybooleanOnly on the Agent: it reads PHI masked and never reveals.
changes30dintegeropenFlagsinteger
supportGrantobject | null2 fields
grantedBystringexpiresAtstring (date-time)
recentarray of object5 fields
idstringatstring (date-time)eventTypestringtextstringcategorystring
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/people/<id>" \
-H "Authorization: Bearer $TOKEN"Flags of the workspace
get/api/audit/flags
The rule evaluator's findings, newest first (up to 100), the caller's own open flags first, and open: how many are still open or assigned. The evaluator runs every 5 minutes over recent audit rows. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: listAuditFlags
Parameters
| Name | In | Type | Description |
|---|---|---|---|
count | query | string |
|
assignee | query | string |
|
Responses
- 200The flags.
Response fields
application/json · object
flagsarray of object18 fields
idstringrulestringphi_burst(high): more than 20 PHI views of one patient within 5 minutes.new_ip(high): sign-in from an IP not seen in 90 days, outside 06:00 to 22:00.bulk_export(medium): export of more than 1,000 messages by one person in a day.signin_locked(high): password sign-in paused after repeated wrong sign-in codes.password_spray(high): repeated wrong passwords for one account from many addresses.One of: "phi_burst", "new_ip", "bulk_export", "signin_locked", "password_spray"
severitystringOne of: "high", "medium"
subjectobject2 fields
idstringnamestringDisplay name, else the email.
factsobjectWhat the rule saw: view counts and times, IPs, export row counts. Never a patient.
atstring (date-time)The newest event behind it.
firstAtstring (date-time)statestringOne of: "open", "assigned", "reviewed", "incident"
assigneeobject | null2 fields
idstringnamestringDisplay name, else the email.
minebooleanAssigned to the caller.
reviewedBystring | nullreviewedAtstring (date-time) | nullnotestring | nullThe reviewer's note for the record. Admin only (it may name a patient); null for every other role.
hasNotebooleanWhether the reviewer left a note.
noteLengthintegerincidentIdstring | nullrevokedSessionsinteger | nullprivacyNoticestring | nullAfter an incident: the email to the workspace's privacy officer was sent, not sent because no address is set (
unset) or email is off on this engine (nomail), or failed. Null before G-audit-4.One of: "sent", "unset", "nomail", "failed"
openinteger
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/flags" \
-H "Authorization: Bearer $TOKEN"One flag with its rule, context and related events
get/api/audit/flags/{id}
The flag; its rule line; the related events (the audit events behind it and the person's own events in the 5 minutes before and after, a run of PHI views of one patient as one row) as sentences with their IPs; the "Agent · context" text; and the admins of the workspace it can be assigned to (never the person flagged). With AI features off, the assistant off or no AI provider, context is computed on the engine from the flag's facts and nothing is sent to a provider. With AI on, the first read asks the Agent once, read-only (no tools, masked events, no clock times), and stores the reply on the flag; a reply that fails the PHI pattern check is dropped for the computed text. Never a patient. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAuditFlag
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The flag id. |
timeZone | query | string | The viewer's IANA time zone, for the clock times in a computed context. UTC when absent. |
Responses
- 200The flag.
Response fields
application/json · object
flagobject18 fields
idstringrulestringphi_burst(high): more than 20 PHI views of one patient within 5 minutes.new_ip(high): sign-in from an IP not seen in 90 days, outside 06:00 to 22:00.bulk_export(medium): export of more than 1,000 messages by one person in a day.signin_locked(high): password sign-in paused after repeated wrong sign-in codes.password_spray(high): repeated wrong passwords for one account from many addresses.One of: "phi_burst", "new_ip", "bulk_export", "signin_locked", "password_spray"
severitystringOne of: "high", "medium"
subjectobject2 fields
idstringnamestringDisplay name, else the email.
factsobjectWhat the rule saw: view counts and times, IPs, export row counts. Never a patient.
atstring (date-time)The newest event behind it.
firstAtstring (date-time)statestringOne of: "open", "assigned", "reviewed", "incident"
assigneeobject | null2 fields
idstringnamestringDisplay name, else the email.
minebooleanAssigned to the caller.
reviewedBystring | nullreviewedAtstring (date-time) | nullnotestring | nullThe reviewer's note for the record. Admin only (it may name a patient); null for every other role.
hasNotebooleanWhether the reviewer left a note.
noteLengthintegerincidentIdstring | nullrevokedSessionsinteger | nullprivacyNoticestring | nullAfter an incident: the email to the workspace's privacy officer was sent, not sent because no address is set (
unset) or email is off on this engine (nomail), or failed. Null before G-audit-4.One of: "sent", "unset", "nomail", "failed"
rulestringThe rule line, e.g. "Rule: more than 20 PHI views of one patient within 5 minutes."
contextstringThe Agent · context text.
contextSourcestring"agent" when the Agent wrote it, "computed" when the engine did.
eventsarray of object4 fields
idstringatstring (date-time)textstringipstring
assigneesarray of object2 fields
idstringnamestringDisplay name, else the email.
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/flags/<id>" \
-H "Authorization: Bearer $TOKEN"Mark a flag reviewed
post/api/audit/flags/{id}/review
Closes the flag, with an optional note for the record (at most 2,000 characters; an empty one is stored as none). Audited as audit.flag_reviewed with the note's length, not its text. 409 FLAG_CLOSED when the flag is no longer open or assigned. Rate limited to 30 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: reviewAuditFlag
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The flag id. |
Request body (required)
application/json · object
notestringWhat you checked and why it's fine (or not).
Responses
- 200Reviewed.
Response fields
application/json · object
statestringreviewedBystringThe reviewer's identity.
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/flags/<id>/review" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"note": "string"
}'Assign a flag to an admin
post/api/audit/flags/{id}/assign
Assigns the flag to an admin of the workspace (one of the flag's assignees); 400 for anyone else. The flag stays open. Audited as audit.flag_assigned. 409 FLAG_CLOSED when the flag is no longer open or assigned. Rate limited to 30 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: assignAuditFlag
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The flag id. |
Request body (required)
application/json · object
userIdstringrequiredEngine user id of the admin.
Responses
- 200Assigned.
Response fields
application/json · object
statestringassignedTostring
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/flags/<id>/assign" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"userId": "string"
}'Open an incident from a flag
post/api/audit/flags/{id}/incident
Numbers an incident (INC- and at least four digits) and revokes every open session of the person flagged, in one transaction with closing the flag; an API client has no sessions. Then emails the workspace's privacy officer the notice audit.incident.opened (the INC number, the flag's title and a link; no PHI); a failed email never undoes the incident. 400 when the flag is about the admin acting. Audited as audit.incident_opened with privacyNotice. 409 FLAG_CLOSED when the flag is no longer open or assigned. Rate limited to 10 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: openAuditIncident
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The flag id. |
Request body
application/json · object
Responses
- 200Incident opened.
Response fields
application/json · object
statestringincidentIdstringrevokedSessionsintegerprivacyNoticestringAfter an incident: the email to the workspace's privacy officer was sent, not sent because no address is set (
unset) or email is off on this engine (nomail), or failed. Null before G-audit-4.One of: "sent", "unset", "nomail", "failed"
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/flags/<id>/incident" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'Legal holds
get/api/audit/legal-holds
The workspace's holds not yet released: active holds, then drafts, newest first in each (up to 100 of each). The audit and execution purges skip what an active hold covers; a draft keeps nothing. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: listLegalHolds
Responses
- 200The holds.
Response fields
application/json · object
holdsarray of object8 fields
idstringnamestringAs typed, with runs of six or more digits masked (55••••).
statusstringA draft keeps nothing until it is started; only an active hold keeps records.
One of: "draft", "active"
scopestring | nullOne of: "patient", "workflow", "user", "range"
subjectLabelstring | nullWhat it covers: a masked MRN (MRN 55••••), the workflow's name, the person, or the date range. Null on a draft that covers nothing yet.
detailstringcreatedAtstring (date-time)createdBystringWho drafted it, as a short name.
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/legal-holds" \
-H "Authorization: Bearer $TOKEN"Add a legal hold (a draft)
post/api/audit/legal-holds
Adds a draft: named "New hold" and covering nothing unless the body says. A draft keeps nothing until it is started with PUT. Once active, a hold keeps matching records past retention until released: a patient's audit and PHI view records (by MRN, matched through the keyed hash), a workflow's runs and audit records, a person's audit records, or every record in a date range. 404 for a workflow of another workspace or a person who is not in this engine; 503 PATIENT_KEY_UNAVAILABLE for a patient hold on an engine without ENGINE_AUTH_SECRET. Audited as audit.legal_hold_created with the scope and the subject key, never the MRN. Rate limited to 20 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: createLegalHold
Request body (required)
application/json · object
namestringWhat the hold is for (at most 120 characters).
scopeobject | object | object | objectWhat the hold covers.
4 fields
kind: "patient"object2 fields
kindstringrequiredOne of: "patient"
mrnstringrequiredThe patient's MRN. Turned into the keyed hash and a masked label; never stored.
kind: "workflow"object2 fields
kindstringrequiredOne of: "workflow"
workflowIdstringrequired
kind: "user"object2 fields
kindstringrequiredOne of: "user"
userIdstringrequiredSomeone in this engine, by sign-in email (any case) or user id. The hold keeps rows recorded under either.
kind: "dateRange"object3 fields
kindstringrequiredOne of: "dateRange"
fromstring (date-time)requiredtostring (date-time)requiredNot before from.
Responses
- 201Added.
Response fields
application/json · object
holdobject8 fields
idstringnamestringAs typed, with runs of six or more digits masked (55••••).
statusstringA draft keeps nothing until it is started; only an active hold keeps records.
One of: "draft", "active"
scopestring | nullOne of: "patient", "workflow", "user", "range"
subjectLabelstring | nullWhat it covers: a masked MRN (MRN 55••••), the workflow's name, the person, or the date range. Null on a draft that covers nothing yet.
detailstringcreatedAtstring (date-time)createdBystringWho drafted it, as a short name.
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/legal-holds" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "string",
"scope": {
"kind": "patient",
"mrn": "string"
}
}'Edit or start a draft legal hold
put/api/audit/legal-holds/{id}
Renames a draft, chooses what it covers, or starts it (status active). 400 when starting a draft that covers nothing yet; 409 HOLD_ACTIVE for an active hold (release it and add a new one) and ALREADY_RELEASED for a released one. 404 for a workflow of another workspace or a person who is not in this engine; 503 PATIENT_KEY_UNAVAILABLE for a patient hold on an engine without ENGINE_AUTH_SECRET. Audited as audit.legal_hold_updated, or audit.legal_hold_activated when it starts. Rate limited to 20 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: updateLegalHold
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The hold id. |
Request body (required)
application/json · object
namestringWhat the hold is for (at most 120 characters).
scopeobject | object | object | objectWhat the hold covers.
4 fields
kind: "patient"object2 fields
kindstringrequiredOne of: "patient"
mrnstringrequiredThe patient's MRN. Turned into the keyed hash and a masked label; never stored.
kind: "workflow"object2 fields
kindstringrequiredOne of: "workflow"
workflowIdstringrequired
kind: "user"object2 fields
kindstringrequiredOne of: "user"
userIdstringrequiredSomeone in this engine, by sign-in email (any case) or user id. The hold keeps rows recorded under either.
kind: "dateRange"object3 fields
kindstringrequiredOne of: "dateRange"
fromstring (date-time)requiredtostring (date-time)requiredNot before from.
statusstringStart the hold: it keeps records from now on.
One of: "active"
Responses
- 200Saved.
Response fields
application/json · object
holdobject8 fields
idstringnamestringAs typed, with runs of six or more digits masked (55••••).
statusstringA draft keeps nothing until it is started; only an active hold keeps records.
One of: "draft", "active"
scopestring | nullOne of: "patient", "workflow", "user", "range"
subjectLabelstring | nullWhat it covers: a masked MRN (MRN 55••••), the workflow's name, the person, or the date range. Null on a draft that covers nothing yet.
detailstringcreatedAtstring (date-time)createdBystringWho drafted it, as a short name.
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X PUT "$ENGINE_URL/api/audit/legal-holds/<id>" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "string",
"scope": {
"kind": "patient",
"mrn": "string"
},
"status": "active"
}'Release a legal hold, or discard a draft
delete/api/audit/legal-holds/{id}
The records it kept fall back to their retention and can be purged. The hold stays as the record, with who released it. Audited as audit.legal_hold_released, or audit.legal_hold_discarded for a draft (it kept nothing). 409 ALREADY_RELEASED for a hold already released. With expect=draft (Discard draft) only a draft is discarded: a hold started in the meantime is a 409 HOLD_ACTIVE and stays. Rate limited to 20 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: releaseLegalHold
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The hold id. |
expect | query | string | draft: discard only if it is still a draft. |
Responses
- 200Released.
Response fields
application/json · object
releasedbooleanreleasedBystring
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X DELETE "$ENGINE_URL/api/audit/legal-holds/<id>" \
-H "Authorization: Bearer $TOKEN"How long records are kept
get/api/audit/retention
Audit events (AUDIT_LOG_RETENTION_DAYS, six years by default), PHI view records (six years and never less than audit events, even after the message is deleted), message bodies (EXECUTION_RETENTION_DAYS by default, 0 = kept; workflows can set their own) and the active legal holds. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAuditRetention
Responses
- 200Retention.
Response fields
application/json · object
auditEventsobject1 field
daysinteger
phiViewsobject1 field
daysinteger
messageBodiesobject2 fields
defaultDaysinteger0 when the engine keeps runs forever.
workflowOverridesintegerWorkflows with their own retention.
legalHoldsinteger
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/retention" \
-H "Authorization: Bearer $TOKEN"Who the HIPAA access report goes to, and when
get/api/audit/reports/hipaa
The workspace's privacy officer (recipient, set under PUT /api/settings/privacy-officer), when a report was last emailed (the 1st's schedule or Send now), when it goes next (nextSendAt: the coming 1st, midnight in the engine's timeZone; while last month's is still due in the first week, now, or the UTC close of that month if later), whether this engine can send email, and the newest download (audit.hipaa_report). On the 1st of each month the previous month's report is emailed to the recipient, once that month has closed in UTC; an engine that was down, or a recipient first set, in the first week gets it within the hour. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getHipaaReportLast
Responses
- 200The schedule and the last download.
Response fields
application/json · object
recipientstring | nulllastSentAtstring (date-time) | nullnextSendAtstring (date-time)timeZonestringThe engine's IANA zone.
emailConfiguredbooleanThis engine has a mailer (Resend, or the webhook relay to SMTP or SendGrid).
lastobject | null3 fields
atstring (date-time)bystring | nullmonthstring | null
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/reports/hipaa" \
-H "Authorization: Bearer $TOKEN"HIPAA access report for a month (PDF)
post/api/audit/reports/hipaa
Who viewed whose PHI in a calendar month (UTC; last month by default; this month runs to now): views, people, patients, flagged and outside-the-workspace counts, then each view (when, who, message id, reason, IP), at most 5,000. Masked identifiers only: patients are counted, never named, keyed or listed; no message content. Audited as audit.hipaa_report with the counts; no PDF is served if that record can't be written. Rate limited to 5 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: hipaaAccessReport
Request body
application/json · object
monthstringYYYY-MM.
Responses
- 200The report.
application/pdf · string (binary)
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/reports/hipaa" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"month": "2026-10"
}'Send the HIPAA access report to the privacy officer now
post/api/audit/reports/hipaa/send
Last month's report (the engine's time zone; the same PDF as POST /api/audit/reports/hipaa, masked identifiers only) emailed now to the workspace's privacy officer. The email body names no patient: the month, the counts and a link. It sets lastSentAt; the 1st's scheduled report still goes. 409 NO_RECIPIENT ("Set the privacy officer's email first") with no recipient, 503 EMAIL_OFF with email off on this engine, 502 EMAIL_FAILED when the mailer refuses it. Audited as audit.report.sent (trigger manual, with the counts) once it went. Rate limited to 3 requests per hour.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: sendHipaaReport
Request body
application/json · object
Responses
- 200Sent.
Response fields
application/json · object
recipientstringmonthstringlastSentAtstring (date-time)nextSendAtstring (date-time)
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 409The request conflicts with the current state.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 502Error.
application/json · ApiError
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/reports/hipaa/send" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'The Audit log header: retention and the log exporter
get/api/audit/summary
How many days audit events are kept (AUDIT_LOG_RETENTION_DAYS, six years by default) and the log exporter the engine streams to, as its provider name only (splunk, datadog, cloudwatch, or null for none). Its settings stay under GET /api/settings/log-export (Admin). Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAuditSummary
Responses
- 200The summary.
Response fields
application/json · object
retentionDaysintegerexporterstring | nullOne of: "splunk", "datadog", "cloudwatch"
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit/summary" \
-H "Authorization: Bearer $TOKEN"The latest daily audit anchor
get/api/audit-log/anchor
At 00:00 UTC the head of the hash chain is recorded as {date, lastSeq, headHash} and its SHA-256 (only the hash, no PHI) is sent to the RFC 3161 timestamping service set under /api/settings/timestamping; the signed token is kept with the anchor (stamped). With AUDIT_ANCHOR_DIR set it is also mirrored to that bucket (external). publishedAt is null while the anchor is recorded in this engine only. GET /api/audit-log/verify compares the chain with every anchor still inside it (409 with anchorMismatch). The service's URL, the token and the bucket path are not returned. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAuditAnchor
Responses
- 200The anchor, or null before the first one.
Response fields
application/json · object
tsabooleanA timestamping service is set.
externalbooleanAUDIT_ANCHOR_DIR mirrors anchors to a bucket.
latestobject | null6 fields
datestringThe UTC day it closes.
lastSeqintegerheadHashstringexternalbooleanMirrored to AUDIT_ANCHOR_DIR.
stampedbooleanSigned by the timestamping service.
publishedAtstring (date-time) | null
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit-log/anchor" \
-H "Authorization: Bearer $TOKEN"Ask the audit log
post/api/audit/ask
A read-only search of the caller's workspace from a plain-English question (specs/10 Ask bar). The question is read as a window (today, yesterday, this week or month, the last N days up to 2190; default 7 days), an Activity category, a resource name (quoted, or a name such as pharmacy-east), or a patient's MRN. A patient question is matched through the MRN's keyed hash against the workspace's PHI views (reveals, plain message views and the Agent's masked reads that name the patient), for operators and admins only (a viewer gets an answer saying so), and never reaches the model; 503 PATIENT_KEY_UNAVAILABLE when the engine has no auth secret. Any other question reads up to 50 matching events, newest first; with an AI provider set up and budget left, the Agent words the answer from masked event sentences (source: "agent"), else the plain search answer is returned (source: "search"). The answer has no PHI patterns (digit runs masked, at most 800 characters) and links up to 5 events, each read back in the workspace. The Agent's wording is one call with no tools, and a reply with a PHI pattern (an MRN, a patient's name, a date) is dropped for the search answer. Every ask is audited as audit.asked (kind, category, window, counts, the question's length and the chip's id; never the question), and nothing is answered if that record can't be written. 403 AI_FEATURES_DISABLED while AI features are off; 404 while the assistant is switched off (CHAT_ENABLED=false), like /api/ai/chat. Rate limited to 20 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: askAuditLog
Request body (required)
application/json · any | any
questionstringThe question in plain English (1 to 500 characters). Never stored, logged or sent to the model as typed; a patient's MRN in it is used only to compute its keyed hash. Send this or
suggestion, not both.suggestionstringA suggestion chip by id instead of a question:
phi("Who viewed MRN 551207 this month?", whose MRN is a made-up example, so it searches this month's PHI views and looks no patient up; its answer leads with "All PHI views, not one patient's: the example MRN is not looked up."),down("What changed before pharmacy-east went down?") oragent("Everything the Agent did today").One of: "phi", "down", "agent"
dayStartstring (date-time)The asker's local midnight, for "today" (within the last 2 days); default UTC midnight.
timeZonestringThe asker's IANA time zone, for the times in the answer.
Responses
- 200The answer.
Response fields
application/json · object
textstringhitsarray of object4 fields
idstringThe audit event id; it exists in the caller's workspace.
refstringevt_<chain seq>, or the id's first 8 characters.
atstring (date-time)eventTypestring
sourcestringOne of: "agent", "search"
scopeobject4 fields
kindstringOne of: "events", "patient"
categorystringOne of: "all", "changes", "phi", "signins", "agent", "access", "system"
fromstring (date-time)tostring (date-time)
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/audit/ask" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d 'null'Open the document an audit event holds
get/api/audit-log/{id}/attachment
Admin only (403 for operators and viewers). The signed BAA copy an ai.baa_confirmed event in the caller's workspace names (after.documentId), as an application/pdf download (Content-Disposition: attachment, no-store, nosniff). Each opening is audited as ai.baa_copy_opened with the copy's id and auditLogId. 404 for an unknown id, another workspace's event or an event without an attachment. 500 BAA_COPY_INTEGRITY (logged) when the stored copy no longer decrypts or matches its recorded SHA-256. Rate limited to 30 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: getAuditLogAttachment
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The audit event's id. |
Responses
- 200The attached document.
application/pdf · string (binary)
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).
application/json · ApiError
- 404Not found in the caller's workspace.
application/json · ApiError
- 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/audit-log/<id>/attachment" \
-H "Authorization: Bearer $TOKEN"Schemas
Named objects the operations above link to.
ApiError
The error body. error is always present. code is present on most errors and is the field to branch on; a few routes and the sign-in and role checks return only error (and sometimes detail).
errorstringrequiredHuman-readable error message.
codestringMachine-readable error code.
One of: "BAD_REQUEST", "INVALID_REQUEST", "UNAUTHORIZED", "UNAUTHENTICATED", "FORBIDDEN", "NOT_FOUND", "CONFLICT", "UNPROCESSABLE_ENTITY", "RATE_LIMITED", "INTERNAL_ERROR", "SERVICE_UNAVAILABLE", "NOT_CONFIGURED", "SIGNATURE_REQUIRED", "INVALID_SIGNATURE", "TIMESTAMP_REQUIRED", "TIMESTAMP_INVALID", "TIMESTAMP_OUT_OF_TOLERANCE", "INVALID_CREDENTIALS", "INVALID_TOKEN", "PAYLOAD_TOO_LARGE", "INVALID_NDJSON", "PHI_NOT_AUTHORIZED", "PHI_IN_SANDBOX", "IN_PROGRESS", "RETRY_SCHEDULED", "WORKFLOW_DISABLED", "CONFLICTING_SCOPE", "ALREADY_DELIVERED", "CHAIN_TOO_DEEP", "NO_FAILED_DESTINATION", "STALE_SCOPE", "UNKNOWN_DESTINATION", "NO_DESTINATIONS", "NOT_A_MESSAGE", "AI_FEATURES_DISABLED"
detailsanyOptional structured context about the error.