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
  }'

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.

FieldOnMeaning
statusAny messagecomplete (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_reasonAn incomplete messageWhy 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_tierAssistant messagesThe tier that answered, as the chat response named it in cruxy.routed_tier: canto, saga, or epos. auto is 400 invalid_request.
routing_modeAssistant messagesHow 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_msAssistant messagesHow 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_tokensAssistant messagesThe 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.
activityAssistant messagesA 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_sourceMeaning
autoDerived from the first user message, in the same append: its first line, truncated to 80 characters on a word boundary.
generatedWritten 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.
userSet at create or with PATCH /api/v1/conversations/{id}. It is never replaced.
nullThe 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"
{ "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'

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}/archive archives a conversation: it leaves the default listing and appears only with archived=true. Nothing is deleted, and archived conversations are still searched. Archiving does not extend the retention deadline.
  • DELETE /api/v1/conversations/{id}/archive restores 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

StatuscodeWhen
400invalid_requestA field is malformed, out of range, or set on a role that cannot carry it.
403conversation_forbiddenA write to a conversation held in a vault you may read but not write.
404conversation_not_foundThe id is not a conversation of yours. Another member's conversation reads the same as one that never existed.
404message_not_foundA message_id or message_branch that is not a message of this conversation.
409idempotency_conflictAn Idempotency-Key reused with a different body.
413payload_too_largeThe 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 of status and incomplete_reason.
  • Rate limits and budgets: the context_window that input_tokens is measured against.
  • API Reference: every conversation operation with its exact request and response shape.

Was this page helpful?