Understanding these core concepts will help you build effective healthcare concierge experiences with the Sunny Agents SDK. Whether you’re building provider search, appointment booking, or health information tools, these concepts form the foundation of your application.
The SDK connects to different endpoints depending on your environment:
The default websocketUrl is the staging URL. Override it for production via the websocketUrl option in createSunnyChat. Use the same environment for Sunny Central and the WebSocket URL (staging credentials with staging chat, production with production).
A conversation is a collection of messages between a patient (or healthcare user) and the AI concierge. Each conversation has:
When authenticated via createSunnyChat, conversations are automatically persisted on the server.
A message represents a single exchange in a conversation. Messages have:
'user', 'assistant', or 'system'Artifacts are rich content objects delivered inline in message text via the WebSocket. Common examples include:
Artifacts are delivered inline in message text via the WebSocket. The backend expands artifact tags JIT during streaming; clients receive the full artifact JSON (item_content, item_type) embedded in message text—no separate fetch required.
The SDK supports two authentication modes, both configured through createSunnyChat:
For applications with custom authentication providers. Your app provides an ID token and the SDK exchanges it for an access token:
idTokenProviderEmail or SMS-based authentication without passwords. The SDK renders a verification UI in the chat:
The SDK manages WebSocket connections automatically:
createSunnyChat calls GET /sdk/config to retrieve auth settingsauth.upgrade message with credentialschat.destroy() is calledThe server may assign a new WebSocket session when a connection drops and reconnects — the SDK does not resume the previous session_id. Conversation identity is independent: conversation_id, the in-memory conversations map, and activeConversationId are kept for the lifetime of the SDK instance (same tab). The next sendMessage continues the same conversation on the new transport session. Interrupted assistant streams are finalized — the spinner is cleared and any partial text is preserved — when the socket closes.
The SDK uses an event-driven architecture. Subscribe to events via chat.client to update your UI:
snapshot: Emitted when state changesconversationCreated: New conversation createdmessagesUpdated: Messages updatedstreamingDelta: Text streaming in real-timestreamingDone: Streaming completedquickResponses: Quick response suggestions availableMCP (Model Context Protocol) Approvals allow users to approve or reject tool execution requests. When the AI needs to execute a tool, it sends an approval request:
The approvalRequestId is the id field of the mcp_approval_request output item in the message’s outputItems array.
Send files as base64-encoded attachments:
The SDK maintains state internally. Access it via chat.client:
State updates trigger events, allowing you to keep your UI in sync.