HTTP API integration
The HTTP API lets your application execute an ExecKernel graph without using an SDK. Your application sends JSON requests and retains a session identifier; the API loads the graph, checks choices and saves the execution. The response describes both the current position and the data your application can present there.
This guide follows one complete interaction and explains how to recover it in another request. It assumes a reachable service with session persistence. For the initial service setup, use the HTTP API Quick Start.
Agree on the destination and graph
Section titled “Agree on the destination and graph”Use the service root as EXECKERNEL_BASE_URL and the deployment’s token as EXECKERNEL_API_TOKEN. The requests below send Authorization: Bearer … and Content-Type: application/json. Keep the token in your application’s backend environment. The API token grants access to the deployment; your application must also check which user may act on a particular session.
The API’s configured graph catalogue contains the definitions it can load. Your application receives a graph code or numeric identifier from the service’s operator and selects that entry through the flow field. The JSON file stays on the server.
We reuse the learning-path graph from Anatomy of a graph to show how these requests become application behavior. A question at node 10 offers a guide through edge 101 and a browser exercise through edge 102. The guide ends at node 20; the exercise ends at node 30 and is available only when the context contains practiceEnabled: true.
The catalogue-ready definition adds graph_id: 7006 to that chapter’s graph. This is the only change: the standalone API catalogue requires a positive numeric graph ID as well as a graph code. Have the service operator place that file in the configured catalogue using the deployment’s usual process.
| Identifier in this example | What it identifies |
|---|---|
graph_code: "learning-path" |
The graph’s named identity; use "flow":"learning-path" in a request. |
graph_id: 7006 |
Its numeric catalogue identity; "flow":7006 selects the same graph. The session state exposes it as flow_id. |
session_id |
One execution, generated by start and returned to your application. |
edge_id: 101 |
A transition chosen within that graph, not a destination node. |
The configured catalogue requires unique codes and numeric IDs. Keep catalogue definitions stable while active sessions use them; reusing an identity for a different graph can make saved executions unusable. Graph identity and versioning develops that distinction. There is no graph-upload or catalogue-list operation in this HTTP API.
Inspect a known graph
Section titled “Inspect a known graph”Inspection returns the structure of one identified graph without creating a session:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/graph/inspect" \ --header "Authorization: Bearer $EXECKERNEL_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{"flow":"learning-path"}' \ --output inspect.jsonThe result contains nodes, edges and labels. This excerpt shows how the question connects to its two endings:
{ "nodes": [ {"id": 10, "isTerminal": false}, {"id": 20, "isTerminal": true}, {"id": 30, "isTerminal": true} ], "edges": [ {"id": 101, "fromNode": 10, "toNode": 20}, {"id": 102, "fromNode": 10, "toNode": 30} ]}Use inspection to confirm the graph’s shape or prepare a structural view. It has no session context, so it does not tell your application which choices are currently available. That information comes from a session payload.
Start with the facts the graph needs
Section titled “Start with the facts the graph needs”POST /execkernel/session/start creates a new execution. Send the graph identity, the desired language and the application facts used by its conditions:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/session/start" \ --header "Authorization: Bearer $EXECKERNEL_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{"flow":"learning-path","lang":"en","context":{"practiceEnabled":true}}' \ --output session.json
SESSION_ID="$(python3 -c 'import json; print(json.load(open("session.json"))["session_id"])')"Here, your application has established that practice is enabled. ExecKernel evaluates that supplied fact; it does not determine the learner’s eligibility in another application system.
The context boundary is deliberately narrow: context is a JSON object with string keys and scalar values—strings, finite numbers or Booleans. You can omit it or send {} when no facts are needed. Lists, nested objects, null values and numeric keys are rejected. For example, send {"practiceEnabled":true} rather than a nested learner record. The same restriction applies to context supplied with a choice.
The response has this shape. The excerpt omits timestamps, additional presentation fields and the request trace, and uses a placeholder for the generated session identifier:
{ "session_id": "<session-id>", "state": { "graph_code": "learning-path", "flow_id": 7006, "current_node": 10, "context": {"practiceEnabled": true}, "history": {"edges": [], "nodes": [10], "overflow_policy": "preserve"} }, "payload": { "type": "node", "node_id": 10, "title": "How would you like to learn?", "edges": [ { "id": 101, "labels": [{"text": "Read the guide"}], "enabled": true, "availability": "available" }, { "id": 102, "labels": [{"text": "Practise in the browser"}], "enabled": true, "availability": "available" } ] }}Each part has a different use:
| Response field | What your application does with it |
|---|---|
session_id |
Associates the execution with its own record and sends the identifier in later requests. |
state |
Reads the confirmed position, context and recorded path when application logic needs them. |
payload |
Builds the current screen: a heading and labeled choices here. |
trace_id |
Retains a request identifier when diagnosing a particular call. It does not identify the session. |
A choice control should carry the edge’s integer id and reflect its enabled or availability value. Starting with practiceEnabled: false would return the same question with the exercise blocked. Availability is still checked by the API when a choice arrives.
Submit a choice and use the result
Section titled “Submit a choice and use the result”When the person using your application selects the guide, send edge 101 for the retained session:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/session/next" \ --header "Authorization: Bearer $EXECKERNEL_API_TOKEN" \ --header "Content-Type: application/json" \ --data "{\"session_id\":\"$SESSION_ID\",\"edge_id\":101}" \ --output next.jsonThe API loads the stored execution, checks the edge from its current node and saves the accepted result. Send the edge identifier as a JSON integer. You do not send a replacement state object or choose a destination node directly.
The response keeps the same session_id and now has state.current_node: 20. Its payload is terminal:
{ "type": "terminal", "node_id": 20, "title": "Guide selected", "outputs": [ {"type": "content", "lang": "en", "content": "Read the guide at your own pace."}, { "type": "url", "lang": "en", "url": "https://example.org/learning/guide", "label": "Open the guide" } ]}This is an excerpt of payload. Your application can show the content as text and the URL as a link. The example’s exercise branch instead returns a redirect output. That is data for your application to act on; the API does not send an HTTP redirect or open a page on the user’s behalf. Replace the illustrative example.org URLs with the locations of your own resources.
A choice can include a context patch if your backend has established new facts. This reuses the candidate values introduced in Context updates and candidate values: they are proposed for this choice and are confirmed only if it is accepted. For a session still at node 10, this body proposes enabling practice and then selecting it:
{ "session_id": "<session-id>", "edge_id": 102, "context": {"practiceEnabled": true}}The API evaluates the proposed values together with the saved context. An accepted transition saves the result; a rejected choice does not confirm the proposed update.
Recover the screen or check the position
Section titled “Recover the screen or check the position”A later request needs the retained session identifier, not the previous response:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/session/resume" \ --header "Authorization: Bearer $EXECKERNEL_API_TOKEN" \ --header "Content-Type: application/json" \ --data "{\"session_id\":\"$SESSION_ID\"}" \ --output resumed.jsonresume returns the saved position and rebuilds its presentation payload. After the guide choice, the position remains node 20 and the guide content is returned again. It does not take another edge. An optional lang field selects the language for that response; omitting it uses the session’s saved language.
For a smaller response containing only the session’s position, call the status route. Notice that this route uses the plural sessions:
curl --fail-with-body --silent --show-error \ "$EXECKERNEL_BASE_URL/execkernel/sessions/$SESSION_ID/status" \ --header "Authorization: Bearer $EXECKERNEL_API_TOKEN"Apart from its request trace, the response is:
{ "session_id": "<session-id>", "current_node": 20, "node_status": "terminal"}node_status is active at an ordinary node and terminal at a terminal node. Use status when your application only needs that check; use resume to rebuild the screen.
Remove a saved execution
Section titled “Remove a saved execution”When your application’s retention decision calls for removing the session, send a DELETE request:
curl --fail-with-body --silent --show-error \ --request DELETE \ "$EXECKERNEL_BASE_URL/execkernel/session/$SESSION_ID" \ --header "Authorization: Bearer $EXECKERNEL_API_TOKEN"A successful response contains deleted: true and the session identifier, plus its request trace. Once removed, the session cannot be resumed. In this API, trying to resume a missing or expired session returns HTTP 400 with EK-INPUT-400 and the message Session not found.
The lifecycle routes serve these distinct purposes:
| Operation | Method and path | Result for your application |
|---|---|---|
| Start | POST /execkernel/session/start |
New identifier, saved initial state and payload. |
| Choose | POST /execkernel/session/next |
Result of an accepted transition. |
| Resume | POST /execkernel/session/resume |
Current state and presentation payload. |
| Status | GET /execkernel/sessions/{session_id}/status |
Current node and active/terminal status. |
| Delete | DELETE /execkernel/session/{session_id} |
Deletion confirmation. |
Distinguish a rejection from an unknown outcome
Section titled “Distinguish a rejection from an unknown outcome”Read the HTTP status and JSON body together. Successful operations above return HTTP 200. A rejected request uses an error envelope. For example, choosing edge 102 while practiceEnabled is false returns HTTP 403 with this structure:
{ "error": { "code": "EK-RULE-403", "message": "Edge bloqueado por condiciones de seguridad.", "details": { "http": 403, "trace_id": "<request-trace>" } }}The API’s diagnostic message is shown as returned; lang selects graph presentation text, not a translated application error message. Your application can use the code to show its own explanation and resume the session to redisplay the available choices. The rejected transition leaves this example at node 10.
| Response | Check or action |
|---|---|
401 / EK-API-003 |
Check the deployment credential. |
400 / EK-INPUT-400 |
Check the input fields; the message also identifies a missing session. |
403 / EK-RULE-403 |
Explain the rejected choice and recover the available options. |
404 / EK-FLOW-404 |
Check the graph identity, or the route if it was not one of the defined endpoints. |
409 / EK-STATE-007 |
Recover the session before resolving a conflicting save. |
The curl examples use --fail-with-body so an HTTP error produces a failing exit code while preserving the response body. A connection error is different: if the response to a choice is lost, the API may already have saved it. Use the known session identifier to recover the current state before deciding what to send next.
start generates a new identifier on the server and has no client-supplied identity or idempotency key. If its response is lost, you do not have a returned identifier to resume. Avoid treating every failed call as permission to repeat it. See Client errors, transport and diagnostics for recovery decisions and diagnostic information.
Complete HTTP interaction
Section titled “Complete HTTP interaction”The complete Bash program uses curl for the requests and Python 3 to encode inputs and prepare view data. It inspects the graph, starts a session, selects the guide, resumes it, checks its status and deletes the demonstration session after the interaction succeeds:
bash http-learning-session.shEXECKERNEL_LANG=es bash http-learning-session.shWith the connection variables already set, the output contains the question’s choices, the guide text and link, the same recovered view, terminal status at node 20 and deleted: true. It writes the session identifier to standard error so you can identify the execution if a later request fails. An error stops the sequence; the program does not repeat a write automatically.
The view adapter in the final part shows where HTTP data becomes application data: node edges become choices, and terminal outputs become messages, links or a possible redirect. It prepares those values without following the example URLs.
Complete Bash program
#!/usr/bin/env bashset -euo pipefail
: "${EXECKERNEL_BASE_URL:?Set EXECKERNEL_BASE_URL}": "${EXECKERNEL_API_TOKEN:?Set EXECKERNEL_API_TOKEN}"LANG_CODE="${EXECKERNEL_LANG:-en}"BASE_URL="${EXECKERNEL_BASE_URL%/}"
WORK="$(mktemp -d)"trap 'rm -rf "$WORK"' EXIT
request() { local method="$1" path="$2" output="$3" body="$4" local args=( --fail-with-body --silent --show-error --request "$method" "$BASE_URL$path" --header "Authorization: Bearer $EXECKERNEL_API_TOKEN" --header "Content-Type: application/json" --output "$output" ) if [[ -n "$body" ]]; then args+=(--data "$body") fi if ! curl "${args[@]}"; then cat "$output" >&2 return 1 fi}
request POST /execkernel/graph/inspect "$WORK/inspect.json" \ '{"flow":"learning-path"}'
START_BODY="$(python3 - "$LANG_CODE" <<'PY'import json, sysprint(json.dumps({ "flow": "learning-path", "lang": sys.argv[1], "context": {"practiceEnabled": True},}))PY)"request POST /execkernel/session/start "$WORK/start.json" "$START_BODY"
SESSION_ID="$(python3 - "$WORK/start.json" <<'PY'import json, syswith open(sys.argv[1]) as source: print(json.load(source)["session_id"])PY)"printf 'Session: %s\n' "$SESSION_ID" >&2
CHOICE_BODY="$(python3 - "$SESSION_ID" <<'PY'import json, sysprint(json.dumps({"session_id": sys.argv[1], "edge_id": 101}))PY)"request POST /execkernel/session/next "$WORK/next.json" "$CHOICE_BODY"
RESUME_BODY="$(python3 - "$SESSION_ID" <<'PY'import json, sysprint(json.dumps({"session_id": sys.argv[1]}))PY)"request POST /execkernel/session/resume "$WORK/resume.json" "$RESUME_BODY"request GET "/execkernel/sessions/$SESSION_ID/status" "$WORK/status.json" ""
# Delete only after the interaction is complete.request DELETE "/execkernel/session/$SESSION_ID" "$WORK/delete.json" ""
python3 - "$WORK" <<'PY'import json, sysfrom pathlib import Path
directory = Path(sys.argv[1])
def read(name): return json.loads((directory / (name + ".json")).read_text())
def view(response): payload = response["payload"] result = { "sessionId": response["session_id"], "nodeId": response["state"]["current_node"], "title": payload["title"], } if payload["type"] == "node": return result | { "kind": "choices", "choices": [{ "edgeId": edge["id"], "label": edge["labels"][0]["text"], "enabled": edge["enabled"], } for edge in payload["edges"]], }
outputs = payload["outputs"] return result | { "kind": "result", "messages": [ item["content"] for item in outputs if item["type"] == "content" ], "links": [{ "url": item["url"], "label": item["label"] or item["url"], } for item in outputs if item["type"] == "url"], "redirect": next(( item["url"] for item in outputs if item["type"] == "redirect" ), None), }
status = read("status")print(json.dumps({ "choices": view(read("start")), "result": view(read("next")), "resumedView": view(read("resume")), "status": { "currentNode": status["current_node"], "nodeStatus": status["node_status"], }, "deleted": read("delete")["deleted"],}, ensure_ascii=False, indent=2))PY