Conversations
Store chat history on the server: create a conversation, append each turn, list and count the shelves, search your own messages, and archive.
A conversation is chat history the gateway stores for you, so a thread can be reopened on another device. You store each turn yourself: send it to Chat, then append the user message and the reply. Conversations are private to their author. No other member of the organization, an owner or admin included, can read, list, or search one.
Create a conversation and append a turn
POST /api/v1/conversations creates a conversation. Every field is optional:
title and model are presentation only, vault_id holds it inside a vault
you can write to, and source is chat (the default) or cli for a Cruxy
Code session. POST /api/v1/conversations/{id}/messages appends one message
with a role of system, user, assistant, or tool, and its content.
# 1. Create the conversation and keep its id.
CONVERSATION_ID=$(curl -s https://api.cruxy.ai/api/v1/conversations \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}' | sed -E 's/.*"id":"([^"]+)".*/\1/')
# 2. Append the user's message. The first user message titles the conversation.
curl https://api.cruxy.ai/api/v1/conversations/$CONVERSATION_ID/messages \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{ "role": "user", "content": "Why is this query doing a seq scan?" }'
# 3. Append the reply you got from chat, with what you know about it.
curl https://api.cruxy.ai/api/v1/conversations/$CONVERSATION_ID/messages \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"role": "assistant",
"content": "The planner chose a seq scan because the estimate is low.",
"status": "complete",
"routed_tier": "saga",
"routing_mode": "explicit",
"reply_ms": 14200,
"input_tokens": 48210
}'const base = 'https://api.cruxy.ai/api/v1'
const headers = {
Authorization: `Bearer ${process.env.CRUXY_API_KEY}`,
'Content-Type': 'application/json',
}
async function post(path: string, body: unknown, idempotencyKey?: string) {
const res = await fetch(`${base}${path}`, {
method: 'POST',
headers: idempotencyKey ? { ...headers, 'Idempotency-Key': idempotencyKey } : headers,
body: JSON.stringify(body),
})
if (!res.ok) throw new Error(`${path} failed: ${res.status} ${await res.text()}`)
return res.json()
}
// 1. Create the conversation.
const conversation = await post('/conversations', {})
// 2. Append the user's message. The first user message titles the conversation.
const question = 'Why is this query doing a seq scan?'
await post(
`/conversations/${conversation.id}/messages`,
{ role: 'user', content: question },
crypto.randomUUID(),
)
// 3. Ask chat, timing the reply.
const sentAt = Date.now()
const completion = await post('/chat', {
model: 'saga',
stream: false,
messages: [{ role: 'user', content: question }],
})
// 4. Append the reply, with what the response says about it.
const stored = await post(
`/conversations/${conversation.id}/messages`,
{
role: 'assistant',
content: completion.message.content,
status: completion.finish_reason === 'length' ? 'incomplete' : 'complete',
...(completion.finish_reason === 'length' && { incomplete_reason: 'length' }),
routed_tier: completion.cruxy.routed_tier,
routing_mode: 'explicit', // 'auto' when you send model: 'auto'
reply_ms: Date.now() - sentAt,
input_tokens: completion.usage.input_tokens,
},
crypto.randomUUID(),
)
console.log(stored.message.id, stored.conversation.title)The 201 carries the stored message, the conversation as it now stands,
and leaf_moved. The gateway assigns each message's sequence, so concurrent
appends cannot collide or reorder the transcript. An append moves the
conversation's updated_at and its retention_until, the deadline after which
the conversation and its messages are deleted: 365 days from last activity by
default.
Send an Idempotency-Key header with every append. A retry with the same key
and body replays the stored 201 instead of writing the turn twice, and the
same key with a different body is 409 idempotency_conflict; see
Errors and retries.
content is required, except on an assistant message that carries
tool_calls, and holds at most 1,048,576 bytes of UTF-8; longer is 400
invalid_request. An agentic turn must carry its tool fields: tool_calls on
the assistant message that requested them, and tool_call_id on each tool
result. A user message can attach up to 20 files in file_ids, on a request
that pins Cruxy-Version: 2026-10-06 or later.
Record what a reply did
An append can store facts about the reply beside its text, so a client can show them again when the conversation is reopened. All are optional, each is written once, and a read omits the ones that were never stored.
| Field | On | Meaning |
|---|---|---|
status | Any message | complete (the default), incomplete when the answer is not whole, or cancelled when a person stopped it. A reply that ended with finish_reason: "length" is incomplete even though its stream closed cleanly. |
incomplete_reason | An incomplete message | Why the answer is not whole: length, content_filter, error (the stream ended in an error), or connection (the stream ended with no finish at all). Any other value, or a reason on a message that is not incomplete, is 400 invalid_request. |
routed_tier | Assistant messages | The tier that answered, as the chat response named it in cruxy.routed_tier: canto, saga, or epos. auto is 400 invalid_request. |
routing_mode | Assistant messages | How the tier was chosen: explicit when you named a tier, auto when you sent model: "auto", or auto_degraded, which the native wire reports in routing.mode. |
reply_ms | Assistant messages | How long the reply took by your measure, from sending the chat request to its last token, in whole milliseconds from 0 to 86,400,000. |
input_tokens | Assistant messages | The chat response's usage.input_tokens for the request that produced the message, from 0 to 16,777,216. On a turn that called tools, send that one request's count, never a sum. Billing never reads it. |
activity | Assistant messages | A JSON object of your own shape recording what the turn did, at most 65,536 bytes of compact JSON. The gateway stores and returns it as sent, never reads inside it, and never sends it to a model. |
On a read, treat incomplete_reason and routing_mode as open lists: show a
value you do not know as you would an absent one. To show how full the context
window is, divide the newest reply's input_tokens by the context_window
that GET /api/v1/limits reports for its tier.
Titles
Every conversation carries title and title_source, which says who wrote
the title:
title_source | Meaning |
|---|---|
auto | Derived from the first user message, in the same append: its first line, truncated to 80 characters on a word boundary. |
generated | Written by the gateway a few seconds after the first reply, replacing an auto title with one of 2 to 6 words. This happens for a chat conversation written through a first-party login. |
user | Set at create or with PATCH /api/v1/conversations/{id}. It is never replaced. |
null | The conversation is untitled, or was titled before the field existed. |
A client that drew an auto title reads the conversation again shortly after
a reply to pick up a generated one. PATCH /api/v1/conversations/{id} changes
title, model, or both; an explicit null clears a field, and an empty
patch is 400 invalid_request.
List and count
GET /api/v1/conversations lists your own conversations, most recently active
first, without their messages. Page with limit (default 50, at most 100) and
the cursor from the previous page's next_cursor, which is null on the
last page. Three filters narrow it: vault_id, archived (false, the
default, lists live conversations; true lists the archived shelf), and
source (chat, the default, cli, or agent).
GET /api/v1/conversations/counts counts both shelves in one read: live is
how many conversations the listing pages through with archived=false, and
archived how many with archived=true. It applies the listing's own
visibility and its vault_id and source filters, so a count never includes
a conversation the list cannot return. It takes no archived parameter.
curl https://api.cruxy.ai/api/v1/conversations/counts \
-H "Authorization: Bearer $CRUXY_API_KEY"const res = await fetch('https://api.cruxy.ai/api/v1/conversations/counts', {
headers: { Authorization: `Bearer ${process.env.CRUXY_API_KEY}` },
})
if (!res.ok) throw new Error(`counts request failed: ${res.status}`)
const counts = await res.json()
console.log(`${counts.live} live, ${counts.archived} archived (${counts.source})`){ "object": "conversation_counts", "source": "chat", "live": 42, "archived": 7 }Read a conversation
GET /api/v1/conversations/{id} returns the conversation and a page of its
messages under messages. Page with message_limit (default 100, at most
200) and the message_cursor from messages.next_cursor. message_order is
asc (the default, oldest first) or desc, which returns the newest messages
first; a cursor works only with the order it was issued for.
A conversation can branch: an append that names a parent_id answers that
message instead of the newest one, which is how an edit or a regeneration is
stored. A read returns one path through the tree, the active branch on a first
page, and each message lists its sibling_ids.
POST /api/v1/conversations/{id}/switch with a message_id moves the
conversation onto the branch through that message for every device, and
returns the branch's leaf_id. To read another branch without switching to
it, pass message_branch on the read.
Search your messages
GET /api/v1/conversations/search runs a full-text search over your own
messages, most relevant first. It sees exactly what the listing sees, so it
never matches another person's message. Archived conversations are searched
too, and so is every branch of a branched conversation.
curl -G https://api.cruxy.ai/api/v1/conversations/search \
-H "Authorization: Bearer $CRUXY_API_KEY" \
--data-urlencode 'q="seq scan" -vacuum' \
--data-urlencode 'limit=10'const params = new URLSearchParams({ q: '"seq scan" -vacuum', limit: '10' })
const res = await fetch(`https://api.cruxy.ai/api/v1/conversations/search?${params}`, {
headers: { Authorization: `Bearer ${process.env.CRUXY_API_KEY}` },
})
if (!res.ok) throw new Error(`search failed: ${res.status}`)
const escapeHtml = (s: string) =>
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
const { data } = await res.json()
for (const hit of data) {
// Escape the whole snippet first, then turn the markers into markup.
const html = escapeHtml(hit.snippet)
.replaceAll('[[hl]]', '<mark>')
.replaceAll('[[/hl]]', '</mark>')
console.log(hit.conversation_id, hit.message_id, hit.on_active_path, html)
}q is required and takes web-search syntax: quoted phrases, or, and a
leading - to exclude a term. No input is a syntax error. limit defaults to
20, at most 50, and source filters as it does on the listing.
Each hit carries conversation_id, conversation_title, message_id,
role, sequence, status, created_at, rank, on_active_path, and a
snippet.
on_active_path is false for a hit on a branch that is not the active one.
To open it, send its message_id to
POST /api/v1/conversations/{id}/switch.
Archive, restore, and delete
PUT /api/v1/conversations/{id}/archivearchives a conversation: it leaves the default listing and appears only witharchived=true. Nothing is deleted, and archived conversations are still searched. Archiving does not extend the retention deadline.DELETE /api/v1/conversations/{id}/archiverestores it to the default listing.DELETE /api/v1/conversations/{id}deletes the conversation and every message in it, immediately and irreversibly. Files its messages attached as chat attachments are deleted with it, unless a message in another conversation still attaches them.
Both archive calls are idempotent and answer 204.
Append a run of messages
POST /api/v1/conversations/{id}/messages/batch appends up to 100 messages in
one transaction: either every message is stored or none is. It is built for
copying in a transcript you already have. Each message is validated as a
single append validates one, every message after the first answers the one
before it, and file_ids is not accepted. The body may be at most 1 MiB;
send a longer transcript as several batches. Send an Idempotency-Key here
too.
Errors
| Status | code | When |
|---|---|---|
400 | invalid_request | A field is malformed, out of range, or set on a role that cannot carry it. |
403 | conversation_forbidden | A write to a conversation held in a vault you may read but not write. |
404 | conversation_not_found | The id is not a conversation of yours. Another member's conversation reads the same as one that never existed. |
404 | message_not_found | A message_id or message_branch that is not a message of this conversation. |
409 | idempotency_conflict | An Idempotency-Key reused with a different body. |
413 | payload_too_large | The request body is over the route's limit. Nothing is stored. |
See Errors and retries for the envelope and what to retry.
Next steps
- Chat: send the turn whose messages you store here.
- Streaming: read a reply's
finish_reason, the source ofstatusandincomplete_reason. - Rate limits and budgets: the
context_windowthatinput_tokensis measured against. - API Reference: every conversation operation with its exact request and response shape.