Relay docs

Conversations

Conversations are persisted multi-turn threads for agents. They give an agent memory across calls without your app having to resend the whole history.

#How it works

Call an agent with a thread query parameter:

POST /v1/agents/{id}/chat/completions?thread=my-thread-123

On each call Relay:

  1. Loads the thread's prior messages and prepends them to the conversation.
  2. Runs the agent normally (prompt, skills, tools, RAG all apply).
  3. Persists this turn (your user message + the assistant reply) back to the thread — only when the call succeeds.

The response carries X-Relay-Thread-Id. Pass any id of your choice; the thread is created on first use. The thread id also becomes the trace's session id (unless you sent X-Relay-Session-Id yourself), so a conversation appears as one session on the Sessions page.

What's persisted is only the user-authored turns plus assistant replies, as role and content — the agent's prompt seed turns (from a chat prompt) are re-applied each call and never stored, so they don't accumulate. An agent with Working loop on also keeps its tool work.

#Images in a thread

A thread remembers the images sent to it, so a later question can refer to a picture from an earlier one. It stores each image as a reference to an uploaded file, { "type": "image_file", "file_id": "…" }, never the image itself. An image named in file_ids is referenced by its id; one sent inline as a data: URL is first stored as an image file of its own (owned like an upload: the key's workspace, and the X-Relay-User-Id user when sent), and an https:// image is kept as its link.

Every turn re-sends the history, so the images are bounded. The five most recent images, counting the ones in the current turn, go to the model as images; older ones go as a one-line note naming the file, such as "[image shelf_3.jpg]". Naming an older image again in file_ids brings it back among the five. For a model without vision every image goes as that note, so a thread with pictures can still continue on such a model. An image whose file has expired, been deleted or belongs to another user goes as "[image no longer available]". Images stay with the conversation: every time a thread is saved, the image files it references are kept for another Gateway:Threads:ImageDays days (90 by default; 0 keeps them until the file is deleted), so a thread in use never loses its pictures. An image uploaded but never used in a thread keeps the ordinary attachment lifetime (24 hours by default). Deleting a thread leaves its image files in place: delete those with DELETE /v1/files/{id}.

A threaded call streams when you send stream: true, unless the agent runs a tool loop (MCP servers, workflows, a connector or a dataset), which answers with one JSON response. The thread's history is prepended exactly as on a non-streamed call, X-Relay-Thread-Id arrives with the response headers, and the gateway assembles the reply from the stream and saves the turn once the stream has ended with [DONE]. A stream that fails or that the caller cancels saves nothing. An agent with Working loop on streams its own way and saves its tool work too; see Agents API.

#Managing threads

The panel's Conversations page lists persisted threads and lets you open one (assistant turns render as Markdown) or delete it. The control-plane api/Conversations supports search, GET {id}, save/upsert, and delete.

An app can delete threads through the gateway with the chat.completions scope: DELETE /v1/threads/{id} for one thread (204, or 404 when there is nothing to delete), and DELETE /v1/threads?prefix= for every thread of the key's workspace whose id starts with a prefix of at least 16 characters (answers { "deleted": n }). Deletes are soft, and a later call that names a deleted thread's id starts it over, empty. See Agents API.

#Playground

The Playground can also save an ad-hoc chat to Conversations (a toggle in its settings drawer), so exploratory sessions can be kept for reference.

#When to use threads

Use a thread when the interaction is genuinely conversational (support chat, an assistant that refers back to earlier turns). For stateless one-shot calls, skip thread= and just send the messages you need — it's cheaper and simpler.