Skip to content
Talk to an engineer

Headless

Headless API reference

The full surface of a headless agent. For how to put it together, see Headless mode.

KeyTypeDefaultDescription
apiNamestring-The agent’s API name from Agent Studio
mode"HEADLESS"-Selects headless mode
aiActionsRecord<string, Action>{}Client-side action handlers
tokenstring-JWT for authenticated agents
onTokenExpired() => Promise<string>-Returns a fresh JWT when token expires. If it fails, the call rejects with HTTP_ERROR (401); requests never go out without the token
languageOverridestring-ISO 639-1 language code
configuration.remoteActionsSettingsobjectFrom Agent StudioOverrides which remote actions file loads
configuration.screenSharingSettings{ active, shareMode }From Agent StudioOverrides screen sharing (shareMode: "image", "html" or "both")
OptionTypeDescription
conversationIdstringContinue this conversation; omit to start a new one
filesArray<File | string>Images to attach (PNG, JPEG, GIF), or ids from uploadFiles
signalAbortSignalStops this message
streamOptionsobjectCallbacks, see below

Resolves with:

FieldTypeDescription
conversationIdstringThe conversation
messageIdstringThe agent message, for feedback
textstringThe full agent message (markdown)
steps{ callId, label?, content }[]Tool and task agent progress
actionsActionResult[]Every client-side action run while answering
suggestions{ id, text, clickType, prompt? }[]Follow-ups. SEND_PROMPT: send it. TYPE_PROMPT: put it in your input. CALLBACK: app-defined
assetsobject[]Related content (videos, articles)
quota{ allowed, action, code }Usage limit decision; BLOCK means not answered

All optional.

CallbackReceivesWhen
onStart{ conversationId, messageId, isNewConversation, abort }The agent started answering (once per message)
onMessage{ conversationId, messageId, textDelta, fullText, turn, turnText }Text arrived
onStep{ callId, label?, content, turn, conversationId, messageId }Tool or task agent progress
onActionStart{ conversationId, messageId, callId, actionKey, params, confirmationRequired, confirmationMessage? }The agent asked to run an action
onConfirmationRequiredSame as onActionStartThe action needs confirmation; return boolean or Promise<boolean>
onRenderRender event, see belowA UI component should be shown; return its element
onActionCompleteAction request plus { success, result }The action finished, failed, or was declined
onTitle{ conversationId, title }A new conversation got its AI-generated title
onCompleteThe resolved responseThe agent finished
onErrorErrorThe message failed or was stopped
FieldTypeDescription
actionKey, callId, paramsThe action the agent called
conversationId, messageIdstringWhere to show the component
dataanyWhat the action’s execute returned (passed to its render())
awaitUserInputbooleantrue: the agent waits for the user to submit or cancel
submit(value, finished?)Promise<Response | undefined>The user submitted
cancel()Promise<Response | undefined>The user dismissed the component
MethodDescription
ready()Resolves when remote config and remote actions are loaded
sendMessage(text, options)Sends a message and streams the answer
resumePendingMessage({ streamOptions, signal })Continues a message interrupted by a full page load
getPendingConversationId()The conversation of the pending message, or null
abort()Stops every in-flight message
conversations.list / get / rename / pin / unpin / deleteConversation history
conversations.showComponent(container, component)Shows a saved component from history, read-only
sendFeedback({ conversationId, messageId, rating, reason })Rates an agent message
uploadFiles(files)Uploads images and returns their ids
transcribe(audio, { signal })Turns recorded audio into text
startShareScreen({ exclude }), stopShareScreen()Share the page with every message
addActionHandlers(actions), removeActionHandlers(keys)Manage actions
getAvailableActions()All registered actions
runAction(key, params)Runs a registered action directly
setNavigationHandler(handler, timeoutMs)How the agent navigates your app
setAgentContext(context), removeAgentContext(name)Extra knowledge for the agent
setNavigationContext(context)Where the user is in your app
shareState(key, state, handleState, schema), clearState(key)Live UI state
runTask(params)Runs a task agent
remove()Stops in-flight messages and unregisters the agent