Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Legacy inference, streaming, and analytics

Inline JSON

The legacy inference body is the input map itself, not the v2 {project_id, input} wrapper.

curl --fail-with-body -sS \
  "$STACKAI_BASE_URL/inference/v0/run/$ORG_ID/$PROJECT_ID" \
  -H "Authorization: Bearer $STACKAI_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"in-0":"Summarize our refund policy"}'

ORG_ID must identify the key's organization. The project must be published for this public inference route. Inputs and outputs depend on the deployed flow; use its exported API example or IO contract. Inspect the result state instead of treating every HTTP 200 as completion.

Server-sent events

curl --fail-with-body -N -sS \
  "$STACKAI_BASE_URL/inference/v0/run/$ORG_ID/$PROJECT_ID?delta=false&prefix=true&verbose=true" \
  -H "Authorization: Bearer $STACKAI_API_KEY" \
  -H 'Accept: text/event-stream' \
  -H 'Content-Type: application/json' \
  --data '{"in-0":"Summarize our refund policy"}'

Parse SSE frames across arbitrary network chunks; a network read is not necessarily an entire JSON event. Inspect the response Content-Type before parsing, because errors may be JSON. Preserve the run identifier when available and handle terminal and paused states. A dropped stream does not prove the run failed. Avoid starting another execution just to reconnect. Disable buffering in your own reverse proxy as needed.

For background legacy execution, pass execution_mode=remote and omit the SSE Accept header. The 202 response supplies a run ID and WebSocket handle; use the returned handle, not a guessed URL. Poll /inference/v0/runs/{org_id}/{run_id} when streaming is unavailable.

Consume a stream in your application

For a standard SSE parser, request prefix=true. Request verbose=true to receive the run ID, state, and pause information. With delta=false, each output frame contains the latest complete output values: replace the displayed value rather than appending it. For example:

These illustrative frames show a growing answer followed by the completion marker. Optional progress and citation fields are omitted here:

Read state and error, not the marker's message, to decide whether execution succeeded. A completion marker means that the stream ended; its state can also be FAILED, CANCELLED, or PAUSED. Do not display outputs.type or the marker's message as an answer. Save the last answer frame separately. For a pause, preserve pause securely on your backend and obtain the person's response before using the resume endpoint.

The following server-side generator parses frames across arbitrary network chunks. Call it from your application's authenticated backend route. Verify that the signed-in user may run the configured project before calling it; keep the API key and any resume token on the backend.

Implement save_run and save_pause using your application’s durable, access-controlled storage. The output ID and input key above must match your project. Send these normalized events to the browser through your application's own stream. The browser only needs to replace answer text for answer, show a waiting state for needs_input, and check the final state for finished. Render answer text as text, or sanitize any supported rich content; do not inject arbitrary HTML.

If your authenticated backend exposes these normalized events as newline-delimited JSON at /api/answer, a browser client can consume them as follows. The route must authenticate the user, authorize the configured project, call stream_answer, and send one JSON object followed by a newline for each yielded event. Do not pass arbitrary project IDs or API keys through from the browser.

A disconnect is not a request to execute again. Retain the run ID and query /inference/v0/runs/{org_id}/{run_id} for its state. This API does not document replay from an SSE Last-Event-ID; do not rely on automatic browser reconnection to resume at the last token.

Legacy resume

POST the resume token and human response to /inference/v0/runs/{org_id}/{run_id}/resume. Inline JSON, SSE, and remote resume have different backend support. Trigger-backed runs reject SSE with 406; retry the resume interface without SSE only after checking the response/state, then poll. In-process runs reject execution_mode=remote with 409. An out-of-band response can say RESUMED with no outputs while execution continues. The legacy state vocabulary includes COMPLETED; v2 exposes succeeded.

Analytics exports

GET /analytics/org/{org_id}/flows/{flow_id} with a personal key or supported legacy private organization key. It returns a list, using zero-based page and optional page_size, start_date, end_date, user_id, and comma-separated state. Use timezone-qualified timestamps and ensure start is not after end. State values are PENDING, RUNNING, PAUSED, RESUMED, COMPLETED, FAILED, and CANCELLED.

For new run-history integrations, /v2/runs provides cursor pagination and lowercase statuses. A workflow result and a run-history record serve different purposes; logging controls can make run history unavailable.

Last updated

Was this helpful?