Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AI SDK v6 Protocol

The AI SDK v6 adapter translates Awaken’s internal AgentEvent stream into the Vercel AI SDK v6 UI Message Stream format. This allows any AI SDK-compatible frontend (useChat, useAssistant) to consume agent output without custom parsing.

Endpoint

POST /v1/ai-sdk/chat

Request Body

{
  "messages": [{ "role": "user", "content": "Hello" }],
  "threadId": "optional-thread-id",
  "agentId": "optional-agent-id"
}
FieldTypeRequiredDescription
messagesAiSdkMessage[]yesChat messages. Content may be a string or an array of content parts.
threadIdstringnoExisting thread to continue. Omit to create a new thread.
agentIdstringnoTarget agent. Uses the default agent when omitted.

Response

SSE stream (text/event-stream). Each line is a JSON-encoded UIStreamEvent.

Auxiliary Routes

RouteMethodDescription
/v1/ai-sdk/streams/:run_idGETReconnect to an active run’s SSE stream.
/v1/ai-sdk/runs/:run_id/streamGETAlias for stream reconnect.
/v1/ai-sdk/threads/:id/messagesGETRetrieve thread message history.

Event Mapping

The AiSdkEncoder is a stateful transcoder that converts AgentEvent variants into UIStreamEvent variants. It tracks open text blocks and reasoning blocks across tool-call boundaries.

AgentEventUIStreamEvent(s)
RunStartMessageStart + Data("run-info", ...)
TextDeltaTextStart (if block not open) + TextDelta
ReasoningDeltaReasoningStart (if block not open) + ReasoningDelta
ReasoningEncryptedValueReasoningStart (if not open) + ReasoningDelta
ToolCallStartClose open text/reasoning blocks, then ToolCallStart
ToolCallDeltaToolCallDelta
ToolCallDoneToolCallEnd
StepStart(no direct mapping)
StepEnd(no direct mapping)
InferenceCompleteData("inference-complete", ...)
MessagesSnapshotData("messages-snapshot", ...)
StateSnapshotData("state-snapshot", ...)
StateDeltaData("state-delta", ...)
ActivitySnapshotData("activity-snapshot", ...)
ActivityDeltaData("activity-delta", ...)
RunFinishClose open blocks, Data("finish", ...), Finish

UIStreamEvent Types

The wire format uses the type field as a discriminant, serialized in kebab-case:

  • start – message lifecycle start, carries optional messageId and messageMetadata
  • text-start, text-delta, text-end – text block lifecycle with content ID
  • reasoning-start, reasoning-delta, reasoning-end – reasoning block lifecycle
  • tool-call-start, tool-call-delta, tool-call-end – tool call lifecycle
  • data – arbitrary named data events (state snapshots, activity, inference metadata)
  • finish – terminal event with finish reason and usage summary

Text Block Lifecycle

The encoder automatically manages text block open/close boundaries:

  1. First TextDelta opens a text block (TextStart).
  2. Subsequent deltas append to the open block.
  3. When a ToolCallStart arrives, the encoder closes any open text or reasoning block before emitting tool events.
  4. After tool execution completes, new text deltas open a fresh block with an incremented ID.

This ensures the frontend receives well-formed block boundaries even though the runtime emits flat delta events.