Skip to content

HTTP API endpoints and payloads

The independent ExecKernel HTTP API loads graphs from its configured loader and manages sessions through its API session store. Your application sends JSON, retains the returned session ID and reads the state and presentation payload in each response. This reference describes the Slim application and the additional behavior of its supplied deployment.

The core package also contains HTTP and replay middleware with different contracts. Those components are documented in Core HTTP and replay middleware contracts. Their routes are not registered by this API.

The six engine-facing routes return HTTP 200 on success, including creation and deletion.

Method and path Consumed input Success body before trace decoration
POST /execkernel/session/start JSON flow; optional lang and context. {session_id, state, payload}
POST /execkernel/session/next JSON session_id, edge_id; optional context. {session_id, state, payload}
POST /execkernel/session/resume JSON session_id; optional lang. {session_id, state, payload}
DELETE /execkernel/session/{session_id} Session ID in the path. {deleted, session_id}
POST /execkernel/graph/inspect JSON flow. {nodes, edges, labels}
GET /execkernel/sessions/{session_id}/status Session ID in the path. {session_id, current_node, node_status?}

The route registrar also adds GET /internal/metrics. The supplied deployment adds GET /healthz and blocks external metrics access. Their exact availability is described below.

There are no graph-upload, replay or session/navigate routes in this application. The body field is flow, not flow_id or graph_code. Unknown body fields are ignored by these controllers; their presence does not enable another operation.

Header Contract
Authorization: Bearer <token> Required by the supplied deployment for API operations. Exactly one Authorization value is accepted and compared with its configured token.
Content-Type: application/json Send JSON bodies to the four POST operations. The controllers decode the raw body as JSON.
X-Trace-Id A single valid value is reused; otherwise the application generates one. Valid values contain 1–128 characters from letters, digits, underscore, dot, colon and hyphen.
X-Session-Id Does not replace the required JSON/path session ID.
X-Correlation-Id Is not translated into X-Trace-Id by this application.
If-Match No HTTP precondition contract consumes it here.

createApp() registers routes and middleware but does not add bearer authentication. deploy/runtime.php adds DeploymentAccessMiddleware; your own host must provide its required access policy when mounting the application differently. The deployment token authorizes service access; user-to-session ownership remains your application’s responsibility.

Each POST body must contain a JSON object; an empty request body is invalid. Empty input, malformed JSON, a scalar/list root, duplicate object keys and unsupported numeric ranges are rejected with HTTP 400 / EK-INPUT-400. This check occurs before PHP could silently discard duplicate fields or approximate an out-of-range integer.

The context field is optional. When supplied, it must be a JSON object with scalar values: strings, booleans, integers or finite floats. Keys must remain strings after PHP decoding, and digit-only names are rejected; for example, both "123" and "0123" are invalid. Empty {} is valid. Root null, [], nested objects, lists and null values are rejected.

SDK builders and their declared JSON types can represent more values than this API accepts. They do not widen this endpoint contract. Further core validation, such as prohibited context keys or size limits, still applies; see Configuration, defaults and limits.

Field Type and default Behavior
flow Required non-empty string or positive JSON integer. Selects a graph code or numeric graph ID. Strings are trimmed.
lang Optional non-empty string; trimmed. Uses the graph’s default language when omitted. Explicit null is invalid.
context Optional scalar-valued object. Supplies the initial context; omission means empty context.

The server generates a 32-character hexadecimal session ID. It does not accept a client-selected session ID, state, timestamp or expected revision through this request. The graph remains in the configured server catalogue; start does not upload it.

The examples return to the learning-path catalogue entry from HTTP API integration. It has code learning-path and numeric ID 7006. Node 10 offers a guide through edge 101 to terminal 20 and practice through edge 102 to terminal 30; practice requires practiceEnabled: true. The catalogue definition provides those IDs and labels.

{
"flow": "learning-path",
"lang": "en",
"context": {"practiceEnabled": true}
}

Send this body to POST /execkernel/session/start. Its response places the session at node 10 and supplies a node payload containing both choices. {"flow":7006} selects the same catalogue graph.

Field Type Behavior
session_id Required non-empty string; trimmed. Loads the server’s stored session.
edge_id Required JSON integer. Selects an outgoing edge; a string or floating-point value is invalid.
context Optional scalar-valued object. Updates the stored execution context for evaluation.

For the session returned by start:

{
"session_id": "596045e185e00524a6579e139d1e2ae6",
"edge_id": 101
}

Send the body to POST /execkernel/session/next, replacing the example ID with the ID returned to your application. This chooses the guide and moves to node 20. The API validates the transition against its stored session, commits the resulting state and only then publishes deferred success events.

lang is not consumed by this endpoint. Next uses the language stored when the session was started. Likewise, sending timestamp, state or expected_revision does not replace server data or establish a precondition.

Start, next and resume return these outer fields:

Field Type and purpose
session_id String identifying the session.
state Core state representation: graph identity, current position, context, history and timestamps.
payload Node or terminal presentation data; the discriminator is payload.type.
trace_id Identifier also returned in the X-Trace-Id response header.

The following complete next response belongs to the guide selection above. IDs and timestamps are example values, not values to expect on every call:

{
"session_id": "596045e185e00524a6579e139d1e2ae6",
"state": {
"graph_code": "learning-path",
"flow_id": 7006,
"current_node": 20,
"context": {"practiceEnabled": true},
"history": {
"edges": [101],
"nodes": [10, 20],
"overflow_policy": "preserve"
},
"created_at": 1796410364,
"updated_at": 1796410364,
"last_transition_at": 1796410364,
"graph_version": null,
"dsl_version": null
},
"payload": {
"type": "terminal",
"node_id": 20,
"title": "Guide selected",
"subtitle": null,
"description": null,
"extras": {"mode": "guide"},
"outputs": [
{
"type": "content",
"url": null,
"label": null,
"open_behavior": null,
"lang": "en",
"content": "Read the guide at your own pace."
},
{
"type": "url",
"url": "https://example.org/learning/guide",
"label": "Open the guide",
"open_behavior": null,
"lang": "en",
"content": null
}
]
},
"trace_id": "82e31525d77550732d7588a463f79ea5"
}

state.current_node and payload.node_id identify the same position; the terminal information is in the payload rather than an added outer is_terminal field. An empty PHP context can appear as [] in a response even though incoming context must be a JSON object. The response has no persisted flag. Its state is documented in Session state and serialization, and its presentation fields in Node and terminal payloads.

Full request/response exchanges for all six operations and the missing-session error are available in English and Spanish.

POST /execkernel/session/resume accepts required session_id: string and optional lang: string. Both are trimmed and must be non-empty when supplied; null language is invalid.

{"session_id":"596045e185e00524a6579e139d1e2ae6"}

Resume loads the server snapshot and regenerates the payload at its current position. It returns the shared session envelope without adding a transition or saving a replacement state. Omitted language uses the snapshot’s language, falling back to the graph default if that stored language is empty.

An explicit language changes this response only. For example, resuming in Spanish can return Spanish presentation, while a later next still uses the original start language. Resume does not consume context updates or an uploaded snapshot. A missing or expired session produces HTTP 400 / EK-INPUT-400 with message Session not found.

DELETE /execkernel/session/{session_id} uses the path ID and needs no body. A successful response is:

{
"deleted": true,
"session_id": "596045e185e00524a6579e139d1e2ae6",
"trace_id": "28b4bd3864608bd4258d26fcc696f311"
}

Deletion is idempotent: an absent session can still return deleted: true. That response does not prove a session existed before deletion. A subsequent resume/status query must handle the missing-session error.

GET /execkernel/sessions/{session_id}/status also uses the path ID and needs no body:

{
"session_id": "596045e185e00524a6579e139d1e2ae6",
"current_node": 20,
"node_status": "terminal",
"trace_id": "3e18477b1a626c67ceaeab2669a0919d"
}

The service resolves the session graph and includes node_status as active or terminal when it finds the node. It does not include context, history, presentation payload or a log tail. Use resume when your application needs the current screen.

POST /execkernel/graph/inspect consumes only flow, with the same string/positive-integer rules as start:

{"flow":"learning-path"}

Inspection returns a structural projection without creating a session:

Response field Row shape
nodes {id: integer, isTerminal: boolean}
edges {id: integer, fromNode: integer, toNode: integer}
labels {edgeId: integer, lang: string, text: string, description: string|null, extras: object|array|null}
trace_id Response trace string.

For the example, nodes are 10, 20 and 30; edge 101 connects 10 → 20 and edge 102 connects 10 → 30. Labels include both graph languages. Inspection does not evaluate choices for a particular context and does not return node metadata, conditions or terminal outputs. The downloadable exchanges contain the full projection.

The service uses the server-loaded snapshot as the expected state for a transition. A ConditionalSessionStoreInterface implementation performs create-if-absent or save-if-unchanged and returns a fresh internal write generation. A conflict is HTTP 409 / EK-STATE-007.

That write generation is not an HTTP field. There is no ETag/If-Match or expected-revision input in these routes. A third-party legacy store receives pre/post readback checks, which confirm observable content but do not provide an atomic compare-and-swap guarantee.

createApp() defaults to NullSessionStore when no store is supplied. In that explicitly stateless mode, start can return a computed result but later resume/next cannot recover it. The supplied deployment uses its configured persistent store. A 200 start response by itself does not identify which store the host mounted.

Application errors use:

{
"error": {
"code": "EK-INPUT-400",
"message": "Session not found.",
"details": {
"http": 400,
"trace_id": "reference-error"
}
}
}

The response header carries the same trace ID. Error responses put it inside error.details rather than adding the success body’s outer trace_id. Ordinary exceptions mapped by ExceptionMiddleware do not expose the domain exception’s full context, severity or hint. The application rate limiter can additionally include session_id, window_seconds and max_requests in error.details; Nginx’s rate-limit envelope contains only http and trace_id there.

Condition HTTP API code
Invalid JSON/fields/context, unsupported language, missing or expired session 400 EK-INPUT-400
Unknown route or graph 404 EK-FLOW-404
Missing target node 404 EK-NODE-404
Missing, invalid or unavailable-from-current-node edge 400 EK-EDGE-404
Edge blocked by rule/security condition 403 EK-RULE-403
Edge reuse or detected cycle 409 EK-CYCLE-001
Conditional persistence conflict 409 EK-STATE-007
Session integrity failure 409 EK-SEC-SES-001
Deployment bearer rejection 401 EK-API-003; includes WWW-Authenticate.
Rate limit 429 EK-RATE-429
Method not allowed by Slim 405 EK-ENGINE-500
Unhandled engine/adapter failure 500 EK-ENGINE-500

The supplied Nginx ingress adds its own JSON errors: oversized body 413 / EK-INPUT-400, rate limit 429 / EK-RATE-429 and unavailable backend 503 / EK-ENGINE-500. Deployment bootstrap failure also returns 503. These responses can occur before a controller runs. See API configuration, access and rate limits for the configured limits and Error codes and exceptions for SDK interpretation.

Surface Effective contract
createApp() / route registration Registers GET /internal/metrics. Without an added access layer, the route is callable.
Deployment access middleware Rejects /internal/* with application HTTP 404 before bearer evaluation.
Supplied Nginx configuration Does not forward /internal/metrics to PHP; it falls through to Nginx’s own 404, outside the application JSON envelope.
deploy/runtime.php Adds GET /healthz, exempt from bearer authentication.

Metrics returns counts, latency_totals, latency_counts and error_counts, plus the normal trace decoration. The first three maps use keys such as POST /execkernel/session/next 200; error counts use method and endpoint without status. Counts are integers and latency totals are seconds. Empty PHP maps can serialize as []. The response reflects measurements already recorded before its own handler completes.

The registry and application rate limiter live in their PHP objects. The default limiter targets next/resume with 30 requests per 60 seconds per session; the supplied FPM deployment disables that limiter and uses ingress limiting. Metrics from a short-lived FPM application are not a cross-request collector, which is why deployment access blocks the internal route.

Health returns {"status":"ok","trace_id":"…"} when its checks succeed. A graph-catalogue validation failure returns 503 with status: "unavailable"; a bootstrap failure returns the service-unavailable error envelope. Health describes service readiness, not whether a particular saved session can resume. SQLite backup, recovery and health explains that operational distinction.