ObservabilityAiAssistantClient

Client for the Kibana Observability AI Assistant API.

The Observability AI Assistant chat completion API generates responses from a large language model (LLM) based on the current conversation context. It also handles any tool (function) requests within the conversation, which may trigger multiple calls to the underlying LLM.

Note

The API is marked as technical preview in Kibana 9.4 and may change or be removed in a future release.

The API requires a preconfigured AI (LLM) connector (for example an OpenAI, Azure OpenAI or Amazon Bedrock connector) identified by connector_id. Conversations are space-scoped: every method accepts an optional space_id to target a specific space.

class kibana._sync.client.observability_ai_assistant.ObservabilityAiAssistantClient(client, default_space_id=None, validate_spaces=True)[source]

Bases: NamespaceClient

Client for the Kibana Observability AI Assistant API.

The Observability AI Assistant chat completion API generates responses from a large language model (LLM) based on the current conversation context. It also handles any tool (function) requests within the conversation, which may trigger multiple calls to the underlying LLM.

The API is marked as Technical Preview in Kibana 9.4 and may change or be removed in a future release.

The API requires a preconfigured AI (LLM) connector (for example an OpenAI, Azure OpenAI or Amazon Bedrock connector) identified by connector_id. Conversations are space-scoped: every method accepts an optional space_id to target a specific space (None targets the default space or the space the client is scoped to).

Note

On success (HTTP 200) Kibana streams the model output as server-sent events (data: {...} chunks terminated by data: [DONE]) with content type application/octet-stream, so the returned response body is the raw event stream rather than a parsed JSON object.

Example

>>> from kibana import Kibana
>>> client = Kibana("http://localhost:5601", api_key="...")
>>>
>>> response = client.observability_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     persist=False,
...     messages=[
...         {
...             "@timestamp": "2026-07-03T00:00:00.000Z",
...             "message": {
...                 "role": "user",
...                 "content": "Is my Elasticsearch cluster healthy?",
...             },
...         }
...     ],
... )
>>> print(response.body)  # raw SSE stream of completion chunks

Chat Completion

from kibana import Kibana

client = Kibana("http://localhost:5601", api_key="your_api_key")

response = client.observability_ai_assistant.chat_complete(
    connector_id="my-openai-connector",
    persist=False,
    messages=[
        {
            "@timestamp": "2026-07-03T00:00:00.000Z",
            "message": {
                "role": "user",
                "content": "Is my Elasticsearch cluster healthy?",
            },
        }
    ],
)

print(response.body)  # raw SSE stream of completion chunks

Note

On success (HTTP 200) Kibana streams the model output as server-sent events (data: {...} chunks terminated by data: [DONE]) with content type application/octet-stream, so the returned response body is the raw event stream rather than a parsed JSON object.

Persisting Conversations

Set persist=True to store the conversation so it can be continued later (and pass conversation_id to append to an existing one):

response = client.observability_ai_assistant.chat_complete(
    connector_id="my-openai-connector",
    persist=True,
    title="Cluster health check",
    messages=[
        {
            "@timestamp": "2026-07-03T00:00:00.000Z",
            "message": {
                "role": "user",
                "content": "Summarize the alerts from the last hour.",
            },
        }
    ],
)
__init__(client, default_space_id=None, validate_spaces=True)[source]

Initialize the ObservabilityAiAssistantClient.

Parameters:
  • client (Kibana) – The parent Kibana client instance to delegate requests to.

  • default_space_id (str | None) – Optional default space ID for all operations.

  • validate_spaces (bool) – Whether to validate space existence before space-scoped operations (default: True).

Example

>>> ai_assistant_client = ObservabilityAiAssistantClient(kibana_client)
chat_complete(*, messages, connector_id, persist, actions=None, conversation_id=None, disable_functions=None, instructions=None, title=None, space_id=None, validate_spaces=None)[source]

Generate a chat completion.

Technical preview in 9.4. Creates a new chat completion by using the Observability AI Assistant. The API returns the model’s response based on the current conversation context, and handles any tool requests within the conversation (which may trigger multiple calls to the underlying LLM).

Parameters:
  • messages (list[dict[str, Any]]) – An array of message objects containing the conversation history. Each message requires @timestamp (ISO 8601 string) and a message object with at least a role (one of "system", "assistant", "function", "user", "elastic") plus optional content, name, event, data and function_call fields.

  • connector_id (str) – A unique identifier for the AI (LLM) connector.

  • persist (bool) – Indicates whether the conversation should be saved to storage. If True, the conversation is saved and available in Kibana.

  • actions (list[dict[str, Any]] | None) – An array of function definitions the model may call. Each function object has name, description and JSON schema parameters.

  • conversation_id (str | None) – A unique identifier for the conversation if you are continuing an existing conversation.

  • disable_functions (bool | None) – Flag indicating whether all function calls should be disabled for the conversation. If True, no calls to functions are made.

  • instructions (list[str | dict[str, Any]] | None) – An array of instruction objects, which can be either simple strings or detailed objects with id and text fields.

  • title (str | None) – A title for the conversation.

  • space_id (str | None) – Optional space ID to run the conversation in.

  • validate_spaces (bool | None) – Override space validation setting for this operation.

Returns:

ObjectApiResponse whose body is the raw server-sent event stream of chat completion chunks (data: {...} lines terminated by data: [DONE]). At runtime Kibana serves it with content type application/octet-stream, so the body is bytes, not parsed JSON.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> response = client.observability_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     persist=False,
...     disable_functions=True,
...     messages=[
...         {
...             "@timestamp": "2026-07-03T00:00:00.000Z",
...             "message": {"role": "user", "content": "Hello"},
...         }
...     ],
...     instructions=["Answer concisely."],
... )
>>> print(response.meta.status)
200
perform_request(method, path, *, params=None, headers=None, body=None)

Perform an HTTP request via the parent client with space context enhancement.

Parameters:
  • method (str) – HTTP method (GET, POST, PUT, DELETE, etc.)

  • path (str) – API endpoint path

  • params (dict[str, Any] | None) – Query parameters

  • headers (dict[str, str] | None) – Request headers

  • body (dict[str, Any] | None) – Request body

Returns:

API response

Raises:

ApiError – If the API returns an error response (enhanced with space context)

Return type:

ObjectApiResponse[Any]

AsyncObservabilityAiAssistantClient

Asynchronous version of the ObservabilityAiAssistantClient for use with async/await syntax.

class kibana._async.client.observability_ai_assistant.AsyncObservabilityAiAssistantClient(client, default_space_id=None, validate_spaces=True)[source]

Bases: AsyncNamespaceClient

Async client for the Kibana Observability AI Assistant API.

The Observability AI Assistant chat completion API generates responses from a large language model (LLM) based on the current conversation context. It also handles any tool (function) requests within the conversation, which may trigger multiple calls to the underlying LLM.

The API is marked as Technical Preview in Kibana 9.4 and may change or be removed in a future release.

The API requires a preconfigured AI (LLM) connector (for example an OpenAI, Azure OpenAI or Amazon Bedrock connector) identified by connector_id. Conversations are space-scoped: every method accepts an optional space_id to target a specific space (None targets the default space or the space the client is scoped to).

Note

On success (HTTP 200) Kibana streams the model output as server-sent events (data: {...} chunks terminated by data: [DONE]) with content type application/octet-stream, so the returned response body is the raw event stream rather than a parsed JSON object.

Example

>>> from kibana import AsyncKibana
>>> client = AsyncKibana("http://localhost:5601", api_key="...")
>>>
>>> response = await client.observability_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     persist=False,
...     messages=[
...         {
...             "@timestamp": "2026-07-03T00:00:00.000Z",
...             "message": {
...                 "role": "user",
...                 "content": "Is my Elasticsearch cluster healthy?",
...             },
...         }
...     ],
... )
>>> print(response.body)  # raw SSE stream of completion chunks

Usage

The AsyncObservabilityAiAssistantClient provides the same methods as ObservabilityAiAssistantClient but all methods are async and must be awaited:

from kibana import AsyncKibana
import asyncio

async def main():
    async with AsyncKibana("http://localhost:5601") as client:
        response = await client.observability_ai_assistant.chat_complete(
            connector_id="my-openai-connector",
            persist=False,
            messages=[
                {
                    "@timestamp": "2026-07-03T00:00:00.000Z",
                    "message": {
                        "role": "user",
                        "content": "Is my cluster healthy?",
                    },
                }
            ],
        )

asyncio.run(main())
__init__(client, default_space_id=None, validate_spaces=True)[source]

Initialize the AsyncObservabilityAiAssistantClient.

Parameters:
  • client (AsyncKibana) – The parent AsyncKibana client instance to delegate requests to.

  • default_space_id (str | None) – Optional default space ID for all operations.

  • validate_spaces (bool) – Whether to validate space existence before space-scoped operations (default: True).

Example

>>> ai_assistant_client = AsyncObservabilityAiAssistantClient(kibana_client)
async chat_complete(*, messages, connector_id, persist, actions=None, conversation_id=None, disable_functions=None, instructions=None, title=None, space_id=None, validate_spaces=None)[source]

Generate a chat completion.

Technical preview in 9.4. Creates a new chat completion by using the Observability AI Assistant. The API returns the model’s response based on the current conversation context, and handles any tool requests within the conversation (which may trigger multiple calls to the underlying LLM).

Parameters:
  • messages (list[dict[str, Any]]) – An array of message objects containing the conversation history. Each message requires @timestamp (ISO 8601 string) and a message object with at least a role (one of "system", "assistant", "function", "user", "elastic") plus optional content, name, event, data and function_call fields.

  • connector_id (str) – A unique identifier for the AI (LLM) connector.

  • persist (bool) – Indicates whether the conversation should be saved to storage. If True, the conversation is saved and available in Kibana.

  • actions (list[dict[str, Any]] | None) – An array of function definitions the model may call. Each function object has name, description and JSON schema parameters.

  • conversation_id (str | None) – A unique identifier for the conversation if you are continuing an existing conversation.

  • disable_functions (bool | None) – Flag indicating whether all function calls should be disabled for the conversation. If True, no calls to functions are made.

  • instructions (list[str | dict[str, Any]] | None) – An array of instruction objects, which can be either simple strings or detailed objects with id and text fields.

  • title (str | None) – A title for the conversation.

  • space_id (str | None) – Optional space ID to run the conversation in.

  • validate_spaces (bool | None) – Override space validation setting for this operation.

Returns:

ObjectApiResponse whose body is the raw server-sent event stream of chat completion chunks (data: {...} lines terminated by data: [DONE]). At runtime Kibana serves it with content type application/octet-stream, so the body is bytes, not parsed JSON.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> response = await client.observability_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     persist=False,
...     disable_functions=True,
...     messages=[
...         {
...             "@timestamp": "2026-07-03T00:00:00.000Z",
...             "message": {"role": "user", "content": "Hello"},
...         }
...     ],
...     instructions=["Answer concisely."],
... )
>>> print(response.meta.status)
200
async perform_request(method, path, *, params=None, headers=None, body=None)

Perform an async HTTP request via the parent client with space context enhancement.

Parameters:
  • method (str) – HTTP method (GET, POST, PUT, DELETE, etc.)

  • path (str) – API endpoint path

  • params (dict[str, Any] | None) – Query parameters

  • headers (dict[str, str] | None) – Request headers

  • body (dict[str, Any] | None) – Request body

Returns:

API response

Raises:

ApiError – If the API returns an error response (enhanced with space context)

Return type:

ObjectApiResponse[Any]