AI
AI endpoints of the MedHook engine API: 24 operations with parameters, schemas and a curl example for each.
On this page
- Check AI mapping availability
- Suggest field mappings
- Condition suggestion availability
- Suggest condition expression
- Attach an API document to the assistant chat
- Assistant status
- Assistant turn (streaming)
- Read mapping feedback
- Record accept or reject for a mapping suggestion
- AI usage
- The caller's Agent watches, by id
- Watch a tunnel's one-time PSK link after Not now
- List your Agent conversations
- Keep an Agent conversation
- Delete an Agent conversation
- An Agent approval card's status
- Not now on an Agent approval card
- Things to @mention in the Agent composer
- The Agent's calls for you
- What the Agent can do
- Choose whether the Agent does an action alone
- Where the Agent's postmortem would be posted
- Post the Agent's postmortem to the Slack channel
- Ask the engine's admins to turn on AI features
- Schemas
Claude-powered field mapping and condition suggestions.
Check AI mapping availability
get/api/ai/mapping-suggest
Returns whether the AI mapping feature is enabled: a configured AI provider (ANTHROPIC_API_KEY, or AI_PROVIDER=vertex with AI_VERTEX_PROJECT and AI_VERTEX_REGION).
Auth: Bearer token (how to get one) · Operation: checkAIMappingAvailability
Responses
Example request
curl "$ENGINE_URL/api/ai/mapping-suggest" \
-H "Authorization: Bearer $TOKEN"Suggest field mappings
post/api/ai/mapping-suggest
Uses the Claude API to suggest field-level mappings between a source data sample and a target schema. Requires a configured AI provider (ANTHROPIC_API_KEY, or AI_PROVIDER=vertex with AI_VERTEX_PROJECT and AI_VERTEX_REGION).
Auth: Bearer token (how to get one) · Operation: suggestMappings
Request body (required)
application/json · object
sourceDatastringrequiredRaw source data sample (HL7v2 message, FHIR JSON, X12 payload, etc.).
sourceFormatstringrequiredOne of: "hl7v2", "fhir", "x12", "json", "csv"
targetFormatstringrequiredOne of: "hl7v2", "fhir", "x12", "json", "csv"
targetSchemaobjectOptional JSON schema or example object for the target format.
contextstring
Responses
- 200Mapping suggestions.
Response fields
application/json · object
summarystringwarningsarray of string
- 401Missing or invalid JWT Bearer token.
application/json · ApiError
- 429Rate limit exceeded.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
- 503There is no a configured AI provider (ANTHROPIC_API_KEY, or AI_PROVIDER=vertex with AI_VERTEX_PROJECT and AI_VERTEX_REGION).
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/ai/mapping-suggest" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"sourceData": "string",
"sourceFormat": "hl7v2",
"targetFormat": "hl7v2",
"targetSchema": {},
"context": "Map HL7v2 ADT A01 to FHIR Patient resource"
}'Condition suggestion availability
get/api/ai/condition-suggest
Whether the AI condition builder is available, so a client can choose between it and the rule-based fallback.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getConditionSuggestStatus
Responses
- 200The status.
Response fields
application/json · object
availablebooleandisabledbooleanmodelstringfallbackAvailableboolean
- 401No credential, or the token is invalid or expired.
application/json · ApiError
Example request
curl "$ENGINE_URL/api/ai/condition-suggest" \
-H "Authorization: Bearer $TOKEN"Suggest condition expression
post/api/ai/condition-suggest
Generates a JavaScript condition expression for a workflow condition node from a natural-language description. Falls back to a rule-based generator when the Claude API is unavailable.
Auth: Bearer token (how to get one) · Operation: suggestCondition
Request body (required)
application/json · object
descriptionstringrequiredsampleInputobjectRepresentative data payload used to ground the generated expression.
Responses
- 200Generated condition expression.
Response fields
application/json · object
expressionstringrequiredconfidencenumberrequiredsourcestringrequiredclaude-haikuwhen the Anthropic API was used;rule-basedfor the fallback.One of: "claude-haiku", "rule-based"
explanationstringrequired
- 401Missing or invalid JWT Bearer token.
application/json · ApiError
- 429Rate limit exceeded.
application/json · ApiError
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/ai/condition-suggest" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"description": "Patient is over 65 and has Medicare coverage",
"sampleInput": {}
}'Attach an API document to the assistant chat
post/api/ai/chat/attachments
Uploads a partner's OpenAPI 3.x or Swagger 2.0 document (JSON or YAML) for the API-to-API copilot. Send its id in the next POST /api/ai/chat as attachments; the assistant reads it with import_api_spec. The document is a contract, not a message: it is not pasted into the chat (so the chat's 4,000-character message limit does not apply) and does not go through the pasted-message gate. Its example and examples values are replaced with schema-typed placeholders before anything reaches the model. It is read once as an API document (400 with the reason when it is not one), then stored AES-256-GCM encrypted in Postgres, in the request's workspace, for 7 days; every replica and a restarted engine read it, and expired attachments are deleted by the retention run. Operator or admin only; at most 5 MB. Audited as ai.chat.attachment_uploaded with the id, size and SHA-256, never the content or the file name. 404 when the assistant is switched off (CHAT_ENABLED=false), 403 while AI features are off. Rate limited: 10 req / 60 s.
Auth: Bearer token (how to get one) · Operation: postAiChatAttachment
Request body (required)
multipart/form-data · object
filestring (binary)requiredThe OpenAPI or Swagger document, .json or .yaml.
Responses
- 201Stored.
Response fields
application/json · object
idstringatt_ and 24 hex digits.
kindstringOne of: "api-spec"
filenamestringbytesintegerexpiresAtstring (date-time)titlestringThe document's title.
operationsintegerHow many operations it has.
- 400No `file`, not multipart/form-data, or not an OpenAPI 3.x or Swagger 2.0 document (the reason is in `error`).
application/json · ApiError
- 401Not signed in.
application/json · ApiError
- 403Viewer role, or AI features are off.
application/json · ApiError
- 404The assistant is switched off.
application/json · ApiError
- 413`PAYLOAD_TOO_LARGE` — a file over 5 MB.
application/json · ApiError
- 429Rate limited.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/ai/chat/attachments" \
-H "Authorization: Bearer $TOKEN" \
-F 'file=@file'Assistant status
get/api/ai/chat
Whether the assistant is on and can answer: enabled, available (false without a configured AI provider (ANTHROPIC_API_KEY, or AI_PROVIDER=vertex with AI_VERTEX_PROJECT and AI_VERTEX_REGION)), the model, the caller's effective daily budget, monthly.reached (this month's AI budget is used up, so the Agent is paused), the onboarding skills (id, title, when) and the caller's role. 404 when switched off with CHAT_ENABLED=false (it is on whenever AI features are on); 403 while AI features are off.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiChatStatus
Responses
- 200The status.
Response fields
application/json · object
enabledbooleanavailablebooleanmodelstringbudgetobjectToday's token budget.
monthlyobject1 field
reachedboolean
skillsarray of object3 fields
idstringtitlestringwhenstring
rolestring
- 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
Example request
curl "$ENGINE_URL/api/ai/chat" \
-H "Authorization: Bearer $TOKEN"Assistant turn (streaming)
post/api/ai/chat
One turn with the assistant (the Agent screen). 404 when switched off with CHAT_ENABLED=false (it is on whenever AI features are on). It answers questions with read-only tools that call this engine's API as the signed-in user (so roles, workspace membership and PHI redaction apply), guides onboarding skills, and proposes workflow drafts, adapter profiles (non-secret values only) and adapter SDK scaffolds that a person saves through the normal UI; it never writes. Message and history are scrubbed before they reach the model, and every turn, tool call and proposal is audited as ai.chat.*. The response is a Server-Sent Events stream; each data: line is JSON with a type of text, tool_use, tool_result, workflow_proposed, skill_loaded, checkpoint, profile_proposed, artifact, done or error. A tool_result may carry resourceId (the plain id the tool read) and resourceName (that object's name, for the composer's Context chips); resourceName is sent only when the PHI scrub leaves it unchanged. A tool_result with notRun: true was held back by What it can do (its action is at Asks first): no API was called. 403 while AI features are off, 503 without a configured AI provider (ANTHROPIC_API_KEY, or AI_PROVIDER=vertex with AI_VERTEX_PROJECT and AI_VERTEX_REGION), 402 BUDGET_REACHED once this month's AI budget (Settings > AI features & BAA) is used up (each active admin is emailed once that month), 429 once the daily AI budget is used up (it resets at midnight UTC; raise it with AI_DAILY_TOKEN_LIMIT and AI_DAILY_ITERATION_LIMIT; for a viewer, also once their own daily allowance is: AI_CHAT_VIEWER_DAILY_TOKEN_LIMIT, default 20,000 tokens). Rate limited to 10 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: postAiChat
Request body (required)
application/json · object
messagestringrequired1 to 4000 characters.
historyarray of object3 fields
rolestringrequireduser or assistant.
textstringrequiredtoolsarray of stringOptional, assistant turns: the tools that answer used (at most 8).
skillIdstringOptional. The skill in play.
stepIdstringOptional. The skill step just confirmed.
contextobjectOptional. The side panel's page context, or what the Agent composer @mentioned (
GET /api/ai/chat/mentions): ids only (1 to 64 letters, digits,_or-; a step id may also have.or:), never page content. Each id is checked as the caller in this workspace; one that is deleted or not readable here reaches the model as not available, without the id.5 fields
workflowIdstringThe workflow open in the builder.
nodeIdstringThe step selected in that workflow (needs workflowId).
messageIdstringThe selected message.
tunnelIdstringThe tunnel on screen.
connectionIdstringA connection (adapter profile) @mentioned in the Agent composer.
attachmentsarray of stringOptional. Up to 3 ids from
POST /api/ai/chat/attachments(a partner's API document) attached to this message. Each is checked in this workspace without reading its content, and named to the model by id; an expired or unknown one reaches the model as not available.
Responses
- 200An event stream.
text/event-stream · string
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
application/json · ApiError
- 402This month's AI budget is used up (code `BUDGET_REACHED`): the Agent is paused until the 1st or until an admin raises it.
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
- 503A dependency is not available.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/ai/chat" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "string",
"history": [
{
"role": "string",
"text": "string",
"tools": [
"string"
]
}
],
"skillId": "string",
"stepId": "string",
"context": {
"workflowId": "string",
"nodeId": "string",
"messageId": "string",
"tunnelId": "string",
"connectionId": "string"
},
"attachments": [
"string"
]
}'Read mapping feedback
get/api/ai/mapping-feedback
The recorded feedback in the caller's workspace, or with stats=true its counts and acceptance rate.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: listMappingFeedback
Parameters
| Name | In | Type | Description |
|---|---|---|---|
limit | query | integer | Records to return, up to 500. |
accepted | query | string | Only accepted or only rejected. |
stats | query | string |
|
Responses
Example request
curl "$ENGINE_URL/api/ai/mapping-feedback" \
-H "Authorization: Bearer $TOKEN"Record accept or reject for a mapping suggestion
post/api/ai/mapping-feedback
Accepted mappings become examples in later suggestions, in the same workspace only (the caller's workspace: X-Workspace-Id, ?workspaceId or the switcher cookie). With a suggestionId a repeat verdict replaces the earlier one. Both fields must be field paths (letters, digits and _ . [ ] : -, no spaces), because accepted rows are examples in the mapping prompt. Context is stored as field paths only, never message values; a key that is not a field name is dropped with its subtree. It is an AI feature, so it is 403 while AI features are off.
Minimum role: operator.
Auth: Bearer token (how to get one) · Operation: recordMappingFeedback
Request body (required)
application/json · object
sourceFieldstringrequiredA field path: letters, digits and _ . [ ] : - (no spaces).
targetFieldstringrequiredThe target the user kept, as a field path (same rule as sourceField).
acceptedbooleanrequiredsuggestionIdstringThe id POST /api/ai/mapping-suggest gave the suggestion.
confidencenumberThe suggestion's confidence.
editedbooleanThe user changed the target before accepting.
suggestedBystringOne of: "ai", "user"
workflowIdstringtransformTypestringsourceContextanytargetContextany
Responses
- 200Recorded.
Response fields
application/json · object
okbooleanidstring
- 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
- 500Unexpected server error.
application/json · ApiError
Example request
curl -X POST "$ENGINE_URL/api/ai/mapping-feedback" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"sourceField": "string",
"targetField": "string",
"accepted": true,
"suggestionId": "string",
"confidence": 0,
"edited": true,
"suggestedBy": "ai",
"workflowId": "string",
"transformType": "hl7v2-to-fhir",
"sourceContext": null,
"targetContext": null
}'AI usage
get/api/analytics/ai-usage
Today's and recent daily AI usage for a license key (anonymous when you give none).
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiUsage
Parameters
| Name | In | Type | Description |
|---|---|---|---|
days | query | integer | Days of history, up to 31. |
licenseKey | query | string | The license key to report on. |
Responses
Example request
curl "$ENGINE_URL/api/analytics/ai-usage" \
-H "Authorization: Bearer $TOKEN"The caller's Agent watches, by id
get/api/ai/watches
What a reopened Agent conversation pulls (the conversation stays in the browser): each of the caller's own watches among ids, in the caller's workspace, with firedAt once the link was opened. Another person's watch, or one in another workspace, is left out. A read: not audited. Rate limited to 120 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiWatches
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idsrequired | query | string | 1 to 20 watch ids, comma separated. |
Responses
- 200The watches.
Response fields
application/json · object
watchesarray of objectrequired9 fields
idstringrequiredThe watch's id, for GET /api/ai/watches?ids=.
kindstringrequiredWhat it watches.
One of: "psk_link_opened"
tunnelIdstringrequiredThe tunnel.
tunnelNamestringrequiredThe tunnel's name.
pskVersionstringrequiredThe tunnel's current key version, e.g. "v3".
waitingOnPeerbooleanrequiredThe tunnel waits on the peer: a rotation GCP has not taken yet, or the failover watcher reads it down or degraded. A routine rotation on a healthy tunnel is false.
linkLivebooleanrequiredOne of the tunnel's one-time PSK links is unused and unexpired.
createdAtstring (date-time)requiredWhen Not now registered it.
firedAtstring (date-time) | nullrequiredWhen the tunnel's one-time link was first revealed after it was made; null while it waits.
- 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/ai/watches?ids=string" \
-H "Authorization: Bearer $TOKEN"Watch a tunnel's one-time PSK link after Not now
post/api/ai/watches
What the Agent watches after Not now on a live tunnel key card ("I'll watch the link and tell you the moment it's opened."). Registers the caller's watch on the tunnel's one-time PSK link, in the caller's workspace (404 for a tunnel outside it). The first successful reveal (POST /api/psk-links/{token}; a GET never counts) after the watch was made fires it once and tells the caller on the "Agent asks first" notification route (Settings › Notifications), with the tunnel's name and the time: never the key or the token. A watch waits 7 days. The same watch still waiting answers 200 with it; a new one is 201 and audited as ai.watch.created with {kind, tunnelId, cardId?}. Nothing changes on the tunnel. Rate limited to 30 requests per minute.
Minimum role: operator.
Auth: Bearer token (how to get one) · Operation: postAiWatch
Request body (required)
application/json · object
kindstringrequiredOne of: "psk_link_opened"
tunnelIdstringrequiredThe tunnel the card was about.
cardIdstringThe Asks first card it came from.
Responses
- 201Watching.
Response fields
application/json · object
watchobjectrequired9 fields
idstringrequiredThe watch's id, for GET /api/ai/watches?ids=.
kindstringrequiredWhat it watches.
One of: "psk_link_opened"
tunnelIdstringrequiredThe tunnel.
tunnelNamestringrequiredThe tunnel's name.
pskVersionstringrequiredThe tunnel's current key version, e.g. "v3".
waitingOnPeerbooleanrequiredThe tunnel waits on the peer: a rotation GCP has not taken yet, or the failover watcher reads it down or degraded. A routine rotation on a healthy tunnel is false.
linkLivebooleanrequiredOne of the tunnel's one-time PSK links is unused and unexpired.
createdAtstring (date-time)requiredWhen Not now registered it.
firedAtstring (date-time) | nullrequiredWhen the tunnel's one-time link was first revealed after it was made; null while it waits.
- 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 -X POST "$ENGINE_URL/api/ai/watches" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"kind": "psk_link_opened",
"tunnelId": "string",
"cardId": "string"
}'List your Agent conversations
get/api/ai/conversations
The caller's own Agent conversations, newest update first: the Conversations rail. Conversations belong to the caller and the workspace the request is verified for: nobody lists, overwrites or deletes another person's, and each workspace has its own. At most 50 per person per workspace; each is deleted 90 days after its last update. What the person typed is PHI-scrubbed, encrypted at rest, and never written to logs or the audit log. Not audited. Rate limited at 120 requests a minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: listAiConversations
Responses
- 200Your conversations.
Response fields
application/json · object
conversationsarray of object
- 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/ai/conversations" \
-H "Authorization: Bearer $TOKEN"Keep an Agent conversation
put/api/ai/conversations/{id}
Adds or replaces one of the caller's conversations. The body is the conversation; its id must match the path (400 otherwise), and the body is at most 1 MB (413 CONVERSATION_TOO_LARGE). A new one over the limit drops the oldest unpinned of the others. Conversations belong to the caller and the workspace the request is verified for: nobody lists, overwrites or deletes another person's, and each workspace has its own. At most 50 per person per workspace; each is deleted 90 days after its last update. What the person typed is PHI-scrubbed, encrypted at rest, and never written to logs or the audit log. The first save is audited as ai.conversation.created with the id and a message count only. Rate limited at 120 requests a minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: putAiConversation
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The conversation id. |
Request body (required)
application/json · object
Responses
- 200Replaced (201 when new).
Response fields
application/json · object
conversationobjectA conversation as the Agent screen holds it:
id,title,mode(build,investigateor null),startedAtandupdatedAt(epoch ms),pinned, optionalsharedWith,messages(at most 500) anddraft(a workflow graph or null).
- 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
- 413The body is larger than the limit.
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 PUT "$ENGINE_URL/api/ai/conversations/<id>" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'Delete an Agent conversation
delete/api/ai/conversations/{id}
Deletes one of the caller's conversations; anyone else's is a 404. Conversations belong to the caller and the workspace the request is verified for: nobody lists, overwrites or deletes another person's, and each workspace has its own. At most 50 per person per workspace; each is deleted 90 days after its last update. What the person typed is PHI-scrubbed, encrypted at rest, and never written to logs or the audit log. Audited as ai.conversation.deleted. Rate limited at 60 requests a minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: deleteAiConversation
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The conversation id. |
Responses
- 200Deleted.
Response fields
application/json · object
deletedbooleanidstring
- 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 -X DELETE "$ENGINE_URL/api/ai/conversations/<id>" \
-H "Authorization: Bearer $TOKEN"An Agent approval card's status
get/api/ai/proposals/{id}
The status of an Asks first card the Agent showed. id is the signed proposal the card carries (p1.<payload>.<mac>, valid 7 days, bound to the workspace); a forged, expired or other-workspace id is 400. The Agent never makes the change: the card links to the screen that does, which sends the proposal back with the change (PATCH /api/vpn-tunnels/{id} with rotateSecret, POST /api/workflows/{id}/deploy with deploy or request-approval), and that route audits ai.proposal.resolved. Read from those audit events only (resource ai.proposal, through the resource index). A read: not audited. Rate limited to 120 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiProposal
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The card's signed proposal id. |
Responses
- 200The card's status.
Response fields
application/json · object
statusstringrequiredpending: nothing happened yet; done: the screen made the change; waiting_second_admin: a deploy's approval was requested; in_progress: approved, not finished (a deploy the second admin approved that is not deployed yet, or a PSK rotation still running in the background); failed: the rotation's background job failed; skipped: Not now.
One of: "pending", "done", "skipped", "waiting_second_admin", "in_progress", "failed"
approvedByarray of stringrequiredreviewerstring | nullDeploys only, while pending or waiting for the second admin: an enabled admin other than the requester and the caller; null when there is none.
- 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/ai/proposals/<id>" \
-H "Authorization: Bearer $TOKEN"Not now on an Agent approval card
post/api/ai/proposals/{id}
Skips the card: nothing changes. Audited as ai.proposal.skipped with {actionId, targetId}; skipping again answers the same and audits nothing. 409 once the change was made, approved or tried from its screen (any status but pending or skipped); 400 on a bad id or body. Rate limited to 30 requests per minute.
Minimum role: operator.
Auth: Bearer token (how to get one) · Operation: postAiProposalSkip
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | The card's signed proposal id. |
Request body (required)
application/json · object
decisionstringrequiredOne of: "skip"
Responses
- 200Skipped.
Response fields
application/json · object
statusstringrequiredpending: nothing happened yet; done: the screen made the change; waiting_second_admin: a deploy's approval was requested; in_progress: approved, not finished (a deploy the second admin approved that is not deployed yet, or a PSK rotation still running in the background); failed: the rotation's background job failed; skipped: Not now.
One of: "pending", "done", "skipped", "waiting_second_admin", "in_progress", "failed"
approvedByarray of stringrequiredreviewerstring | nullDeploys only, while pending or waiting for the second admin: an enabled admin other than the requester and the caller; null when there is none.
- 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
Example request
curl -X POST "$ENGINE_URL/api/ai/proposals/<id>" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"decision": "skip"
}'Things to @mention in the Agent composer
get/api/ai/chat/mentions
What the Agent composer's @mention popover lists, in the caller's workspace: tunnels, connections (adapter profiles) and workflows whose name holds q (any case; at most 6 of each, by name), and messages whose control id starts with q (2 characters or more, through the control id index; at most 6). Ids and names only (a message's name is its control id): no configuration, patient, source or body. Send a picked id in the next POST /api/ai/chat as context (tunnelId, connectionId, workflowId or messageId); the chat checks it again as the caller. A kind whose read fails is left out. Messages match on a plaintext control id, first deliveries only: on a deployment that seals stored messages (MESSAGE_ENCRYPTION_KEY) sealed rows never match. The message search (q of 2 characters or more) is audited as message.searched (fields ["control"] and the result count, never the value), like GET /api/messages; name lookups are not. 404 when the assistant is switched off (CHAT_ENABLED=false), 403 while AI features are off. Rate limited to 120 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiChatMentions
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q | query | string | What follows the @: letters, digits, |
Responses
- 200The matches, by kind (tunnel, connection, workflow, message).
Response fields
application/json · object
itemsarray of object3 fields
kindstringrequiredOne of: "tunnel", "connection", "workflow", "message"
idstringrequiredThe id to send as context.
namestringrequiredThe display name; a message's control id.
- 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/ai/chat/mentions" \
-H "Authorization: Bearer $TOKEN"The Agent's calls for you
get/api/ai/activity
What the Agent's Activity view lists: every call the Agent made for the caller in the caller's workspace over the last days, newest first, at most 100. These are the ai.chat.tool_call audit events, without the Agent's local helpers (loading a skill, asking a question, reading the docs); the whole workspace's are in GET /api/audit-log. An approval card's call (propose_action) also has proposal: what became of the change it proposed, read from the card's ai.proposal.* audit events (the Agent never runs it; the screen does). Each entry has the tool, what it acted on (a record id, when the call named one), its kind (read or proposal: the Agent never runs a live action itself), whether it worked and its HTTP status (notRun when Asks first held it back, so nothing ran), and the browser's conversation id from the chat request (titles stay in the browser). today counts the same calls since todayFrom, up to 999. A caller with no identity gets an empty list. Any role, each person their own. A read: not audited. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiActivity
Parameters
| Name | In | Type | Description |
|---|---|---|---|
days | query | integer | How many days back, 1 to 30 (default 7). |
todayFrom | query | string (date-time) | Where today starts: the browser's local midnight as an ISO date-time, within the last 48 hours, or up to 5 minutes ahead for browser clock skew (counted from now). Default: the server's midnight. |
Responses
- 200The calls, newest first, and today's count.
Response fields
application/json · object
entriesarray of objectrequired10 fields
idstringrequiredThe audit event's id.
atstring (date-time)requiredWhen, ISO 8601.
toolstringrequiredThe Agent tool it called.
resourceIdstring | nullrequiredWhat it acted on: a plain record id; null when none, or when the value is not a plain id the PHI scrub leaves as is.
kindstringrequiredOne of: "read", "proposal", "unknown"
okbooleanrequiredIt worked.
statusinteger | nullrequiredThe HTTP status; null when none.
conversationIdstring | nullrequiredThe browser's conversation id; null when the request had none.
notRunbooleanPresent and true when the call was held back because its action is set to Asks first: nothing ran and no API was called.
proposalobject2 fields
statusstringrequiredWhat became of the change: pending (nothing yet), done (its screen made it), waiting_second_admin (a deploy waiting for a second admin), in_progress (approved, not finished: a deploy not deployed yet or a rotation still running), failed (the rotation's background job failed), skipped (Not now).
One of: "pending", "done", "skipped", "waiting_second_admin", "in_progress", "failed"
approvedByarray of stringrequiredWho made the change, in order.
todayintegerrequiredCalls since todayFrom, up to 999.
daysintegerrequiredThe window the entries cover, in days.
- 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/ai/activity" \
-H "Authorization: Bearer $TOKEN"What the Agent can do
get/api/ai/capabilities
Every action the Agent can take in the caller's workspace (the Agent's What it can do view), in groups (Workflows, Messages, Tunnels, Connections, Docs and messages): what it does, the MedHook API call behind it, and whether it does it alone (alone) or asks first (ask). Two levels only. A locked action always asks first and gives its reason ("goes live", "PHI, audited", "changes a live tunnel", "leaves MedHook", "credentials"). Modes are per workspace; with nothing chosen each action has its default. count is the number of actions. Asking first never runs anything from the conversation: the Agent links to the screen that does it. The next chat request reads the mode: an action that asks first is never run from the conversation, and an action that changes something only offers a card that opens its screen. Not gated on AI features. Rate limited to 60 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiCapabilities
Responses
- 200The actions, by group.
Response fields
application/json · object
groupsarray of objectrequired2 fields
labelstringrequiredOne of: "Workflows", "Messages", "Tunnels", "Connections", "Docs and messages"
actionsarray of objectrequired8 fields
idstringrequiredThe action's id, for PUT /api/ai/capabilities/{action}.
One of: "workflow.read", "workflow.draft", "workflow.test", "workflow.deploy", "workflow.toggle", "workflow.listener", "message.search", "message.reveal", "message.dry-run", "message.replay", "queue.pause", "tunnel.read", "tunnel.test-mllp", "tunnel.psk", "tunnel.psk-link", "connection.read", "connection.limits", "connection.secret", "docs.write", "docs.slack"
descriptionstringrequiredWhat the Agent does.
apiLinestringrequiredThe MedHook API call behind it (or
local draft/ the external call).modestringrequiredThe workspace's mode.
One of: "alone", "ask"
defaultModestringrequiredThe mode with nothing chosen.
One of: "alone", "ask"
lockedbooleanrequiredAlways asks first; the mode can't be changed.
reasonstring | nullrequiredWhy it is locked; null when it isn't.
One of: "goes live", "PHI, audited", "changes a live tunnel", "leaves MedHook", "credentials", null
wiredbooleanrequiredThe Agent has a tool or an Asks first card behind it; false means it can't do this yet.
countintegerrequiredHow many actions there are.
- 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/ai/capabilities" \
-H "Authorization: Bearer $TOKEN"Choose whether the Agent does an action alone
put/api/ai/capabilities/{action}
Sets one action's mode for the caller's workspace: alone or ask. A locked action is 400; an unknown action 404. Audited as ai.capability.changed with {action, from, to}. The next chat request reads the mode: an action that asks first is never run from the conversation, and an action that changes something only offers a card that opens its screen. Setting the mode it already has stores and audits nothing. Rate limited to 30 requests per minute.
Minimum role: admin.
Auth: Bearer token (how to get one) · Operation: putAiCapability
Parameters
| Name | In | Type | Description |
|---|---|---|---|
actionrequired | path | string | The action's id (see GET). |
Request body (required)
application/json · object
modestringrequiredOne of: "alone", "ask"
Responses
- 200The action with its new mode.
Response fields
application/json · object
actionobjectrequired8 fields
idstringrequiredThe action's id, for PUT /api/ai/capabilities/{action}.
One of: "workflow.read", "workflow.draft", "workflow.test", "workflow.deploy", "workflow.toggle", "workflow.listener", "message.search", "message.reveal", "message.dry-run", "message.replay", "queue.pause", "tunnel.read", "tunnel.test-mllp", "tunnel.psk", "tunnel.psk-link", "connection.read", "connection.limits", "connection.secret", "docs.write", "docs.slack"
descriptionstringrequiredWhat the Agent does.
apiLinestringrequiredThe MedHook API call behind it (or
local draft/ the external call).modestringrequiredThe workspace's mode.
One of: "alone", "ask"
defaultModestringrequiredThe mode with nothing chosen.
One of: "alone", "ask"
lockedbooleanrequiredAlways asks first; the mode can't be changed.
reasonstring | nullrequiredWhy it is locked; null when it isn't.
One of: "goes live", "PHI, audited", "changes a live tunnel", "leaves MedHook", "credentials", null
wiredbooleanrequiredThe Agent has a tool or an Asks first card behind it; false means it can't do this yet.
- 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 -X PUT "$ENGINE_URL/api/ai/capabilities/<action>" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"mode": "alone"
}'Where the Agent's postmortem would be posted
get/api/ai/postmortem/share
The Slack channel a postmortem is posted to: the Slack channel connected in Settings › Notifications, or null while Slack is not connected (the Postmortem's Post button is then disabled). Never a credential. A read: not audited. Rate limited to 120 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: getAiPostmortemShare
Responses
- 200The channel, or null.
Response fields
application/json · object
channelstring | nullrequiredThe Slack channel of the notification channel registry (Settings › Notifications), as
#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/ai/postmortem/share" \
-H "Authorization: Bearer $TOKEN"Post the Agent's postmortem to the Slack channel
post/api/ai/postmortem/share
The person posts the postmortem the Agent drafted (the Agent never posts it; the screen asks first). The text passes the structure-aware PHI scrub (HL7 PID-3, PID-5, PID-7 and other identifiers, then the free-text rules; hashed the same way for the same postmortem) and is sent with Slack's chat.postMessage to the registry's channel; the response carries the text that was sent. With preview: true the response is only {text}, the exact text a post of the same postmortem sends, and nothing is sent or audited (the screen's confirm shows it). Audited as ai.postmortem.posted with {channel, conversationId}, never the text. 409 CHANNEL_NOT_CONNECTED ("Connect Slack in Settings › Notifications first") while Slack is not connected; 502 DELIVERY_FAILED when Slack refuses (its error code only); 400 on a bad body; 500 when the channel can't be read. Rate limited to 10 requests per minute, previews included.
Minimum role: operator.
Auth: Bearer token (how to get one) · Operation: postAiPostmortemShare
Request body (required)
application/json · object
textstringrequiredThe postmortem.
conversationIdstringThe Agent conversation it came from (letters, digits,
_,-; at most 80).previewbooleanOnly answer the text that would be sent (
{text}); send and audit nothing.
Responses
- 200Posted (or, with `preview`, only `{text}`).
Response fields
application/json · object
channelstringrequiredThe Slack channel of the notification channel registry (Settings › Notifications), as
#name.textstringrequiredThe text that was sent, PHI removed.
- 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
Example request
curl -X POST "$ENGINE_URL/api/ai/postmortem/share" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "string",
"conversationId": "string",
"preview": true
}'Ask the engine's admins to turn on AI features
post/api/ai/access-requests
Works while AI features are off and never reaches an AI service. Tells the engine's active admins through the notification channels connected in Settings › Notifications: an email to each admin on the Email channel, and a line on the Slack channel. What is sent names the person (their name, or the part of their email before the @) and nothing else. notified lists the channels that delivered; it is empty when none is connected, and the ask is in the audit log either way (ai.access.requested, the person as actor). Once per person per rolling 24 hours: then 429 ALREADY_ASKED ("Already asked today"). Any signed-in role; 401 when the caller can't be named. No body. Rate limited to 10 requests per minute.
Minimum role: viewer.
Auth: Bearer token (how to get one) · Operation: postAiAccessRequest
Responses
- 201Asked.
Response fields
application/json · object
askedbooleanrequiredAlways true.
notifiedarray of stringrequired
- 400The request is malformed or fails validation.
application/json · ApiError
- 401No credential, or the token is invalid or expired.
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/ai/access-requests" \
-H "Authorization: Bearer $TOKEN"Schemas
Named objects the operations above link to.
AIMappingSuggestion
sourceFieldstringrequiredsourcePathstringtargetFieldstringrequiredconfidencenumberrequiredtransformstring | nullOptional note on a value change the model suggests (free text; not applied).
notesstring
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.