API Reference
Canonical streamed AI API for Impression
Impression API Reference
Impression now exposes one canonical streamed AI endpoint:
This route replaces the old split /api/chat and /api/generate streaming APIs. It accepts the shared AiStreamRequest contract and returns Server-Sent Events where each data: frame is a typed AiRunEvent.
Authentication
You can authenticate in either of these ways:
Authorization: Bearer <token>for user/session-backed requestsX-Space-API-Key: <space_api_key>for server-to-server requests
When using X-Space-API-Key, the request body must include context.spaceId, and any context.brandId must belong to that space.
Request Contract
The request body is JSON and follows the canonical AiStreamRequest shape:
Top-level fields
runIdoptional: reuse an existing run id when reconnectingafterSequenceoptional: resume after the last event sequence you processedmode:visible_chatorhidden_actionagentId: canonical product callers usehudsonAgentthreadIdoptional: existing visible thread or hidden thread resumeinput: message, action id, tool response, attachments, and surface metadatacontext: space/brand/post scope, requested targets, mutation scope, and thread semantics
Input fields
messageoptional: visible-chat user promptactionIdoptional: hidden editor action preset such as a generate or rewrite actiontoolResponseoptional: structured response to a question/choice tooluiSurface:chatoreditor_buttonattachmentsoptional: normalized file references for visible chat
Context fields
spaceId: requiredbrandId: optional but recommended when brand-scoped behavior is requiredpostIdoptional: current post contextrequestedTargets: one or more explicit targets such aschat_only,post_node,post_selection,create_post, oropen_postdefaultTargetoptionalselectionSnapshotoptionalallowedMutationScope:none,selection_only,node_only,post_only, orpost_or_createcreateThreadIfMissing: whether the run may create a threadthreadVisibility:visibleorhidden
Streaming Response
The response is SSE:
Each frame contains a typed AiRunEvent. Common event types include:
run.startedassistant.deltaassistant.completedtool.startedtool.completedtool.failededitor.deltaeditor.completedartifact.readyrun.failedrun.completed
Every event includes runId, sequence, and timestamp.
Resume / Reconnect
To resume a dropped stream:
- Keep the
x-ai-run-idresponse header from the original request. - Keep the highest
sequenceyou processed. - Reissue
POST /api/ai/streamwith:runIdafterSequence- the same canonical request context
The server replays persisted events from ai_run_events and then continues live delivery.
Current Constraints
- JSON request bodies are supported
- Multipart voice uploads are not supported on the canonical route yet
- Product-visible streamed entry flows are Hudson-first
- Hidden editor actions should use
mode: "hidden_action"
Error Handling
Errors return JSON when the request cannot be accepted before streaming starts, for example:
Once streaming has started, terminal failures arrive as a run.failed SSE event.
Examples
See API Usage Examples for curl, JavaScript, and Python examples for visible chat, hidden actions, and resume flows.