---
type: api
title: Send a message and get the answer
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-post-chat-message
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-post-chat-message
products:
  - Kibana
---

# Send a message and get the answer

Availability: Planned

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/chat/message`
- `POST` `/s/{space_id}/api/chat/message`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/authentication#basicauth)

## Description

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.

## Request Body

`application/json`

- `agent_id` (string · min: 1 · max: 64 · default: elastic-ai-agent) — optional
  The ID of the agent to send the message to. Defaults to the default Elastic AI agent.
- `conversation_id` (string · max: 256) — optional
  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 · min: 1 · max: 100000) — required
  The user message to send to the agent.

## Responses

#### `200`

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

`application/json`

- `answer` (string)
  The agent's final text answer. Empty when the agent finished without a message.
- `conversation_id` (string)
  The conversation the message was added to: the one requested, or the one created for it.
- `declined_prompts` ([] object · min: 1)
  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)
    The explanation the agent received in place of the prompt.
  - `tool_id` (string)
    The tool whose call was declined.
#### `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.

## Code Examples

#### Console

```console
POST kbn://api/chat/message
{
  "message": "What is Elasticsearch?",
  "agent_id": "elastic-ai-agent"
}
```

#### curl

```curl
curl \
  -X POST "${KIBANA_URL}/api/chat/message" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "What is Elasticsearch?",
    "agent_id": "elastic-ai-agent"
  }'
```

## Response Examples

#### Message declined prompt response

The agent tried to call a tool that requires user confirmation. There is no user to ask on this endpoint, so the call was declined and the agent answered with what it could

```json
{
  "answer": "I could not run the reindex because it requires confirmation, which is not available here. You can run it from a conversation in Kibana instead.",
  "conversation_id": "696ccd6d-4bff-4b26-a62e-522ccf2dcd16",
  "declined_prompts": [
    {
      "message": "Agent running in non-interactive mode, user input not available - execution was declined",
      "tool_id": "reindex-logs"
    }
  ]
}
```

#### Message response

The agent's answer and the ID of the conversation it was stored in. `declined_prompts` is absent because the agent asked for nothing.

```json
{
  "answer": "Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine\u2011tuned relevancy, and powerful analytics that scale with ease.",
  "conversation_id": "696ccd6d-4bff-4b26-a62e-522ccf2dcd16"
}
```

#### Message empty

The `message` is empty

```json
{
  "error": "Bad Request",
  "message": "[request body.message]: value has length [0] but it must have a minimum length of [1].",
  "statusCode": 400
}
```

#### Message unexpected key

The body carries a key this endpoint does not accept

```json
{
  "error": "Bad Request",
  "message": "[request body.connector_id]: Additional properties are not allowed (\u0027connector_id\u0027 was unexpected)",
  "statusCode": 400
}
```

#### Message not found

The `conversation_id` is unknown, or the `agent_id` is unknown or not usable by the caller

```json
{
  "attributes": {
    "trace_id": "8d4f2a3b-1c5e-4a9b-9f0d-2e6c1a3d4f5e"
  },
  "error": "Not Found",
  "message": "Conversation 696ccd6d-4bff-4b26-a62e-522ccf2dcd16 not found",
  "statusCode": 404
}
```

