---
url: /v7.0/en-us/copilot-sdk-api.md
---
# 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](copilot-sdk.md#CORS-configuration) for browser calls. The [data client SDK](copilot-sdk-client.md) 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](copilot-sdk-client.md#Events-and-results). Do not mix these shapes.

### Correlation identifiers

| Field | When to care |
| --- | --- |
| `runId` | Identifies 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. |
| `traceId` | Server-side tracing identifier for logs, audit, and diagnosis; client logic does not use it. |
| `requestId` | Correlates 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

| Operation | Endpoint |
| --- | --- |
| Read run | `GET /api/conversations/{id}/chats/headless/runs/{runId}` |
| Cancel run | `POST /api/conversations/{id}/chats/headless/runs/{runId}:cancel` |
| Chats / one chat | `GET /api/conversations/{id}/chats` / `GET /api/conversations/{id}/chats/{chatUid}` |
| Clarification confirmation | Submit the confirmed picks through the ordinary turn route `POST /api/conversations/{id}/chats/headless:stream` |
| Abandon clarification | `POST /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 operation | `GET /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](copilot-sdk-client.md) 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](copilot-sdk.md#cors-configuration) before calling from a browser.

### GET /api/chatbi/headless/capabilities

No parameters.

| Field | Type | Meaning |
| --- | --- | --- |
| `available` | boolean | Whether a turn can start |
| `unavailableReason` | string | `LICENSE_REQUIRED`, `SANDBOX_RUNTIME_UNAVAILABLE`, `MODEL_PROFILE_UNAVAILABLE`, and so on |
| `luiVersion` | string | Event protocol version |
| `eventTypes` | string\[] | Event types the server may emit |
| `writePolicy` | string | Write-policy marker |
| `traceSupport` | boolean | Whether tracing is supported |
| `scopeOptional` | boolean | Whether a question may start without a query scope |
| `limits` | object | Runtime limits; `limits.runtime` describes the sandbox and isolation |

### POST /api/conversations

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `title` | string | No | Conversation title |
| `agentContext.mode` | string | Yes | `read_only` (Ask) or `authoring` (Act) |
| `agentContext.scope.type` | string | No | `application`, `measure_subject`, `dashboard`, `global`; omitted means `global` when the server allows it |
| `agentContext.scope.appId` | number | Conditional | Required for `application` and `dashboard` |
| `agentContext.scope.dashboardId` | number | Conditional | Required for `dashboard` |
| `agentContext.scope.measureSubjectId` | number | Conditional | Required 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

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `prompt` | string | Yes | The question for this turn |
| `luiVersion` | string | No | `1.0`, matching `capabilities.luiVersion` |
| `clientRequestId` | string | Yes | Unique per turn; reuse it when retrying |
| `interactionMode` | string | No | `interactive` (default, clarifications allowed) or `non_interactive` |
| `runtimeContext` | object | No | Turn context |
| `runtimeContext.userConfig` | object | No | `dataSources[]` with `dataAppId` and `datasetId`; one application or one subject |
| `runtimeContext.dataAppId` / `datasetId` | number | No | Authorization anchor for a single-dataset turn |
| `runtimeContext.clarificationResolution` | object | No | Sent 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 |
| `clientContext` | object | No | Bounded page context hint; never an authorization source |
| `policyHints` | object | No | Client policy hints; server validation is unchanged |
| `handoff` | object | No | Handoff 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`.

| Event | Meaning |
| --- | --- |
| `chat.created` | The answer exists; `data.chatUid` is used for readback and recovery |
| `agent.status` | Stage change |
| `agent.analysis.delta` | Analysis text delta |
| `assistant.text.delta` | Answer text delta, concatenated in order |
| `tool.call` / `tool.result` | Tool invocation and result for progress display |
| `agent.token_usage` | Usage for the turn |
| `lui.clarification` | Clarification 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.citation` | Structured results with the same shape as in a persisted answer |
| `lui.error` | Failure with code and message |
| `done` | End 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.
