Skip to main content
Chats are tenant- and knowledge-base-scoped conversations. The same endpoints support complete JSON responses and live Server-Sent Events (SSE).
Endpoints on this page are [User+Key]. API-key chat operations require query:rag. Use external_subject_id to isolate API-served end users; signed-in user requests do not accept that field.

Endpoints

MethodPathDescriptionAuth
GET/chatsList chats[User+Key]
POST/chatsCreate a chat, optionally with its first turn[User+Key]
GET/chats/modelsList supported models[User+Key]
PATCH/chats/:idUpdate the title[User+Key]
PATCH/chats/:id/accessSet private, org, or public access[User+Key]
DELETE/chats/:idDelete a chat[User+Key]
GET/chats/:id/todoGet persistent todo state[User+Key]
GET/chats/:id/messagesList messages[User+Key]
POST/chats/:id/messagesSend a message and wait for the response[User+Key]
POST/chats/:id/messages/streamSend a message over SSE[User+Key]
POST/chats/:id/stopStop the active stream[User+Key]
DELETE/chats/:id/messages/:messageIdDelete one message[User+Key]
GET/chats/:id/mcp-serversList available and enabled MCP servers[User+Key]
PATCH/chats/:id/mcp-serversSet enabled MCP servers[User+Key]
POST/chats/:id/terminateTerminate an agent session[User+Key]
POST/chats/improve-promptImprove a prompt[User+Key]
POST/chats/follow-up-questionsGenerate follow-up questions[User+Key]
POST/chats/fast-queryRun a quick grounded query[User+Key]
POST/chats/fast-raw-queryReturn raw retrieval chunks[User+Key]
POST/chats/raw-queryCompatibility alias for fast-raw-query[User+Key]

List chats

GET /chats
tenant_id
string
required
Tenant whose chats to list.
knowledge_base_id
string
Restrict results to one knowledge base. Required when the API key itself is knowledge-base-restricted.
external_subject_id
string
Restrict an API-key request to one external end user’s chats.
is_query
boolean
Filter query chats from regular chats.
curl "$AUTOSAGE_URL/chats?tenant_id=TENANT_ID&external_subject_id=CUSTOMER_123" \
  -H "Authorization: Bearer $AUTOSAGE_KEY"

Create a chat

POST /chats Creates an empty chat or, when message is present, creates the chat and processes its first turn.
id
string
required
Client-generated UUID for the chat.
tenant_id
string
required
Tenant that owns the chat.
knowledge_base_id
string
required
Knowledge base that grounds the conversation.
model
string
required
Supported model identifier. Use /chats/models to discover choices.
title
string
Optional title. Long titles are truncated to 255 characters.
message
string
Optional initial user message.
agent_mode
string
quick or deep. Defaults to deep.
websearch_enable
boolean
Enable web search for the initial turn.
external_subject_id
string
External end-user identifier for API-key-authenticated ownership, memory, and connected apps.
connector_slugs
string[]
Connected apps available to the turn.
skill_ids
string[]
Skills to load for this turn.
delegate_agent_ids
string[]
Agents available for delegation on this turn.
attached_artifact_ids
string[]
Up to 20 artifacts to add as context.
curl -X POST "$AUTOSAGE_URL/chats" \
  -H "Authorization: Bearer $AUTOSAGE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "CHAT_UUID",
    "tenant_id": "TENANT_ID",
    "knowledge_base_id": "KB_ID",
    "model": "MODEL_ID",
    "message": "What is our refund window?",
    "agent_mode": "quick",
    "external_subject_id": "CUSTOMER_123"
  }'
Keep the same external_subject_id on every operation for an API-served end user. AutoSage uses it as part of chat ownership and durable-memory isolation.
For an externally owned chat, API-key calls to owner-checked routes must pass external_subject_id in the query string unless the endpoint schema places it in the request body. This includes title or access changes, deletion, todo reads, message listing, stop, message deletion, MCP configuration, and session termination.
The schema also supports up to two base64 image data URLs and an optional shared-chat seed. Use /swagger for their exact shapes.

List supported models

GET /chats/models Returns supported model IDs and display metadata.

Update a title

PATCH /chats/:id
external_subject_id
string
External owner for API-key-authenticated chats.
title
string
New chat title.

Set access level

PATCH /chats/:id/access
external_subject_id
string
Required for an API-key call when the chat has an external owner.
access_level
string
required
One of private, org, or public.
Returns the updated access level and a share URL when the chat can be shared.
LevelRead access
privateThe owner only.
orgSigned-in members of the organization.
publicAnyone with the link.
Anyone with a public link can read the shared transcript. Share only content you are comfortable making public.

Delete a chat

DELETE /chats/:id Deletes the chat and its conversation data. API-key calls for external subjects should include external_subject_id in the query string.

Get todo state

GET /chats/:id/todo Pass external_subject_id in the query for an API-key call to an externally owned chat. Returns the current persistent todo list for the chat, or null when no todo state exists.

List messages

GET /chats/:id/messages
limit
number
Number of messages to return, from 1 to 200.
offset
number
Zero-based pagination offset.
external_subject_id
string
External owner for an API-key-authenticated chat.
Returns message records and chat metadata.

Send a message

POST /chats/:id/messages
content
string
required
User message, up to 32,000 characters.
model
string
required
Supported model identifier.
agent_mode
string
quick or deep. Defaults to deep.
websearch_enable
boolean
Enable web search for this turn.
external_subject_id
string
External owner for API-key authentication. It must resolve to the chat owner.
skill_ids
string[]
Skills to load for this turn.
delegate_agent_ids
string[]
Additional delegates for this turn.
connector_slugs
string[]
Connected apps available in Deep mode.
attached_artifact_ids
string[]
Artifacts to attach as context.
curl -X POST "$AUTOSAGE_URL/chats/CHAT_ID/messages" \
  -H "Authorization: Bearer $AUTOSAGE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "How do I start a return?",
    "model": "MODEL_ID",
    "agent_mode": "deep",
    "external_subject_id": "CUSTOMER_123"
  }'
The response contains user_message, assistant_message, and usage with token and credit information.

Stream a message

POST /chats/:id/messages/stream Accepts the same body as the non-streaming endpoint and returns text/event-stream.
curl -N -X POST "$AUTOSAGE_URL/chats/CHAT_ID/messages/stream" \
  -H "Authorization: Bearer $AUTOSAGE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Compare the return rules by product category.",
    "model": "MODEL_ID",
    "agent_mode": "deep"
  }'

SSE events

SSE data contains JSON. Heartbeats can also use the SSE event name ping.
typePurpose
pingTransport keep-alive.
user_messageConfirms that the user message was persisted.
agent_thoughtUser-facing progress from the agent.
data_previewA preview of document or data content.
todo_updateUpdated persistent todo tasks.
mcp_tool_callAn MCP tool invocation started.
mcp_tool_resultAn MCP tool invocation finished.
final_responseAnswer content and isComplete.
chartStructured chart configuration.
sourcesKnowledge-base citations.
tokensToken usage.
doneTerminal summary; the response has been persisted.
errorAn error message and recovery metadata.
Treat a final_response with isComplete: true as canonical complete answer content. If your client receives partial events, accumulate their content until completion. Finalize the UI on done and always handle error.

One active stream

Each chat supports one active stream. Starting another stream on the same chat replaces the current one. A client disconnect or explicit stop preserves partial output that has already been generated.

Stop a stream

POST /chats/:id/stop Pass external_subject_id in the query for an API-key call to an externally owned chat. Returns { "stopped": true } when an active stream was aborted, or false when no stream was active.

Delete one message

DELETE /chats/:id/messages/:messageId Pass external_subject_id in the query for an API-key call to an externally owned chat. Deletes a message only when it belongs to the chat in the path.

Configure MCP servers

GET /chats/:id/mcp-servers lists organization servers and annotates which are enabled for the chat. PATCH /chats/:id/mcp-servers replaces the enabled list: For either route, pass external_subject_id in the query for an API-key call to an externally owned chat.
{ "enabled_mcp_server_ids": ["MCP_SERVER_UUID"] }
AutoSage validates that every ID belongs to the chat’s organization. Up to 25 servers can be enabled.

Terminate a session

POST /chats/:id/terminate Ends an agent session while preserving its messages for audit. Later standalone agent-runtime calls using that chat return a conflict. The optional body accepts termination_reason up to 500 characters.

Prompt and follow-up utilities

Improve a prompt

POST /chats/improve-prompt accepts knowledge_base_id, query, and an optional supported category. It returns an improved prompt, analysis, and techniques applied. This operation uses credits.

Generate follow-up questions

POST /chats/follow-up-questions accepts knowledge_base_id and chat_id and returns suggestions based on the conversation. The chat must belong to that knowledge base.

Fast query utilities

Quick grounded answer

POST /chats/fast-query performs one knowledge-base retrieval pass and produces an answer. Its main fields are knowledge_base_id, content, model, optional chat_id, chunk_count (1–50), external_subject_id, websearch_enable, and connector_slugs.

Raw retrieval chunks

POST /chats/fast-raw-query returns grouped retrieval chunks without answer generation. POST /chats/raw-query is a compatibility alias. Prefer fast-raw-query for new integrations.
Use the interactive explorer at /swagger for complete utility schemas and response examples.

Next steps

Chat lifecycle

Understand persistence, compaction, stopping, and recovery.

Chat & streaming

Implement an SSE client.

Shared chats

Read shared transcripts safely.

Chat modes

Choose between Quick and Deep mode.