Skip to main content

K12 Tools Endpoint Reference

This page documents the authentication requirements, common endpoint pattern, and full tool inventory for the K12 Safety API. All 11 external-facing tools share the same execution model and authentication flow described here.


Authentication and Environments

note

For full setup instructions including prerequisites, token acquisition, environment base URLs, and required headers, see the Authentication and Setup page.

Every API call requires three headers:

HeaderValue
AuthorizationBearer {access_token} (OAuth 2.0 client credentials)
Ocp-Apim-Subscription-Key{subscription_key}
Content-Typeapplication/json

Legacy Tool Execute (Current)

All K12 tools share a single execution endpoint:

POST {BASE_URL}/ai/api/tools/{tool-id}/execute

Every request body wraps tool-specific inputs inside a data envelope:

{
"data": {
"field1": "value1",
"field2": "value2"
}
}

The response structure varies by tool but always returns JSON. Kickoff tools return tracking identifiers; status tools return progress information; result tools return the completed output.

Domain Routes (Alternative)

The API also exposes domain-scoped routes with descriptive URLs and flat request bodies:

POST {BASE_URL}/ai/k12/tools/{slug}

Domain routes accept a flat JSON body (no data wrapper) and return 422 for validation errors instead of 400. Both endpoint styles reach the same underlying tools.

Example: To call k12-qrg-generation-kickoff via the domain route:

curl -X POST "${BASE_URL}/ai/k12/tools/qrg-generation-kickoff" \
-H "Authorization: Bearer $TOKEN" \
-H "Ocp-Apim-Subscription-Key: $SUBSCRIPTION_KEY" \
-H "Content-Type: application/json" \
-d '{
"emergencyOperationPlanId": "d4e5f6a7-b8c9-0123-d456-e78901234567",
"waitForResult": false
}'

Domain workflow routes are also available:

POST {BASE_URL}/ai/k12/workflows/{slug}                -- Synchronous execution
POST {BASE_URL}/ai/k12/workflows/{slug}/start-async -- Async (returns runId)
GET {BASE_URL}/ai/k12/workflows/{slug}/runs/{runId} -- Poll run status
note

The examples in this documentation use the legacy /ai/api/tools/.../execute endpoint. Domain routes can be used interchangeably by dropping the data wrapper from the request body and using the domain path instead.


Tool Quick Reference

The K12 Safety API exposes 19 tools organized into three groups plus cancellation tools:

EOP Editing

Tool IDDescriptionDetails
k12-district-planning-kickoffStart district-level EOP planning editsUses the EOP kickoff schema
k12-facility-planning-kickoffStart facility-level EOP planning editsUses the EOP kickoff schema
k12-functional-annex-kickoffStart functional annex editingUses the EOP kickoff schema
k12-hazard-annex-kickoffStart hazard annex editingUses the EOP kickoff schema
k12-functional-annex-suggest-roles-kickoffSuggest missing roles for a functional annexUses the EOP kickoff schema
k12-hazard-annex-suggest-roles-kickoffSuggest missing roles for a hazard annexUses the EOP kickoff schema
k12-annex-editing-kickoffCompatibility kickoff for general EOP annex editingView schema
k12-annex-editing-statusCheck status of an editing jobView schema
k12-annex-editing-resultFetch the result of a completed editing jobView schema

EOP Role Context

Tool IDDescriptionDetails
k12-get-selected-eop-rolesResolve the currently selected EOP rolesReturns the EOP-scoped role set used by annex workflows
k12-get-eop-role-universeResolve the organization role universe for the EOPReturns selected roles plus the organization role universe used for suggest-role flows

QRG Generation

Tool IDDescriptionDetails
k12-qrg-generation-kickoffStart QRG generation from an EOPView schema
k12-qrg-generation-statusCheck status of a QRG generation jobView schema
k12-qrg-generation-resultFetch generated QRGs from a completed jobView schema

QRG Editing

Tool IDDescriptionDetails
k12-qrg-editing-kickoffStart a QRG section editing jobView schema
k12-qrg-editing-statusCheck status of a QRG editing jobView schema
k12-qrg-editing-resultFetch the result of a completed QRG editView schema

Cancellation

Tool IDDescriptionDetails
k12-cancel-task-requestCancel a pending or in-progress EOP editing jobView schema
k12-qrg-cancelCancel a pending QRG generation or editing jobView schema

Async Integration Pattern

All tool groups that perform AI processing follow the same three-step asynchronous pattern: kickoff, poll, fetch result.

Step 1: Kickoff

Call the kickoff tool with the required inputs. The response returns immediately with a requestId and sessionId that you must persist for subsequent calls.

Kickoff response fields:

FieldTypeDescription
requestIdstringUnique identifier for this job; use it to poll status and fetch results
sessionIdstringSession identifier for correlating related operations
statusstringAlways accepted on successful kickoff
messagestringHuman-readable confirmation

Step 2: Poll Status

Pass the requestId (in an array) to the corresponding status tool. Repeat until the status reaches a terminal value.

Possible status values:

StatusTerminalMeaning
acceptedNoJob received and queued
processingNoJob is actively running
success / SUCCESSYesJob completed successfully
error / ERRORYesJob failed
cancelled / CANCELLEDYesJob was cancelled
warning

EOP editing tools return lowercase statuses (success, error). QRG generation tools return uppercase statuses (SUCCESS, ERROR). Your polling logic must handle both conventions.

Step 3: Fetch Result

Once a terminal status is reached, call the result tool with the requestId to retrieve the full output.

Cancellation

To cancel a running or queued QRG job, call k12-qrg-cancel with the requestId and the jobType (generation or editing). To cancel an EOP editing job, call k12-cancel-task-request with the requestId.


Example: Full Kickoff Request

The following curl command kicks off an EOP annex editing job in the Development environment. Provide exactly one identity source: emergencyOperationPlanId or emergencyOperationPlan for persisted plans, emergencyOperationPlanConfigurationId or emergencyOperationPlanConfiguration for pre-EOP configuration-stage plans, or eopMasterCopyId/emergencyOperationPlanMasterCopy for Master Copy editing. The selected request object should send organizationId; the workflow uses that organization ID directly for district/organization details and does not derive it through EOP, configuration, or Master Copy lookups. Frontend-provided roles, userTags, or generalUserTags override backend-resolved role tags for prompt context; userTagIds may be an empty array while tag filling is pending.

curl -X POST "https://dev-k12-aitools-t27p-apim.azure-api.net/ai/api/tools/k12-annex-editing-kickoff/execute" \
-H "Authorization: Bearer $TOKEN" \
-H "Ocp-Apim-Subscription-Key: $SUBSCRIPTION_KEY" \
-H "Content-Type: application/json" \
-d '{
"data": {
"emergencyOperationPlan": {
"id": "plan-abc123",
"organizationId": "org-789",
"organization": {
"id": "org-789",
"name": "District One"
}
},
"userId": "user-456",
"userTagIds": [],
"roles": [
{ "id": "tag-principal", "name": "Principal" }
],
"form": {
"name": "Fire Safety Annex",
"field": {
"group": "Response Procedures",
"name": "evacuation_steps",
"content": "<p>Current evacuation procedures for the main building.</p>"
}
},
"prompt": "Add assembly point verification step after building clearance"
}
}'

Expected response:

{
"requestId": "req-7f3a2b1c-d4e5-6789-abcd-ef0123456789",
"sessionId": "sess-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "accepted",
"message": "Editing job accepted and queued for processing"
}

Error Responses

When the API rejects a request, it returns a structured error:

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Exactly one of emergencyOperationPlanId/emergencyOperationPlan, emergencyOperationPlanConfigurationId/emergencyOperationPlanConfiguration, or eopMasterCopyId/emergencyOperationPlanMasterCopy must be provided. Request objects may identify their source with id or organizationId; district/organization details require organizationId on the selected request object."
}
}

HTTP Error Codes

CodeMeaningWhen
400Bad RequestMissing required fields, invalid field types, malformed JSON
401UnauthorizedInvalid or expired bearer token, missing subscription key
403ForbiddenToken lacks the required OAuth scope
404Not FoundUnknown tool ID, or result not yet available for the given requestId
422Validation ErrorDomain route schema validation failed (field constraints violated)
429Rate LimitedToo many requests -- back off and retry
500Server ErrorInternal failure during processing

Job-Level Failure States

When the HTTP request succeeds (200) but the async job itself fails, the status endpoint returns one of these terminal states:

StatusMeaning
ERRORThe job failed during processing (check the error message in the result)
CANCELLEDThe job was cancelled via the cancel endpoint before completion
TIMEOUTThe job exceeded the maximum processing time

Non-terminal states: accepted (queued), PROCESSING (running).

EOP editing uses lowercase statuses. QRG generation and editing use UPPERCASE for terminal and processing states (the kickoff response uses lowercase accepted).

Common Error Scenarios

ScenarioTypical Error
Missing required field400 with validation error naming the field
Invalid authentication token401 Unauthorized
Missing subscription key401 Unauthorized
Tool ID not found404 Not Found
Rate limit exceeded429 Too Many Requests
None or more than one of emergencyOperationPlanId/emergencyOperationPlan, emergencyOperationPlanConfigurationId/emergencyOperationPlanConfiguration, and eopMasterCopyId/emergencyOperationPlanMasterCopy provided400 with specific validation message

Best Practices

  • Persist identifiers -- Store the requestId and sessionId returned by kickoff calls. These are required for all subsequent operations.
  • Poll with backoff -- Use exponential backoff when polling status endpoints. Start at 2 seconds and increase the interval.
  • Handle both status conventions -- EOP editing uses lowercase statuses; QRG generation uses uppercase. Normalize before comparison.
  • Expect partial success -- QRG generation processes each annex independently. The result may contain both successful QRGs and error entries for individual annexes.
  • Use sessions for correlation -- When performing multiple edits in sequence, pass the sessionId from the first kickoff to subsequent calls for conversation continuity.

Next Steps