---
type: api
title: Generate a chat completion
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-observability-ai-assistant-chat-complete
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-observability-ai-assistant-chat-complete
products:
  - Kibana
---

# Generate a chat completion

Availability:

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

## Paths

- `POST` `/api/observability_ai_assistant/chat/complete`
- `POST` `/s/{space_id}/api/observability_ai_assistant/chat/complete`

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

## Description

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

Create a new chat completion by using the Observability AI Assistant.

The API returns the model's response based on the current conversation context.

It also handles any tool requests within the conversation, which may trigger multiple calls to the underlying large language model (LLM).

This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.

## Request Body

`application/json`

- `actions` ([] object) — optional
  - `description` (string) — optional
    The description of the function.
  - `name` (string) — optional
    The name of the function.
  - `parameters` (object) — optional
    The parameters of the function.
- `connectorId` (string) — required
  A unique identifier for the connector.
- `conversationId` (string) — optional
  A unique identifier for the conversation if you are continuing an existing conversation.
- `disableFunctions` (boolean) — optional
  Flag indicating whether all function calls should be disabled for the conversation. If true, no calls to functions will be made.
- `instructions` ([] union) — optional
  An array of instruction objects, which can be either simple strings or detailed objects.
  - **string**
    A simple instruction represented as a string.
  - **{ id, text }**
    A detailed instruction with an ID and text.
    - `id` (string) — required
      A unique identifier for the instruction.
    - `text` (string) — required
      The text of the instruction.
- `messages` ([] object) — required
  An array of message objects containing the conversation history.
  - `@timestamp` (string) — required
    The timestamp when the message was created.
  - `message` (object) — required
    The main content of the message.
    - `content` (string) — optional
      The content of the message.
    - `data` (string) — optional
      Additional data associated with the message.
    - `event` (string) — optional
      The event related to the message.
    - `function_call` ({}) — optional
      Details of the function call within the message.
      - `arguments` (string) — optional
        The arguments for the function call.
      - `name` (string) — required
        The name of the function.
      - `trigger` (enum) — required
        The trigger of the function call.
        Values: `assistant`, `user`, `elastic`
    - `name` (string) — optional
      The name associated with the message.
    - `role` (enum) — required
      The role of the message sender.
      Values: `system`, `assistant`, `function`, `user`, `elastic`
- `persist` (boolean) — required
  Indicates whether the conversation should be saved to storage. If true, the conversation will be saved and will be available in Kibana.
- `title` (string) — optional
  A title for the conversation.

## Response

Successful response

`application/json`

Type: `object`

## Code Examples

#### curl

```curl
curl --request POST 'localhost:5601/api/observability_ai_assistant/chat/complete' -u <username>:<password> -H 'kbn-xsrf: true' -H "Content-Type: application/json" --data '
{
"connectorId": "<connectorId>",
"disableFunctions": false,
  "messages": [
    {
      "@timestamp": "2025-06-25T23:45:00.000Z",
      "message": {
        "role": "user",
        "content": "Is my Elasticsearch cluster healthy right now?"
      }
    }
  ],
"persist": false,
"actions": [
  {
    "name": "get_cluster_health",
    "description": "Fetch the current Elasticsearch cluster-health status and key metrics.",
    "parameters": {
      "type": "object",
      "properties": {
        "includeShardStats": {
          "type": "boolean",
          "default": false
        }
      }
    }
  }
],
"instructions": ["When the user asks about Elasticsearch cluster health, use the get_cluster_health tool to retrieve cluster health, then summarize the response in plain English."]
}'
```

## Response Examples

#### Get a chat completion from the Observability AI Assistant

```json
data: {"model":"unknown","choices":[{"delta":{"content":"","function_call":{"name":"get_cluster_health","arguments":"{\"includeShardStats\":true}"}},"finish_reason":null,"index":0}],"created":1750936626911,"id":"9c8eff9b-4fd4-4203-a4ab-2e364688deff","object":"chat.completion.chunk"}

data: [DONE]
```

