AI Sessions
Sessions are persistent conversation contexts for multi-turn AI interactions. Sessions support archiving and pinning for organization, and are automatically purged 30 days after being ended to comply with AI provider data retention policies.
Session Lifecycle Walkthrough
POST /ai/sessionsto create a session (setassistantType, optionalmetadata, and the primary context scope you need).- Persist the
session.idand pollGET /ai/sessions/:idto render the session title, status, and last activity. - Use
PATCH /ai/sessions/:id/pin/archive/unpin/unarchivefor the organization workflow you want, then callDELETE /ai/sessions/:idwhen the conversation is over. - Keep session IDs to load history (
GET /ai/sessions), resume SSE streams, or order sessions bylastActivityAtin your UI.
const chainyId = process.env.CHAINY_ID; // id of the Project this session is scoped to
const manageSession = async () => {
const sessionRes = await fetch(`https://api.chainabit.com/api/v1/ai/sessions`, {
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Chainabit onboarding",
assistantType: "chao",
primaryContextType: "chainy",
primaryContextId: chainyId,
}),
});
const session = (await sessionRes.json()).data;
await fetch(`https://api.chainabit.com/api/v1/ai/sessions/${session.id}/pin`, {
method: "PATCH",
headers: { Authorization: `Bearer ${TOKEN}` },
});
const refreshed = await fetch(
`https://api.chainabit.com/api/v1/ai/sessions/${session.id}`,
{ headers: { Authorization: `Bearer ${TOKEN}` } }
);
console.log("Session status:", (await refreshed.json()).data.status);
};Endpoints
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /ai/sessions | List sessions | JWT + Entitlement |
| POST | /ai/sessions | Create a session | JWT + Entitlement |
| GET | /ai/sessions/:id | Get a session | JWT + Entitlement |
| DELETE | /ai/sessions/:id | End a session | JWT + Entitlement |
| PATCH | /ai/sessions/:id/archive | Archive a session | JWT + Entitlement |
| PATCH | /ai/sessions/:id/unarchive | Restore an archived session | JWT + Entitlement |
| PATCH | /ai/sessions/:id/pin | Pin a session | JWT + Entitlement |
| PATCH | /ai/sessions/:id/unpin | Unpin a session | JWT + Entitlement |
| POST | /workspaces/:workspaceId/ai/sessions/:sessionId/share | Create or reactivate a share link (public unless noIndex is set) | JWT + Entitlement |
| PATCH | /workspaces/:workspaceId/ai/sessions/:sessionId/share | Switch an active share between public and link only | JWT + Entitlement |
| DELETE | /workspaces/:workspaceId/ai/sessions/:sessionId/share | Revoke a share link | JWT + Entitlement |
| GET | /cs/:urlShort | Resolve a shared session by short URL | None (public) |
GET /ai/sessions
Description
List AI sessions for the authenticated user. Returns active sessions by default. Pass ?status=archived to list archived sessions. Results are offset-paginated and can be searched with q.
Authentication: JWT Bearer token + active AI entitlement required.
Request
Query Parameters
| Parameter | Type | Description |
|---|---|---|
limit | integer | Number of sessions to return. Defaults to 20, max 50. |
offset | integer | Number of sessions to skip. Defaults to 0. |
status | "active" | "archived" | Filter by session status. Defaults to active. |
chainyId | string (uuid) | Optional. Filter to sessions associated with a specific Project. |
q | string | Optional. Search session titles or date-like session timestamps. Max 200 characters. |
originSurface | string | Optional. A surface name, for example drawer (the values of the originSurface response field). Lists only sessions you own that were started on that surface; sessions you were invited to are not included. |
originRoute | string | Optional. A route pattern such as /agents or /bits/:view. Lists only sessions you own that were started in the Chao drawer on that page (exact match; patterns carry no query string and no ids). Max 80 characters. Anything that is not a route pattern returns 400. |
Response
Response Example
{
"data": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Spanish Learning Coach",
"titleGenerationState": "resolved",
"status": "active",
"sessionType": "chat",
"mode": "auto",
"visibility": "private",
"startedAt": "2026-03-17T10:00:00.000Z",
"lastActivityAt": "2026-03-17T11:00:00.000Z",
"archivedAt": null,
"pinnedAt": "2026-03-17T09:00:00.000Z",
"chainyId": null,
"originSurface": "web",
"originRoute": null,
"lastRoute": null,
"metadata": {
"title": "Spanish Learning Coach"
},
"privacyMode": "standard",
"temporary": false,
"humanParticipantCount": 0,
"isOwner": true
}
],
"meta": {
"limit": 20,
"offset": 0,
"total": 1,
"totalCount": 1,
"hasNextPage": false
}
}Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Session ID |
title | string | null | Session title; null until Chao has named the chat |
titleGenerationState | string | pending, resolved or fallback: whether the title is still being generated |
status | string | active or archived |
sessionType | string | The kind of session, for example chat |
mode | string | Tool execution mode: auto, approval or plan |
visibility | string | Who can open the session, for example private |
startedAt | string | ISO 8601 timestamp when the session started |
lastActivityAt | string | null | ISO 8601 timestamp of the latest activity, or null |
archivedAt | string | null | ISO 8601 timestamp when archived, or null |
pinnedAt | string | null | ISO 8601 timestamp when pinned, or null |
chainyId | string | null | The Project the session belongs to, or null |
originSurface | string | null | Where the session was started: web, drawer, cli, desktop or nexus; null when unknown |
originRoute | string | null | For a session started in the Chao drawer: the route pattern of the page it was started on, for example /agents; null for every other session |
lastRoute | string | null | For a session started in the Chao drawer: the route pattern of the page it was last used on; null for every other session |
metadata | object | null | A curated set of keys (title, assistantPreset, selectedModelKey, selectedModelProvider), or null |
privacyMode | string | standard or temporary |
temporary | boolean | True for a temporary chat |
humanParticipantCount | number | People other than the owner who take part in the session |
isOwner | boolean | True when you own the session, false when you were invited to it |
The response can carry further fields (for example the expiry fields of a temporary chat); treat unknown fields as additive.
Code Examples
Use the id of one of your Projects (AI personalities) as $CHAINY_ID in the filter example below.
curl "https://api.chainabit.com/api/v1/ai/sessions?limit=20&offset=0" \
-H "Authorization: Bearer $TOKEN"# Archived sessions:
curl "https://api.chainabit.com/api/v1/ai/sessions?status=archived" \
-H "Authorization: Bearer $TOKEN"# Filter by Project context:
curl "https://api.chainabit.com/api/v1/ai/sessions?chainyId=$CHAINY_ID" \
-H "Authorization: Bearer $TOKEN"# Search sessions:
curl "https://api.chainabit.com/api/v1/ai/sessions?q=weekly%20planning" \
-H "Authorization: Bearer $TOKEN"# Sessions started in the Chao drawer on a page (newest first):
curl -G "https://api.chainabit.com/api/v1/ai/sessions" \
--data-urlencode "originSurface=drawer" \
--data-urlencode "originRoute=/agents" \
--data-urlencode "limit=3" \
-H "Authorization: Bearer $TOKEN"POST /ai/sessions
Description
Create a new AI session.
Authentication: JWT Bearer token + active AI entitlement required.
Request
Request Body
Unknown properties are rejected. The request body accepts only the fields below.
| Field | Type | Required | Constraints | Description |
|---|---|---|---|---|
title | string | No | Max 120 chars | Session title |
assistantType | string | No | "chat" | "chao" | Session assistant type. Set to "chao" for Chao behavioral advisor sessions. Default: "chat". |
assistantPreset | string | No | — | Named assistant preset to apply to this session |
model | string | No | — | Exact active model_key to use, e.g. gemini-2.5-flash |
provider | string | No | Max 64 chars | Preferred provider key. Falls back to another active provider if unavailable. |
effortMode | string | No | "basic" | "thinking" | "pro" | High-level routing preference; the orchestrator picks a compatible model. |
mode | string | No | "auto" | "approval" | "plan" | Tool execution mode. Defaults to account preference (or "approval"). |
chainId | string | No | UUID | Chain to scope this session to |
chainyId | string | No | UUID | Project to scope this session to |
bitId | string | No | UUID | Task to scope this session to |
agentInstanceId | string | No | UUID | Agent instance to use for this session. It must be an active agent available in the session's workspace (an agent of that workspace or one shared with the whole account); otherwise 400. |
primaryContextType | string | No | "chainy" | "chain" | "workspace" | "account" | Primary context scope (Chao sessions). |
primaryContextId | string | No | UUID | UUID of the primary context entity. Required when primaryContextType is set. |
originSurface | string | No | "web" | "drawer" | "cli" | "desktop" | "nexus" | Label for where the session was started, shown beside it in session lists. A signed-in person's session records web or drawer (the other values are accepted but not recorded); a session started from the CLI is always recorded as cli, and one started from the desktop app as desktop, whatever you send. A value outside this list returns 400. It is a label only and never changes access. |
metadata | object | No | — | Free-form key/value metadata stored with the session. |
Response
Response Example
{
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Spanish Learning Coach",
"status": "active",
"sessionType": "chat",
"mode": "approval",
"startedAt": "2026-03-17T10:00:00.000Z",
"lastActivityAt": "2026-03-17T10:00:00.000Z",
"archivedAt": null,
"pinnedAt": null,
"originSurface": null,
"originRoute": null,
"lastRoute": null,
"metadata": {
"title": "Spanish Learning Coach"
}
}
}originSurface is where the session was started (web, drawer, cli, desktop or nexus). It is null when unknown, for example for sessions created before the label existed.
The metadata object in the response surfaces a curated set of keys (title, assistantPreset, selectedModelKey, selectedModelProvider); it is null when none are present.
Code Examples
Use the id of one of your Chains as $CHAIN_ID.
curl -X POST https://api.chainabit.com/api/v1/ai/sessions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Spanish Learning Coach",
"chainId": "'"$CHAIN_ID"'",
"metadata": {
"goal": "Improve daily vocabulary retention"
}
}'Creating a Chao Session
To create a session powered by Chao (Chainabit's behavioral advisor), pass assistantType: "chao" with a Project context. Use the id of the Project to coach with as $CHAINY_ID.
curl -X POST https://api.chainabit.com/api/v1/ai/sessions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "My Project Coach",
"assistantType": "chao",
"primaryContextType": "chainy",
"primaryContextId": "'"$CHAINY_ID"'"
}'When assistantType is "chao", the session automatically loads Project-scoped memories and productivity context into all AI interactions.
Reasoning and Tool Activity
Chao sessions can stream safe activity summaries while a response is being generated. Use payload.activity on events such as tool.started, tool.progress, tool.approval_required, tool.completed, tool.failed, tool.degraded, plan.step_added, and capability.resolved to render status cards.
Raw private Chain-of-Thought is not a public UI contract. If diagnostic cot.* events appear in an internal/debug session, treat them as nonessential metadata and do not show raw reasoning to end users by default.
Persisted message.toolCalls is the stable source for reconstructing tool cards after reload. See AI Messages and SSE Streaming.
GET /ai/sessions/:id
Description
Get details of a single session.
Authentication: JWT Bearer token + active AI entitlement required.
Request
- Path params:
id(Session ID)
Response
Response Example
{
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Spanish Learning Coach",
"titleGenerationState": "resolved",
"status": "active",
"sessionType": "chat",
"mode": "auto",
"visibility": "private",
"startedAt": "2026-03-17T10:00:00.000Z",
"lastActivityAt": "2026-03-17T11:00:00.000Z",
"archivedAt": null,
"pinnedAt": null,
"chainyId": null,
"originSurface": "web",
"originRoute": null,
"lastRoute": null,
"metadata": {
"title": "Spanish Learning Coach"
},
"privacyMode": "standard",
"temporary": false,
"humanParticipantCount": 0,
"isOwner": true,
"hasContent": true
}
}Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID \
-H "Authorization: Bearer $TOKEN"DELETE /ai/sessions/:id
Description
End a session. The session is soft-deleted and no longer accepts new messages. Sessions ended this way are permanently deleted after 30 days of inactivity.
Authentication: JWT Bearer token + active AI entitlement required.
Request
- Path params:
id(Session ID)
Response
Response Example
{
"data": {
"id": "cm5sess01",
"ended": true,
"endedAt": "2026-03-17T12:00:00.000Z"
}
}Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl -X DELETE https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID \
-H "Authorization: Bearer $TOKEN"PATCH /ai/sessions/:id/archive
Description
Archive an active session. Archived sessions are excluded from the default list but preserved indefinitely. Archived sessions are never auto-deleted.
Authentication: JWT Bearer token + active AI entitlement required.
Request
- Path params:
id(Session ID)
Response
Response Example
{
"data": { "count": 1 }
}Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl -X PATCH https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/archive \
-H "Authorization: Bearer $TOKEN"PATCH /ai/sessions/:id/unarchive
Description
Restore an archived session back to active status.
Authentication: JWT Bearer token + active AI entitlement required.
Request
- Path params:
id(Session ID)
Response
Response Example
{
"data": { "count": 1 }
}Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl -X PATCH https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/unarchive \
-H "Authorization: Bearer $TOKEN"PATCH /ai/sessions/:id/pin
Description
Pin a session. Pinning is a client-side organizational marker and does not change the session status. Both active and archived sessions can be pinned.
Authentication: JWT Bearer token + active AI entitlement required.
Request
- Path params:
id(Session ID)
Response
Response Example
{
"data": { "count": 1 }
}Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl -X PATCH https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/pin \
-H "Authorization: Bearer $TOKEN"PATCH /ai/sessions/:id/unpin
Description
Unpin a pinned session.
Authentication: JWT Bearer token + active AI entitlement required.
Request
- Path params:
id(Session ID)
Response
Response Example
{
"data": { "count": 1 }
}Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl -X PATCH https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/unpin \
-H "Authorization: Bearer $TOKEN"Sharing a Session
Only the session owner can create, change or revoke a share link. Invited participants and workspace members can collaborate in a session but cannot publish it (see Conversation Participants & Lenses). Sharing is scoped to Chao sessions accessed through a workspace.
Every share link has one of two audiences:
| Audience | noIndex | Who can find it |
|---|---|---|
| Public | false | Anyone with the link can open it, and search engines may index the conversation. |
| Link only | true | Only people who have the link can open it. Search engines are asked not to index it. |
A new share is public. The owner can switch a share to link only at any time with PATCH; doing so keeps the same link. Copies that a search engine has already made can remain until it refreshes them.
POST /workspaces/:workspaceId/ai/sessions/:sessionId/share
Description
Creates a read-only share link for the session. Without a noIndex value the share is public. Calling this again on an already-shared session returns the existing share rather than creating a duplicate — the urlShort does not change, and an existing share keeps its audience unless you send a noIndex value that differs. A share that was revoked is reactivated with the audience you request (public when you send none).
Authentication: JWT Bearer token + active AI entitlement required (session owner only).
Request
- Path params:
workspaceId,sessionId - Body (optional):
| Field | Type | Required | Description |
|---|---|---|---|
noIndex | boolean | No | false makes the share public, true makes it link only. Omit it to use the default for a new share (public) or to keep the audience of an existing one. |
acknowledgePrivateResults | boolean | No | Send true only after a 403 with details.acknowledgeable: true (see Conversations with private results). It applies to this share only. |
Conversations with private results
A conversation whose answers used the owner's private workspace data cannot be published silently. Without acknowledgePrivateResults the request returns 403; when the caller is the session owner, the error carries details.acknowledgeable: true:
{
"error": {
"code": "result_audience_publication_denied",
"message": "Forbidden",
"details": { "code": "result_audience_publication_denied", "acknowledgeable": true }
},
"meta": { "requestId": "94e2c8e7-3cdf-491f-b037-69d051c6268f" }
}Repeat the request with { "acknowledgePrivateResults": true } to publish that conversation knowingly. The share is created link only (noIndex is true, whatever you send) and is never offered to search engines. The acknowledgment belongs to that share: after you revoke it, the next share asks again.
Response
Response Example
{
"data": {
"id": "00000000-0000-4000-8000-000000000041",
"shareUrl": "https://chainabit.com/cs/00000000-0000-4000-8000-000000000041?share=SHARE_TOKEN",
"urlShort": "SHARE_TOKEN",
"noIndex": false,
"openCount": 0
}
}Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Identifier of the share link |
shareUrl | string | Full URL for the share link |
urlShort | string | Short token used in the URL and in GET /cs/:urlShort |
noIndex | boolean | false for a public share, true for link only |
openCount | integer | Number of times the link has been opened |
Code Examples
Use the id from Create a Session response as $SESSION_ID.
curl -X POST https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/sessions/$SESSION_ID/share \
-H "Authorization: Bearer $TOKEN"PATCH /workspaces/:workspaceId/ai/sessions/:sessionId/share
Description
Switches the session's active share between public and link only. The link and its urlShort do not change. Sending the audience the share already has is a no-op. This route never creates or reactivates a share: a session with no active share returns 404.
Authentication: JWT Bearer token + active AI entitlement required (session owner only).
Request
- Path params:
workspaceId,sessionId - Body:
| Field | Type | Required | Description |
|---|---|---|---|
noIndex | boolean | Yes | false for public, true for link only. Any other value returns 400. |
Response
The response has the same shape as POST. Use the noIndex field to confirm the audience; openCount is not reported by this route and is always 0.
Code Examples
curl -X PATCH https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/sessions/$SESSION_ID/share \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"noIndex": true}'DELETE /workspaces/:workspaceId/ai/sessions/:sessionId/share
Description
Revokes the session's active share link. The previous urlShort stops resolving immediately.
Authentication: JWT Bearer token + active AI entitlement required (session owner only).
Request
- Path params:
workspaceId,sessionId
Response
Response Example
{
"data": { "revoked": true }
}Code Examples
curl -X DELETE https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/sessions/$SESSION_ID/share \
-H "Authorization: Bearer $TOKEN"GET /cs/:urlShort
Description
Resolve a shared session by its short token. This endpoint is public and unauthenticated. Revoked, expired, and malformed tokens all resolve to a generic 404 Not Found — the response never distinguishes between those cases.
Authentication: None (public). Rate limit: 60 requests per 60 seconds.
Request
- Path params:
urlShort(from a share response'sdata.urlShort)
Response
Response Example
{
"data": {
"title": "Spanish Learning Coach",
"messages": [
{
"id": "msg_01",
"role": "user",
"content": "How am I doing with my Morning Run chain?",
"createdAt": "2026-03-17T10:00:00.000Z"
}
]
}
}Response Fields
| Field | Type | Description |
|---|---|---|
title | string | null | Session title |
messages | array | Session messages, each with id, role, content, createdAt |
Code Examples
curl https://api.chainabit.com/api/v1/cs/SHARE_TOKENData Retention
Sessions ended via DELETE /ai/sessions/:id are soft-deleted and permanently removed after 30 days of inactivity. All messages within the session are deleted at the same time.
To preserve a session indefinitely, archive it with PATCH /ai/sessions/:id/archive before deleting — archived sessions are never auto-deleted.