Docs menu

Send agent message

POST /v1/organisations/{organisation_id}/spaces/{space_id}/conversations/{conversation_id}/messages

Sends a message and streams the assistant's reply as server-sent events. Each event's name is event and its data is the JSON of data in AgentStreamEvent; its id is the position in the run's event log. The stream ends after done or error. The reply is written by a background run (named by the Ivy-Run-Id header) that keeps going if the connection drops: resume with GET …/runs/{run_id}/events and Last-Event-ID. While the assistant is still answering an earlier message, the message joins the chat's queue instead (202, as queueAgentMessage) and starts once the chat is free.

Authentication

Send an API key, or an access token from your organisation’s identity provider, in the Authorization header. How API keys work

Scope the API key needs: conversations:write

Security schemes in the OpenAPI document: session_cookie (cookie __Host-ivy_session)bearer (bearer)api_key (bearer)

Parameters

  • organisation_id path string required
  • space_id path string required
  • conversation_id path string required
  • Last-Event-ID header string | null

    With a repeated client_message_id: resume after this event

Request body

application/json SendMessage required

  • agent_id string | null

    A WorkspaceAgent.id. The first message of a chat chooses its agent (the built-in assistant when absent); later messages may repeat it or leave it out.

  • attachments string[]

    Up to 10 ids of files in the chat's space for the assistant to read.

  • client_message_id string | null

    A client-generated id (1-128 of A-Z a-z 0-9 _ -). Sending the same id again does not post the message twice: the response follows the run the first request started, resuming after Last-Event-ID.

  • context MessageContext | null
  • interface_locale Locale | null
  • model string | null

    One of the ids from GET /v1/agent/models, or of the chat's agent's models; the default model when absent.

  • quote QuoteInput | null
  • text string required

Responses

  • 200 text/event-stream AgentStreamEvent

    Server-sent events

    Response headers: Ivy-Run-Id

  • 201 application/json ChatMessage

    Posted without a reply, while conversations with people are on: no agent answers it (§3.4: in a group or a shared thread, agents answer only when @mentioned)

  • 202 application/json QueuedMessage

    Queued while the assistant answers an earlier message; Ivy-Run-Id is set when it started at once because the chat had just become free

    Response headers: Ivy-Run-Id

  • 401 application/json ErrorBody

    unauthenticated

  • 402 application/json ErrorBody

    usage_limit_reached: the organisation used its AI credit allowance and spending limit for this period (details: scope_type, period_end, can_raise_limit); billing_restricted: its subscription is unpaid. A run can also end with an error event of either code.

  • 403 application/json ErrorBody

    workspace_content_restricted, invalid_origin, insufficient_scope (also when an API key mentions a person); not_a_participant; not_a_channel_member: the caller reads this open channel but hasn't joined it, and only members post (join with addChannelMembers), unless they take part in this thread already

  • 404 application/json ErrorBody

    No such chat of the caller's in this space

  • 409 application/json ErrorBody

    invite_required when the message mentions someone who isn't in this private conversation (details.participants: invite them, then send again); workspace_archived; queue_full when the assistant is answering and 20 messages already wait; queue_full_for_person when the caller already queued 10 here; run_in_progress when a retried client_message_id meets another answer in progress; chat_busy when the message couldn't be stored because the chat kept changing (send it again)

  • 422 application/json ErrorBody

    validation_failed (reason not_quotable for a quote that isn't a message of this conversation still in it); not_a_workspace_member or agent_not_enabled for a mention; invalid_model when model is not one of listAgentModels (or of the chat's agent's models), such as a regular variant while the organisation has EU-only processing on; invalid_attachment when an id in attachments is not a file of this space or failed its malware scan; invalid_agent when agent_id is not one of listSpaceAgents or differs from the chat's agent; agent_unavailable (with details.reason) when the agent can't run here yet

  • 429 application/json ErrorBody

    rate_limited: the API key's requests per minute are used up; retry after Retry-After seconds

  • 503 application/json ErrorBody

    agent_unavailable when no assistant worker is running or configured; or unavailable: the database is briefly unavailable; retry after Retry-After seconds

Server-sent events

The response is a text/event-stream. Each event is named after one of these, and its data is the JSON of the schema shown.

To resume after a dropped connection, send the id of the last event you received as the Last-Event-ID header.

  • message_start AgentMessageStart

    Data of the message_start SSE event.

  • text_delta AgentTextDelta

    Data of the text_delta SSE event.

  • Data of the thinking SSE event: the summarized progress note so far, replacing the one before it.

  • tool_call AgentToolCall

    Data of the tool_call SSE event.

  • tool_result AgentToolResult

    Data of the tool_result SSE event.

  • tool_progress AgentToolProgress

    Live output of a running tool: a bash command's output, or an event of the code run that run_code started (event is then the run's event name: stdout, stderr, output_file, …).

  • sandbox_status AgentSandboxStatus

    The conversation's sandbox. reason says why it stopped or is unavailable; a new one is started (with a fresh working copy) the next time the assistant needs a shell.

  • app_status AppInstance

    One running copy of an app: in the sandbox session of a conversation, or the space's own.

  • changes_saved AgentChangesSaved

    Files the sandbox created or changed, saved as new versions after a step.

  • changes_pending AgentChangesPending

    Deletes and conflicting overwrites the sandbox made, held until the person confirms them (…/sandbox/changes/{change_set_id}/apply or /discard).

  • Data of the done SSE event.

  • Data of the error SSE event. The stream ends after it.

Example stream
id: 1
event: message_start
data: {"message_id":"message_123","model":"string"}

id: 2
event: text_delta
data: {"text":"Hello, Ivy"}

id: 3
event: thinking
data: {"text":"Hello, Ivy"}

id: 4
event: tool_call
data: {"id":"id_123","input":{},"name":"Ada Lovelace"}

id: 5
event: tool_result
data: {"files":[{"file_id":"file_123","name":"Ada Lovelace","path":"string","space_id":"space_123","version":1,"workspace_id":"workspace_123"}],"id":"id_123","invalidates":["workspaces"],"sources":[{"title":"string","url":"https://example.com"}],"status":"ok","summary":"string","view":{"app_id":"app_123","instance_id":"instance_123","kind":"page","result":{},"source_space_id":"source_space_123","source_workspace_id":"source_workspace_123","ui":"string","version_id":"version_123"}}

id: 6
event: tool_progress
data: {"data":{},"event":"string","tool_use_id":"tool_use_123"}

id: 7
event: sandbox_status
data: {"reason":"string","state":"starting"}

id: 8
event: app_status
data: {"access":"read","app_id":"app_123","conversation_id":"conversation_123","frontend":"builtin","id":"id_123","last_active_at":"2026-01-15T09:30:00Z","name":{"de":"string","el":"string","en":"string","es":"string","fr":"string","hu":"string","it":"string"},"owner":"session","reason":"string","snapshot_hash":"string","started_at":"2026-01-15T09:30:00Z","state":"starting","status":{"dropped":["string"],"processes":[{"busy":"string","error":"string","exit_code":1,"id":"id_123","ports":[],"progress":1,"restarts":0,"state":{},"text":"Hello, Ivy"}],"skipped":["string"]},"stopped_at":"2026-01-15T09:30:00Z"}

id: 9
event: changes_saved
data: {"checkpoint":0,"files":[{"change":"created","check":{"file_id":"file_123","kind":{},"path_changes":[],"problems":[],"reference":{},"valid":false,"version_id":"version_123"},"file_id":"file_123","path":"string","version_id":"version_123"}],"skipped":["string"]}

id: 10
event: changes_pending
data: {"change_set_id":"change_set_123","conflicts":[{"base_version_id":"base_version_123","current_version_id":"current_version_123","file_id":"file_123","path":"string"}],"deletes":[{"file_id":"file_123","path":"string"}]}

id: 11
event: done
data: {"message":{"acting_for":{"id":"id_123","type":{}},"ask_id":"ask_123","attachments":[{"file_id":"file_123","name":"Ada Lovelace"}],"author":{"id":"id_123","type":{}},"author_name":"Ada Lovelace","branch":{"count":0,"index":0},"created_at":"2026-01-15T09:30:00Z","deleted_at":"2026-01-15T09:30:00Z","edited_at":"2026-01-15T09:30:00Z","feedback":"up","file_links":[{"file_id":"file_123","name":"Ada Lovelace","path":"string","space_id":"space_123","version":1,"workspace_id":"workspace_123"}],"id":"id_123","in_reply_to":"string","mentions":["string"],"model":"string","notice":{"actor":{},"channel_id":"channel_123","conversation_id":"conversation_123","kind":{},"participants":[],"title":"string"},"origin":{"platform_message_id":"platform_message_123","source":{}},"parts":[{"text":"Hello, Ivy","type":"text"}],"quote":{"author":{},"author_name":"Ada Lovelace","created_at":"2026-01-15T09:30:00Z","deleted":false,"excerpt":"string","message_id":"message_123"},"reactions":[{"emoji":"string","participants":[]}],"read_through":"string","role":"user","stopped_by":{"id":"id_123","type":{}},"thinking":[{"before_part":0,"duration_ms":0,"text":"Hello, Ivy"}]}}

id: 12
event: error
data: {"code":"not_found","message":"A short explanation for people"}

Error codes

Errors come back as an ErrorBody whose code is one of these.

  • 401 unauthenticated
  • 402 usage_limit_reachedperiod_endcan_raise_limitbilling_restricted
  • 403 workspace_content_restrictedinvalid_origininsufficient_scopenot_a_participantnot_a_channel_member
  • 404 not_found generic code for this status
  • 409 invite_requiredworkspace_archivedqueue_fullqueue_full_for_personrun_in_progresschat_busy
  • 422 validation_failednot_a_workspace_memberagent_not_enabledinvalid_modelinvalid_attachmentinvalid_agentagent_unavailable
  • 429 rate_limited
  • 503 agent_unavailableunavailable

Examples

curl
curl -X POST -N "$IVY_API_URL/v1/organisations/$ORGANISATION_ID/spaces/$SPACE_ID/conversations/$CONVERSATION_ID/messages" \
  -H "Authorization: Bearer $IVY_API_KEY" \
  -H "Accept: text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{"text":"Hello, Ivy"}'
JavaScript SDK
import { client, streamAgentMessage } from "@spacivapp/ivy-sdk";

client.setConfig({
  baseUrl: process.env.IVY_API_URL,
  headers: { Authorization: `Bearer ${process.env.IVY_API_KEY}` },
});

for await (const event of streamAgentMessage({
  organisationId,
  spaceId,
  conversationId,
  body: {
    text: "Hello, Ivy"
  },
})) {
  if (event.event === "text_delta") process.stdout.write(event.data.text);
}
Example request body
{
  "agent_id": "agent_123",
  "attachments": [
    "string"
  ],
  "client_message_id": "client_message_123",
  "context": {
    "organisation_id": "organisation_123",
    "user_id": "user_123"
  },
  "interface_locale": "en",
  "model": "string",
  "quote": {
    "message_id": "message_123"
  },
  "text": "Hello, Ivy"
}