Integrating AI Chat
Step-by-step example of embedding chat sessions.
AI Chat is the simplest and fastest way to integrate therappai’s AI therapist into your product. Your application sends a user message to the API, and the API responds with supportive, therapy-aligned guidance. This flow powers chat interfaces, onboarding conversations, coaching tools, and lightweight support experiences.
This page shows how to implement AI chat end-to-end.
How AI Chat Works
Each chat interaction follows a simple loop:
User sends a message
Your app sends that message to
/chatting/therappai generates a therapist response
Your app displays the response in your UI
Repeat for the conversation
There’s no session object to create or maintain — the API is stateless per request.
1. Collect the User’s Message
Your UI (mobile, web, chat bubble) captures the text the user wants to send. Example:
"I'm feeling overwhelmed today. I'm not sure why."You then package this into a JSON request.
2. Send Message to therappai
Make a POST request to:
POST /chatting/
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/jsonBody example:
{
"message": "I'm feeling overwhelmed today and can't focus."
}Your app can include additional context if needed (optional).
3. Receive the AI Therapist Response
The API returns a structured response that includes the therapist’s message.
Example:
{
"reply": "I'm really sorry you're feeling overwhelmed. Let’s take one step at a time. Can you tell me what part of today has been the hardest so far?"
}Your UI displays this however you choose:
chat bubble
message card
conversation feed
coaching panel
This keeps your UX completely flexible.
4. Render the Response in Your UI
Most developers show AI chat using:
a chat bubble layout
timestamped messages
typing indicator (“AI is responding…”)
scrollable conversation feed
optional “suggested replies”
The message structure is intentionally simple so you can style it however you want.
5. Repeat the Loop
Each time the user sends a message, you:
Call
/chatting/Display the therapist’s response
Store the chat if your UI needs history
This continues until the interaction ends.
Optional: Store Chat History
Because the API is stateless, you decide:
whether to store conversations
how long to store them
whether to show history in your app
whether to sync chats across devices
Many early-stage integrations simply store messages client-side.
Recommended UX Enhancements
Developers often add:
Typing Indicators
Show a spinner or “therappai is responding…” after sending a message.
Message Error Handling
If network fails or token expires, show a retry option.
Suggested Replies
Prompt users with one-tap responses generated by your own heuristics or content.
Protective Copy
For sensitive messages, include calm, grounding microcopy.
Safety Layer
Every message is processed through therappai’s safety system to identify:
risk-related language
self-harm signals
severe distress phrases
harmful or abusive content
The API always responds with a safe, supportive message. No raw model output is returned.
Note: therappai does NOT contact emergency services. Crisis Buddy contacts can be shown by your app if appropriate.
Minimum Viable Integration (5 Steps)
Login user → get access token
Build a text input field
Send messages to
/chatting/Display therapist responses
Refresh token when needed
That’s enough to launch a fully working AI therapy chat.
Last updated

