---
title: "Send a message and get the answer"
method: POST
path: "/api/chat/message"
tags: ["agent builder"]
---

# Send a message and get the answer

`POST /api/chat/message`

## Request

- Base URL: `https://localhost:5601`
- URL: `https://localhost:5601/api/chat/message`
- Auth: one of:
  - API key in header `Authorization`
  - HTTP basic

**Spaces method and path for this operation:**

<div><span class="operation-verb post">post</span>&nbsp;<span class="operation-path">/s/{space_id}/api/chat/message</span></div>

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Send a message to an agent and get its text answer. Use this synchronous endpoint in scripts and command-line tools. The response contains only the answer and the conversation ID. To continue the conversation, include the returned `conversation_id` in the next request.

The agent runs without a user, so the endpoint declines every prompt that the agent raises, such as a tool confirmation, a question, or a destructive API approval. The `declined_prompts` property lists these prompts. This endpoint does not support attachments.

The `agentBuilder:experimentalFeatures` advanced setting must be enabled. If it is disabled, the endpoint returns a 404 response.<br/><br/>[Required authorization] Route required privileges: agentBuilder:read.

## Headers

- `kbn-xsrf` string, required

## Request body

- object
  - `agent_id` string: The ID of the agent to send the message to. Defaults to the default Elastic AI agent.
  - `conversation_id` string: The ID of an existing conversation to continue. Omit it to start a new conversation; the response carries the ID to reuse on the next call.
  - `message` string, required: The user message to send to the agent.

## Response `200`

The agent answered. The response contains the answer and the ID of the conversation that stores the exchange.

- object
  - `answer` string, required: The agent's final text answer. Empty when the agent finished without a message.
  - `conversation_id` string, required: The conversation the message was added to: the one requested, or the one created for it.
  - `declined_prompts` object[]: The prompts that the endpoint declined. In an interactive conversation, these prompts pause the agent until the user answers. Examples are tool confirmations, questions to the user, and destructive API approvals. This endpoint has no user, so it declines each prompt and tells the agent why. The property is absent if the agent raised no prompts.
    - `message` string, required: The explanation the agent received in place of the prompt.
    - `tool_id` string, required: The tool whose call was declined.

## Other responses

- `400`: Bad Request: the request body is not valid. Possible causes are an empty or too long `message`, a `conversation_id` that is not a UUID, or an unsupported property such as `connector_id` or `attachments`.
- `404`: Not Found: the conversation or agent was not found. Possible causes are a `conversation_id` that does not exist, an `agent_id` that the caller cannot use, or a disabled `agentBuilder:experimentalFeatures` advanced setting. If the caller cannot use the agent, the error says that the conversation was not found. This prevents callers from discovering hidden agents.

---

[API](https://skmtc.dev/elastic/apis/kibana-apis.md) - [All operations](https://skmtc.dev/elastic/apis/kibana-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/elastic/apis/kibana-apis/revisions/514417f60094?raw)
