Skip to content

HTTP API integration ​

Applies to HENGSHI SENSE 7.0. A business backend or custom UI can call the conversation HTTP/SSE service without browser UI or a Node Agent service. HENGSHI owns execution, conversations, cancellation, and permissions; the caller owns user authentication, protocol handling, display, and recovery.

Use a configured user login/SSO or API authorization solution. The service derives user and tenant from authentication; body user/tenant IDs are not authorization. Configure CORS for browser calls. The data client SDK simplifies browser transport.

Basic flow ​

  1. Check available with GET /api/chatbi/headless/capabilities.
  2. Create a fixed-scope conversation with POST /api/conversations.
  3. Start a read-only turn with POST /api/conversations/{id}/chats/headless:stream and consume SSE.
  4. Save real runId / chatUid and read run state and persisted results.
  5. Submit clarification, cancellation, or admitted operation confirmation according to user actions.

Creation example:

http
POST /api/conversations
Content-Type: application/json
Authorization: Bearer <current-user-credential>
json
{
  "title": "Sales analysis",
  "agentContext": {
    "mode": "read_only",
    "scope": { "type": "application", "appId": 251 }
  }
}

Read the conversation ID from data.id. A subject scope is { "type": "measure_subject", "measureSubjectId": 7 }; a dashboard scope is { "type": "dashboard", "appId": 251, "dashboardId": 18 }. Each conversation has one scope and a server-resolved model profile.

Turn example:

http
POST /api/conversations/123/chats/headless:stream
Accept: text/event-stream
Content-Type: application/json
Authorization: Bearer <current-user-credential>
json
{ "prompt": "Show 2025 sales quantity by region", "clientRequestId": "<unique-request-id>" }

Use a stream reader supporting POST; browser EventSource cannot directly send this POST. Configure proxies for long connections, no SSE buffering, and sufficient read timeout. Parse SSE event, data, and id; a network chunk is not necessarily a complete event.

Raw HTTP event envelopes use type, seq, runId, traceId, requestId, conversationId, chatUid, and data. The SDK places correlation fields in metadata. See SDK events. Do not mix these shapes.

Correlation identifiers ​

FieldWhen to care
runIdIdentifies one turn run. Normal streaming does not require handling it; persist it only to query status or cancel after a disconnect or page refresh. GET .../runs/{runId} returns status, stage, event counts, and errors; it does not replay text deltas already streamed.
traceIdServer-side tracing identifier for logs, audit, and diagnosis; client logic does not use it.
requestIdCorrelates one HTTP/SSE request and is returned by the server for troubleshooting. It is not a conversation or run id and cannot resume, cancel, or deduplicate a turn. The request body's clientRequestId is client-generated for correlating one submission with logs; do not confuse the two.

Run and interaction APIs ​

OperationEndpoint
Read runGET /api/conversations/{id}/chats/headless/runs/{runId}
Cancel runPOST /api/conversations/{id}/chats/headless/runs/{runId}:cancel
Chats / one chatGET /api/conversations/{id}/chats / GET /api/conversations/{id}/chats/{chatUid}
Clarification confirmationSubmit the confirmed picks through the ordinary turn route POST /api/conversations/{id}/chats/headless:stream
Abandon clarificationPOST /api/conversations/{id}/chats/headless/clarifications/{clarificationId}:abandon; only when the user dismisses without a new turn, because any new turn automatically closes a waiting clarification
Read / confirm operationGET /api/chatbi/headless/operations/{operationId} / POST /api/chatbi/headless/operations/{operationId}/confirm

Create authoring conversations with agentContext: { mode: 'authoring' } and use POST /api/conversations/{id}/chats/headless/authoring:stream. Switching endpoint cannot elevate a read-only conversation. clientContext is a bounded hint, not DOM, credentials, or permission assertions.

Use server state for disconnection, cancellation, and clarification recovery. Do not automatically resend turn POSTs or equate done with success. Display operation content and obtain explicit consent before submitting its fingerprint. See the data client SDK for examples.

Answer again uses a normal new turn and retains the old answer. The legacy GET .../regenerate endpoint is removed. New 7.0 integrations use the conversation protocol rather than legacy Agent/Workflow and /chat/completions event examples.

Endpoint reference ​

These fields cover Ask (read_only) integration. Every call runs as the signed-in user; user or tenant values in a body do not change authorization. POST bodies use Content-Type: application/json, streaming calls add Accept: text/event-stream. Configure CORS before calling from a browser.

GET /api/chatbi/headless/capabilities ​

No parameters.

FieldTypeMeaning
availablebooleanWhether a turn can start
unavailableReasonstringLICENSE_REQUIRED, SANDBOX_RUNTIME_UNAVAILABLE, MODEL_PROFILE_UNAVAILABLE, and so on
luiVersionstringEvent protocol version
eventTypesstring[]Event types the server may emit
writePolicystringWrite-policy marker
traceSupportbooleanWhether tracing is supported
scopeOptionalbooleanWhether a question may start without a query scope
limitsobjectRuntime limits; limits.runtime describes the sandbox and isolation

POST /api/conversations ​

FieldTypeRequiredMeaning
titlestringNoConversation title
agentContext.modestringYesread_only (Ask) or authoring (Act)
agentContext.scope.typestringNoapplication, measure_subject, dashboard, global; omitted means global when the server allows it
agentContext.scope.appIdnumberConditionalRequired for application and dashboard
agentContext.scope.dashboardIdnumberConditionalRequired for dashboard
agentContext.scope.measureSubjectIdnumberConditionalRequired for measure_subject

data.id in the response is the conversation ID. The scope is fixed at creation; start a new conversation to change it.

POST /api/conversations/{conversationId}/chats/headless:stream ​

FieldTypeRequiredMeaning
promptstringYesThe question for this turn
luiVersionstringNo1.0, matching capabilities.luiVersion
clientRequestIdstringYesUnique per turn; reuse it when retrying
interactionModestringNointeractive (default, clarifications allowed) or non_interactive
runtimeContextobjectNoTurn context
runtimeContext.userConfigobjectNodataSources[] with dataAppId and datasetId; one application or one subject
runtimeContext.dataAppId / datasetIdnumberNoAuthorization anchor for a single-dataset turn
runtimeContext.clarificationResolutionobjectNoSent when submitting a clarification confirmation: clarificationId and answers[] (questionId, selectedCandidateIds); validated and stored by the service, which closes that clarification when the turn is created
clientContextobjectNoBounded page context hint; never an authorization source
policyHintsobjectNoClient policy hints; server validation is unchanged
handoffobjectNoHandoff data when switching mode or scope

The response is text/event-stream. Each event envelope carries type, seq, runId, traceId, requestId, conversationId, chatUid, and data.

EventMeaning
chat.createdThe answer exists; data.chatUid is used for readback and recovery
agent.statusStage change
agent.analysis.deltaAnalysis text delta
assistant.text.deltaAnswer text delta, concatenated in order
tool.call / tool.resultTool invocation and result for progress display
agent.token_usageUsage for the turn
lui.clarificationClarification required; data.clarificationId plus questions[], each with slot, question, selectionMode, and options. One event carries every unresolved slot of the turn
lui.table / lui.chart / lui.metric_card / lui.citationStructured results with the same shape as in a persisted answer
lui.errorFailure with code and message
doneEnd of stream only; not a success marker

POST /api/conversations/{conversationId}/chats/headless/authoring:stream ​

Same body as the read-only turn. The conversation must be created with agentContext.mode=authoring; calling it on a read-only conversation grants no extra permission.

GET /api/conversations/{conversationId}/chats/headless/runs/{runId} ​

Response fields: found, runId, traceId, requestId, conversationId, chatUid, status, currentStage, lastEventType, emittedEvents, createdAt, startedAt, finishedAt, cancelRequested.

POST /api/conversations/{conversationId}/chats/headless/runs/{runId}:cancel ​

No body; returns the same run-status structure. Cancellation is a request; trust status, not a closed stream.

Clarification confirmation ​

Clarifications no longer have a dedicated answer endpoint. On lui.clarification, compose the pick for every item in data.questions[] into a new ordinary turn and submit it through POST /api/conversations/{conversationId}/chats/headless:stream:

text
继续上一个问题,已确认:
- 看哪个指标?:零售额
- 按哪个维度?:大区

Carry the structured picks in runtimeContext.clarificationResolution: creating the turn automatically moves any clarification that is still ACTIVE in that conversation to ABANDONED (recording supersededAt and supersededBy and storing the validated selections), so a normal submission does not need :abandon. A finished clarification returns selections on readback, which clients use to restore the read-only form. The service keeps the clarification turn's agent session, so the new turn resumes the same thread and the answer is no longer posted back to the service.

POST /api/conversations/{conversationId}/chats/headless/clarifications/{clarificationId}:abandon ​

Optional body {"answers":[{"questionId":"q0","selectedCandidateIds":["retail_amount"]}]}: record the confirmed picks with an explicit close. The service validates them against the questions[] rendered on that chat and stores them; an unknown question or candidate, an empty candidate list, or several candidates for a selectionMode=single (default) question is rejected with INVALID_CLARIFICATION_ANSWER, while multiple keeps the deduplicated values. Submitting a confirmation turn does not need this call: the turn carries the picks in runtimeContext.clarificationResolution and creating it supersedes the old clarification. Returns clarificationId, status (ABANDONED), parentRunId and related state fields; the turn does not continue after abandonment.

User Manual for Hengshi Analysis Platform