SecurityAiAssistantClient

Client for the Kibana Security AI Assistant API.

The Security AI Assistant helps security analysts triage alerts, write queries and investigate incidents through a large language model. This client manages the assistant’s building blocks – conversations, prompts, anonymization fields and Knowledge Base entries – and can request model responses via chat_complete using any AI connector (.gen-ai, .bedrock, .gemini, …) configured in Kibana.

All Security AI Assistant resources are space-scoped: a conversation or prompt created in one space is not visible from another space. Every method accepts an optional space_id to target a specific space.

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

Bases: NamespaceClient

Client for the Kibana Security AI Assistant API.

The Security AI Assistant helps security analysts triage alerts, write queries and investigate incidents through a large language model. This client manages the assistant’s building blocks – conversations, prompts, anonymization fields and Knowledge Base entries – and can request model responses via chat_complete() using any AI (.gen-ai, .bedrock, .gemini, …) connector configured in Kibana.

All Security AI Assistant resources 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).

Example

>>> from kibana import Kibana
>>> client = Kibana("http://localhost:5601", api_key="...")
>>>
>>> # Create and find conversations
>>> conv = client.security_ai_assistant.create_conversation(
...     title="Suspicious login investigation",
... )
>>> found = client.security_ai_assistant.find_conversations(
...     filter="Suspicious",
... )
>>>
>>> # Ask the model a question through an AI connector
>>> answer = client.security_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     messages=[{"role": "user", "content": "What is a brute force attack?"}],
...     persist=False,
... )
>>> print(answer.body["data"])

Managing Conversations

from kibana import Kibana

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

# Create a conversation
conv = client.security_ai_assistant.create_conversation(
    title="Suspicious login investigation",
    messages=[
        {
            "content": "Investigate the failed logins on host web-01.",
            "role": "user",
            "timestamp": "2026-01-01T12:00:00Z",
        }
    ],
)
conversation_id = conv.body["id"]

# Search, update and delete conversations
found = client.security_ai_assistant.find_conversations(
    filter="Suspicious", sort_field="created_at", sort_order="desc"
)
client.security_ai_assistant.update_conversation(
    id=conversation_id, title="Suspicious login investigation (triaged)"
)
client.security_ai_assistant.delete_conversation(id=conversation_id)

# Delete every conversation except the ones listed
client.security_ai_assistant.delete_all_conversations(
    excluded_ids=["keep-this-conversation-id"]
)

Prompts and Anonymization Fields

Prompts and anonymization fields are managed through _find and _bulk_action endpoints:

# Bulk-create prompts
result = client.security_ai_assistant.bulk_action_prompts(
    create=[
        {
            "name": "Summarize alerts",
            "content": "Summarize the open alerts of the last 24 hours.",
            "promptType": "quick",
        }
    ],
)
prompt_id = result.body["attributes"]["results"]["created"][0]["id"]

# Update and delete in one bulk call
client.security_ai_assistant.bulk_action_prompts(
    update=[{"id": prompt_id, "content": "Summarize critical alerts."}],
)
client.security_ai_assistant.bulk_action_prompts(
    delete={"ids": [prompt_id]},
)

# Control which fields may be sent to the model (and anonymized)
client.security_ai_assistant.bulk_action_anonymization_fields(
    create=[{"field": "user.name", "allowed": True, "anonymized": True}],
)
fields = client.security_ai_assistant.find_anonymization_fields(
    filter='field: "user.name"'
)

Knowledge Base

# Check and run the Knowledge Base setup (ELSER model + content)
status = client.security_ai_assistant.get_knowledge_base()
if status.body["is_setup_available"]:
    client.security_ai_assistant.setup_knowledge_base(
        ignore_security_labs=True
    )

# Create a document entry the assistant can use as context
entry = client.security_ai_assistant.create_knowledge_base_entry(
    type="document",
    name="Password reset runbook",
    kb_resource="user",
    source="/runbooks/password-reset.md",
    text="To reset a password, open the settings page ...",
)
entry_id = entry.body["id"]

# Find, update, and delete entries
client.security_ai_assistant.find_knowledge_base_entries(per_page=50)
client.security_ai_assistant.update_knowledge_base_entry(
    id=entry_id,
    type="document",
    name="Password reset runbook (v2)",
    kb_resource="user",
    source="/runbooks/password-reset.md",
    text="Updated instructions ...",
)
client.security_ai_assistant.delete_knowledge_base_entry(id=entry_id)

Chatting With the Model

chat_complete routes the messages through a Kibana AI connector. LLM calls can be slow, so raise the request timeout for these calls:

response = client.options(request_timeout=120).security_ai_assistant.chat_complete(
    connector_id="my-openai-connector",
    messages=[
        {"role": "user", "content": "What are common phishing techniques?"}
    ],
    persist=False,
)
print(response.body["data"])
__init__(client, default_space_id=None, validate_spaces=True)[source]

Initialize the SecurityAiAssistantClient.

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

>>> security_ai_assistant_client = SecurityAiAssistantClient(kibana_client)
create_conversation(*, title, api_config=None, category=None, exclude_from_last_conversation_storage=None, id=None, messages=None, replacements=None, space_id=None, validate_spaces=None)[source]

Create a conversation.

POST /api/security_ai_assistant/current_user/conversations. Creates a new Security AI Assistant conversation for the current user, optionally seeded with messages and an LLM API configuration.

Parameters:
  • title (str) – The conversation title.

  • api_config (dict[str, Any] | None) – LLM API configuration, e.g. {"connectorId": "...", "actionTypeId": ".gen-ai", "model": "gpt-4", "provider": "OpenAI"}. connectorId and actionTypeId are required inside this object when it is provided.

  • category (str | None) – The conversation category: assistant or insights.

  • exclude_from_last_conversation_storage (bool | None) – Exclude this conversation from last-conversation storage.

  • id (str | None) – Optional caller-specified conversation ID.

  • messages (list[dict[str, Any]] | None) – The conversation messages. Each message requires content, role (system, user or assistant) and timestamp (ISO 8601).

  • replacements (dict[str, str] | None) – Replacements object used to anonymize/de-anonymize messages (mapping of replacement token to original value).

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

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

Returns:

ObjectApiResponse with the created conversation, including its server-assigned id, createdAt, createdBy and users.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> conv = client.security_ai_assistant.create_conversation(
...     title="Security Discussion",
...     messages=[
...         {
...             "content": "Hello, how can I assist you today?",
...             "role": "system",
...             "timestamp": "2026-01-01T12:00:00Z",
...         }
...     ],
... )
>>> print(conv.body["id"])
get_conversation(*, id, space_id=None, validate_spaces=None)[source]

Get a conversation.

GET /api/security_ai_assistant/current_user/conversations/{id}. Gets the details of an existing conversation by its unique ID.

Parameters:
  • id (str) – The conversation’s id value.

  • space_id (str | None) – Optional space ID to get the conversation from.

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

Returns:

ObjectApiResponse with the conversation details (id, title, messages, apiConfig, users, …).

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> conv = client.security_ai_assistant.get_conversation(id="abc123")
>>> print(conv.body["title"])
update_conversation(*, id, api_config=None, category=None, exclude_from_last_conversation_storage=None, messages=None, replacements=None, title=None, users=None, space_id=None, validate_spaces=None)[source]

Update a conversation.

PUT /api/security_ai_assistant/current_user/conversations/{id}. Updates an existing conversation. Only the provided fields are modified.

Parameters:
  • id (str) – The conversation’s id value.

  • api_config (dict[str, Any] | None) – Updated LLM API configuration (connectorId and actionTypeId are required inside this object when it is provided).

  • category (str | None) – Updated conversation category: assistant or insights. Note: on Kibana 9.4.3 the live server accepts this field but does not change the stored category.

  • exclude_from_last_conversation_storage (bool | None) – Exclude this conversation from last-conversation storage.

  • messages (list[dict[str, Any]] | None) – Replacement list of conversation messages. Each message requires content, role and timestamp.

  • replacements (dict[str, str] | None) – Replacements object used to anonymize/de-anonymize messages.

  • title (str | None) – Updated conversation title.

  • users (list[dict[str, Any]] | None) – Users with access to the conversation, e.g. [{"id": "...", "name": "..."}].

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

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

Returns:

ObjectApiResponse with the updated conversation.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> updated = client.security_ai_assistant.update_conversation(
...     id="abc123",
...     title="Updated Security Discussion",
... )
>>> print(updated.body["title"])
Updated Security Discussion
delete_conversation(*, id, space_id=None, validate_spaces=None)[source]

Delete a conversation.

DELETE /api/security_ai_assistant/current_user/conversations/{id}. Permanently deletes an existing conversation by its ID.

Note: the 9.4.3 spec documents the deleted conversation as the response body, but the live server returns an empty object {}.

Parameters:
  • id (str) – The conversation’s id value.

  • space_id (str | None) – Optional space ID to delete the conversation from.

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

Returns:

ObjectApiResponse with an empty object body on success.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> client.security_ai_assistant.delete_conversation(id="abc123")
find_conversations(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, is_owner=None, space_id=None, validate_spaces=None)[source]

Get conversations.

GET /api/security_ai_assistant/current_user/conversations/_find. Lists the current user’s conversations with search, filter, sort and pagination support.

Parameters:
  • fields (list[str] | None) – A list of fields to include in the response. If omitted, all fields are returned.

  • filter (str | None) – A search query to filter the conversations. Can match against titles, messages, or other conversation attributes.

  • sort_field (str | None) – Field to sort by: created_at, title or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Conversations per page (default 20).

  • is_owner (bool | None) – If True, only conversations owned by the current user are returned.

  • space_id (str | None) – Optional space ID to search conversations in.

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

Returns:

ObjectApiResponse with page, perPage, total and the data array of conversations.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = client.security_ai_assistant.find_conversations(
...     filter="Security",
...     sort_field="created_at",
...     sort_order="desc",
... )
>>> print(found.body["total"])
delete_all_conversations(*, excluded_ids=None, space_id=None, validate_spaces=None)[source]

Delete all conversations.

DELETE /api/security_ai_assistant/current_user/conversations. Permanently deletes all of the current user’s conversations in the target space. Conversations listed in excluded_ids are kept.

Parameters:
  • excluded_ids (list[str] | None) – Conversation IDs to exclude from deletion (they are kept; every other conversation is deleted).

  • space_id (str | None) – Optional space ID to delete conversations in.

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

Returns:

ObjectApiResponse with success, totalDeleted and failures.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = client.security_ai_assistant.delete_all_conversations(
...     excluded_ids=["abc123"],
... )
>>> print(result.body["totalDeleted"])
find_prompts(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, space_id=None, validate_spaces=None)[source]

Get prompts.

GET /api/security_ai_assistant/prompts/_find. Lists prompts with optional filters, sorting and pagination.

Parameters:
  • fields (list[str] | None) – List of specific fields to include in each returned prompt.

  • filter (str | None) – Search query string to filter prompts by matching fields.

  • sort_field (str | None) – Field to sort by: created_at, is_default, name or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Prompts per page (default 20).

  • space_id (str | None) – Optional space ID to search prompts in.

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

Returns:

ObjectApiResponse with page, perPage, total and the data array of prompts.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = client.security_ai_assistant.find_prompts(
...     filter="security",
...     per_page=50,
... )
>>> for prompt in found.body["data"]:
...     print(prompt["name"])
bulk_action_prompts(*, create=None, update=None, delete=None, space_id=None, validate_spaces=None)[source]

Apply a bulk action to prompts.

POST /api/security_ai_assistant/prompts/_bulk_action. Creates, updates and/or deletes multiple prompts in a single request. The delete action is applied to all prompts matching the filter query or to the listed prompt IDs.

Parameters:
  • create (list[dict[str, Any]] | None) – List of prompts to create. Each prompt requires name, content and promptType (system or quick). Note: on Kibana 9.4.3 the live server 500s when a prompt name contains KQL-special characters such as : (its internal duplicate-name check builds an unescaped KQL query), so avoid colons in prompt names.

  • update (list[dict[str, Any]] | None) – List of prompt updates. Each item requires id plus the fields to change (content, color, categories, isDefault, …).

  • delete (dict[str, Any] | None) – Deletion criteria: {"ids": [...]} and/or {"query": "..."}.

  • space_id (str | None) – Optional space ID to apply the bulk action in.

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

Returns:

ObjectApiResponse with success, prompts_count and an attributes object holding per-action results (created, updated, deleted, skipped) and a summary.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = client.security_ai_assistant.bulk_action_prompts(
...     create=[
...         {
...             "name": "New Security Prompt",
...             "content": "Please verify the security settings.",
...             "promptType": "quick",
...         }
...     ],
... )
>>> print(result.body["attributes"]["results"]["created"][0]["id"])
find_anonymization_fields(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, all_data=None, space_id=None, validate_spaces=None)[source]

Get anonymization fields.

GET /api/security_ai_assistant/anonymization_fields/_find. Lists the anonymization fields that control which event fields are allowed to be sent to the model and which are anonymized first.

Parameters:
  • fields (list[str] | None) – Fields to return, e.g. ["id", "field", "anonymized", "allowed"].

  • filter (str | None) – Search query, e.g. 'field: "user.name"'.

  • sort_field (str | None) – Field to sort by: created_at, anonymized, allowed, field or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Anonymization fields per page (default 20).

  • all_data (bool | None) – If True, additionally fetch all anonymization fields (returned under all), otherwise fetch only the requested page.

  • space_id (str | None) – Optional space ID to search anonymization fields in.

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

Returns:

ObjectApiResponse with page, perPage, total, the data array, optional all array and aggregations.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = client.security_ai_assistant.find_anonymization_fields(
...     filter='field: "host.name"',
... )
>>> print(found.body["total"])
bulk_action_anonymization_fields(*, create=None, update=None, delete=None, space_id=None, validate_spaces=None)[source]

Apply a bulk action to anonymization fields.

POST /api/security_ai_assistant/anonymization_fields/_bulk_action. Creates, updates and/or deletes multiple anonymization fields in a single request. The delete action is applied to all fields matching the filter query or to the listed field IDs.

Parameters:
  • create (list[dict[str, Any]] | None) – List of anonymization fields to create. Each item requires field (the ECS field name) and optionally allowed and anonymized booleans.

  • update (list[dict[str, Any]] | None) – List of anonymization field updates. Each item requires id plus the allowed/anonymized flags to change.

  • delete (dict[str, Any] | None) – Deletion criteria: {"ids": [...]} and/or {"query": "..."}.

  • space_id (str | None) – Optional space ID to apply the bulk action in.

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

Returns:

ObjectApiResponse with success, anonymization_fields_count and an attributes object holding per-action results (created, updated, deleted, skipped) and a summary.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = client.security_ai_assistant.bulk_action_anonymization_fields(
...     create=[
...         {"field": "host.name", "allowed": True, "anonymized": False},
...     ],
... )
>>> print(result.body["attributes"]["summary"]["succeeded"])
get_knowledge_base(*, resource=None, space_id=None, validate_spaces=None)[source]

Read Knowledge Base status.

GET /api/security_ai_assistant/knowledge_base or GET /api/security_ai_assistant/knowledge_base/{resource} when resource is provided. Returns the setup status of the assistant’s Knowledge Base (ELSER model, Security Labs docs, user data, product documentation).

Parameters:
  • resource (str | None) – Optional Knowledge Base resource identifier (e.g. security_labs, defend_insights, user) to read the status for.

  • space_id (str | None) – Optional space ID to read the Knowledge Base status in.

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

Returns:

elser_exists, is_setup_available, is_setup_in_progress, security_labs_exists, defend_insights_exists, user_data_exists and product_documentation_status.

Return type:

ObjectApiResponse with status flags

Raises:

Example

>>> status = client.security_ai_assistant.get_knowledge_base()
>>> print(status.body["elser_exists"])
setup_knowledge_base(*, resource=None, model_id=None, ignore_security_labs=None, space_id=None, validate_spaces=None)[source]

Set up the Knowledge Base.

POST /api/security_ai_assistant/knowledge_base or POST /api/security_ai_assistant/knowledge_base/{resource} when resource is provided. Installs and starts the ELSER model (if needed) and loads Knowledge Base content. Security Labs docs are installed by default unless ignore_security_labs is True.

Parameters:
  • resource (str | None) – Optional Knowledge Base resource identifier (e.g. security_labs, defend_insights, user) to set up.

  • model_id (str | None) – ELSER model ID to use when setting up the Knowledge Base. If not provided, a default model is used.

  • ignore_security_labs (bool | None) – If True, skip installing Security Labs docs during setup. Defaults to False on the server.

  • space_id (str | None) – Optional space ID to set up the Knowledge Base in.

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

Returns:

ObjectApiResponse with {"success": true} on success.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = client.security_ai_assistant.setup_knowledge_base(
...     ignore_security_labs=True,
... )
>>> print(result.body["success"])
True
create_knowledge_base_entry(*, type, name, text=None, source=None, kb_resource=None, required=None, vector=None, index=None, field=None, description=None, query_description=None, input_schema=None, output_fields=None, global_=None, namespace=None, users=None, space_id=None, validate_spaces=None)[source]

Create a Knowledge Base entry.

POST /api/security_ai_assistant/knowledge_base/entries. Creates either a document entry (inline text content) or an index entry (an Elasticsearch index/data stream the assistant may query), depending on type.

Parameters:
  • type (str) – Entry type: document or index.

  • name (str) – Name of the Knowledge Base entry.

  • text (str | None) – Entry content (required for document entries).

  • source (str | None) – Source document name or filepath (required for document entries).

  • kb_resource (str | None) – Knowledge Base resource grouping for the entry: security_labs, defend_insights or user (required for document entries).

  • required (bool | None) – Whether this document resource should always be included in the model context (document entries only, defaults to False).

  • vector (dict[str, Any] | None) – Optional pre-computed embeddings for document entries: {"modelId": ..., "tokens": {...}}.

  • index (str | None) – Index or data stream to query for content (required for index entries).

  • field (str | None) – Field to query for content (required for index entries).

  • description (str | None) – Description of when this index should be queried, passed to the LLM as a tool description (required for index entries).

  • query_description (str | None) – Description of the query field, passed to the LLM as part of the tool input schema (required for index entries).

  • input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for index entries: [{"fieldName": ..., "fieldType": ..., "description": ...}].

  • output_fields (list[str] | None) – Fields to extract from query results for index entries; defaults to all fields.

  • global – Whether the entry is global (visible to all users). Sent as the global body field; defaults to False.

  • namespace (str | None) – Kibana space for the entry, defaults to the default space.

  • users (list[dict[str, Any]] | None) – Users with access to the entry, defaults to the current user. An empty array grants access to all users.

  • space_id (str | None) – Optional space ID to create the entry in.

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

Returns:

ObjectApiResponse with the created Knowledge Base entry, including its server-assigned id.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> entry = client.security_ai_assistant.create_knowledge_base_entry(
...     type="document",
...     name="Password reset runbook",
...     kb_resource="user",
...     source="/runbooks/password-reset.md",
...     text="To reset a password, open the settings page ...",
... )
>>> print(entry.body["id"])
get_knowledge_base_entry(*, id, space_id=None, validate_spaces=None)[source]

Get a Knowledge Base entry.

GET /api/security_ai_assistant/knowledge_base/entries/{id}. Retrieves a Knowledge Base entry by its unique ID.

Parameters:
  • id (str) – The unique identifier of the Knowledge Base entry.

  • space_id (str | None) – Optional space ID to get the entry from.

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

Returns:

ObjectApiResponse with the Knowledge Base entry.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> entry = client.security_ai_assistant.get_knowledge_base_entry(
...     id="12345",
... )
>>> print(entry.body["name"])
update_knowledge_base_entry(*, id, type, name, text=None, source=None, kb_resource=None, required=None, vector=None, index=None, field=None, description=None, query_description=None, input_schema=None, output_fields=None, global_=None, namespace=None, users=None, space_id=None, validate_spaces=None)[source]

Update a Knowledge Base entry.

PUT /api/security_ai_assistant/knowledge_base/entries/{id}. Replaces an existing Knowledge Base entry. The body follows the same document/index union as create_knowledge_base_entry(), so the type-specific required fields must be provided again.

Parameters:
  • id (str) – The unique identifier of the Knowledge Base entry to update.

  • type (str) – Entry type: document or index.

  • name (str) – Name of the Knowledge Base entry.

  • text (str | None) – Entry content (required for document entries).

  • source (str | None) – Source document name or filepath (required for document entries).

  • kb_resource (str | None) – Knowledge Base resource grouping for the entry: security_labs, defend_insights or user (required for document entries).

  • required (bool | None) – Whether this document resource should always be included in the model context (document entries only).

  • vector (dict[str, Any] | None) – Optional pre-computed embeddings for document entries.

  • index (str | None) – Index or data stream to query for content (required for index entries).

  • field (str | None) – Field to query for content (required for index entries).

  • description (str | None) – Description of when this index should be queried (required for index entries).

  • query_description (str | None) – Description of the query field (required for index entries).

  • input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for index entries.

  • output_fields (list[str] | None) – Fields to extract from query results for index entries.

  • global – Whether the entry is global (visible to all users). Sent as the global body field.

  • namespace (str | None) – Kibana space for the entry.

  • users (list[dict[str, Any]] | None) – Users with access to the entry.

  • space_id (str | None) – Optional space ID to update the entry in.

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

Returns:

ObjectApiResponse with the updated Knowledge Base entry.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> updated = client.security_ai_assistant.update_knowledge_base_entry(
...     id="12345",
...     type="document",
...     name="Password reset runbook (updated)",
...     kb_resource="user",
...     source="/runbooks/password-reset.md",
...     text="Updated instructions ...",
... )
>>> print(updated.body["name"])
delete_knowledge_base_entry(*, id, space_id=None, validate_spaces=None)[source]

Delete a Knowledge Base entry.

DELETE /api/security_ai_assistant/knowledge_base/entries/{id}. Deletes a Knowledge Base entry by its unique ID.

Parameters:
  • id (str) – The unique identifier of the Knowledge Base entry to delete.

  • space_id (str | None) – Optional space ID to delete the entry from.

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

Returns:

ObjectApiResponse with the id of the deleted entry.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> client.security_ai_assistant.delete_knowledge_base_entry(
...     id="12345",
... )
find_knowledge_base_entries(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, space_id=None, validate_spaces=None)[source]

Find Knowledge Base entries.

GET /api/security_ai_assistant/knowledge_base/entries/_find. Finds Knowledge Base entries that match the given query, with sorting and pagination.

Parameters:
  • fields (list[str] | None) – A list of fields to include in the response. If not provided, all fields are included.

  • filter (str | None) – Search query to filter entries by specific criteria.

  • sort_field (str | None) – Field to sort by: created_at, is_default, title or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Entries per page (default 20).

  • space_id (str | None) – Optional space ID to search entries in.

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

Returns:

ObjectApiResponse with page, perPage, total and the data array of Knowledge Base entries.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = client.security_ai_assistant.find_knowledge_base_entries(
...     per_page=50,
... )
>>> print(found.body["total"])
bulk_action_knowledge_base_entries(*, create=None, update=None, delete=None, space_id=None, validate_spaces=None)[source]

Apply a bulk action to Knowledge Base entries.

POST /api/security_ai_assistant/knowledge_base/entries/_bulk_action. Creates, updates and/or deletes multiple Knowledge Base entries in a single request. The delete action is applied to all entries matching the filter query or to the listed entry IDs.

Parameters:
  • create (list[dict[str, Any]] | None) – List of entries to create. Each item follows the same document/index union as create_knowledge_base_entry() (e.g. {"type": "document", "name": ..., "kbResource": ..., "source": ..., "text": ...}).

  • update (list[dict[str, Any]] | None) – List of entry updates. Each item requires id plus the entry fields to change.

  • delete (dict[str, Any] | None) – Deletion criteria: {"ids": [...]} and/or {"query": "..."}.

  • space_id (str | None) – Optional space ID to apply the bulk action in.

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

Returns:

ObjectApiResponse with success, knowledgeBaseEntriesCount and an attributes object holding per-action results (created, updated, deleted, skipped) and a summary.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = client.security_ai_assistant.bulk_action_knowledge_base_entries(
...     delete={"ids": ["123", "456"]},
... )
>>> print(result.body["attributes"]["summary"]["succeeded"])
chat_complete(*, connector_id, messages, persist, conversation_id=None, is_stream=None, lang_smith_api_key=None, lang_smith_project=None, model=None, prompt_id=None, response_language=None, content_references_disabled=None, space_id=None, validate_spaces=None)[source]

Create a model response for a chat conversation.

POST /api/security_ai_assistant/chat/complete. Sends the chat messages to the LLM behind the given Kibana AI connector and returns the model response. Depending on the model and local setup this call can take a while; consider raising the request timeout via client.options(request_timeout=...).

Parameters:
  • connector_id (str) – Kibana AI connector ID used to route the request (e.g. a .gen-ai connector).

  • messages (list[dict[str, Any]]) – List of chat messages exchanged so far. Each message requires role (system, user or assistant) and typically content; optional data and fields_to_anonymize attach anonymizable metadata.

  • persist (bool) – Whether to persist the chat and response as a Security AI Assistant conversation.

  • conversation_id (str | None) – Existing conversation ID to continue (used with persist=True).

  • is_stream (bool | None) – If True, the response is streamed in chunks (application/octet-stream) instead of a single JSON object.

  • lang_smith_api_key (str | None) – API key for LangSmith integration.

  • lang_smith_project (str | None) – LangSmith project name for tracing.

  • model (str | None) – Model ID or name to use for the response (overrides the connector’s default model).

  • prompt_id (str | None) – Prompt template identifier.

  • response_language (str | None) – ISO language code for the assistant’s response.

  • content_references_disabled (bool | None) – If True, the response will not include content references (sent as the content_references_disabled query parameter).

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

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

Returns:

ObjectApiResponse with the model response. For non-streaming calls the body contains connector_id, data (the response text), replacements, trace_data and status.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> response = client.options(request_timeout=120).security_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     messages=[
...         {"role": "user", "content": "What are common phishing techniques?"},
...     ],
...     persist=False,
... )
>>> print(response.body["data"])
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]

AsyncSecurityAiAssistantClient

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

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

Bases: AsyncNamespaceClient

Async client for the Kibana Security AI Assistant API.

The Security AI Assistant helps security analysts triage alerts, write queries and investigate incidents through a large language model. This client manages the assistant’s building blocks – conversations, prompts, anonymization fields and Knowledge Base entries – and can request model responses via chat_complete() using any AI (.gen-ai, .bedrock, .gemini, …) connector configured in Kibana.

All Security AI Assistant resources 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).

Example

>>> from kibana import AsyncKibana
>>> client = AsyncKibana("http://localhost:5601", api_key="...")
>>>
>>> # Create and find conversations
>>> conv = await client.security_ai_assistant.create_conversation(
...     title="Suspicious login investigation",
... )
>>> found = await client.security_ai_assistant.find_conversations(
...     filter="Suspicious",
... )
>>>
>>> # Ask the model a question through an AI connector
>>> answer = await client.security_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     messages=[{"role": "user", "content": "What is a brute force attack?"}],
...     persist=False,
... )
>>> print(answer.body["data"])

Usage

The AsyncSecurityAiAssistantClient provides the same methods as SecurityAiAssistantClient but all methods are async and must be awaited:

import asyncio

from kibana import AsyncKibana

async def main():
    async with AsyncKibana("http://localhost:5601") as client:
        conv = await client.security_ai_assistant.create_conversation(
            title="Async investigation",
        )
        found = await client.security_ai_assistant.find_conversations(
            filter="Async investigation",
        )
        await client.security_ai_assistant.delete_conversation(
            id=conv.body["id"],
        )

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

Initialize the AsyncSecurityAiAssistantClient.

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

>>> security_ai_assistant_client = AsyncSecurityAiAssistantClient(
...     kibana_client
... )
async create_conversation(*, title, api_config=None, category=None, exclude_from_last_conversation_storage=None, id=None, messages=None, replacements=None, space_id=None, validate_spaces=None)[source]

Create a conversation.

POST /api/security_ai_assistant/current_user/conversations. Creates a new Security AI Assistant conversation for the current user, optionally seeded with messages and an LLM API configuration.

Parameters:
  • title (str) – The conversation title.

  • api_config (dict[str, Any] | None) – LLM API configuration, e.g. {"connectorId": "...", "actionTypeId": ".gen-ai", "model": "gpt-4", "provider": "OpenAI"}. connectorId and actionTypeId are required inside this object when it is provided.

  • category (str | None) – The conversation category: assistant or insights.

  • exclude_from_last_conversation_storage (bool | None) – Exclude this conversation from last-conversation storage.

  • id (str | None) – Optional caller-specified conversation ID.

  • messages (list[dict[str, Any]] | None) – The conversation messages. Each message requires content, role (system, user or assistant) and timestamp (ISO 8601).

  • replacements (dict[str, str] | None) – Replacements object used to anonymize/de-anonymize messages (mapping of replacement token to original value).

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

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

Returns:

ObjectApiResponse with the created conversation, including its server-assigned id, createdAt, createdBy and users.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> conv = await client.security_ai_assistant.create_conversation(
...     title="Security Discussion",
...     messages=[
...         {
...             "content": "Hello, how can I assist you today?",
...             "role": "system",
...             "timestamp": "2026-01-01T12:00:00Z",
...         }
...     ],
... )
>>> print(conv.body["id"])
async get_conversation(*, id, space_id=None, validate_spaces=None)[source]

Get a conversation.

GET /api/security_ai_assistant/current_user/conversations/{id}. Gets the details of an existing conversation by its unique ID.

Parameters:
  • id (str) – The conversation’s id value.

  • space_id (str | None) – Optional space ID to get the conversation from.

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

Returns:

ObjectApiResponse with the conversation details (id, title, messages, apiConfig, users, …).

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> conv = await client.security_ai_assistant.get_conversation(id="abc123")
>>> print(conv.body["title"])
async update_conversation(*, id, api_config=None, category=None, exclude_from_last_conversation_storage=None, messages=None, replacements=None, title=None, users=None, space_id=None, validate_spaces=None)[source]

Update a conversation.

PUT /api/security_ai_assistant/current_user/conversations/{id}. Updates an existing conversation. Only the provided fields are modified.

Parameters:
  • id (str) – The conversation’s id value.

  • api_config (dict[str, Any] | None) – Updated LLM API configuration (connectorId and actionTypeId are required inside this object when it is provided).

  • category (str | None) – Updated conversation category: assistant or insights. Note: on Kibana 9.4.3 the live server accepts this field but does not change the stored category.

  • exclude_from_last_conversation_storage (bool | None) – Exclude this conversation from last-conversation storage.

  • messages (list[dict[str, Any]] | None) – Replacement list of conversation messages. Each message requires content, role and timestamp.

  • replacements (dict[str, str] | None) – Replacements object used to anonymize/de-anonymize messages.

  • title (str | None) – Updated conversation title.

  • users (list[dict[str, Any]] | None) – Users with access to the conversation, e.g. [{"id": "...", "name": "..."}].

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

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

Returns:

ObjectApiResponse with the updated conversation.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> updated = await client.security_ai_assistant.update_conversation(
...     id="abc123",
...     title="Updated Security Discussion",
... )
>>> print(updated.body["title"])
Updated Security Discussion
async delete_conversation(*, id, space_id=None, validate_spaces=None)[source]

Delete a conversation.

DELETE /api/security_ai_assistant/current_user/conversations/{id}. Permanently deletes an existing conversation by its ID.

Note: the 9.4.3 spec documents the deleted conversation as the response body, but the live server returns an empty object {}.

Parameters:
  • id (str) – The conversation’s id value.

  • space_id (str | None) – Optional space ID to delete the conversation from.

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

Returns:

ObjectApiResponse with an empty object body on success.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> await client.security_ai_assistant.delete_conversation(id="abc123")
async find_conversations(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, is_owner=None, space_id=None, validate_spaces=None)[source]

Get conversations.

GET /api/security_ai_assistant/current_user/conversations/_find. Lists the current user’s conversations with search, filter, sort and pagination support.

Parameters:
  • fields (list[str] | None) – A list of fields to include in the response. If omitted, all fields are returned.

  • filter (str | None) – A search query to filter the conversations. Can match against titles, messages, or other conversation attributes.

  • sort_field (str | None) – Field to sort by: created_at, title or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Conversations per page (default 20).

  • is_owner (bool | None) – If True, only conversations owned by the current user are returned.

  • space_id (str | None) – Optional space ID to search conversations in.

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

Returns:

ObjectApiResponse with page, perPage, total and the data array of conversations.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = await client.security_ai_assistant.find_conversations(
...     filter="Security",
...     sort_field="created_at",
...     sort_order="desc",
... )
>>> print(found.body["total"])
async delete_all_conversations(*, excluded_ids=None, space_id=None, validate_spaces=None)[source]

Delete all conversations.

DELETE /api/security_ai_assistant/current_user/conversations. Permanently deletes all of the current user’s conversations in the target space. Conversations listed in excluded_ids are kept.

Parameters:
  • excluded_ids (list[str] | None) – Conversation IDs to exclude from deletion (they are kept; every other conversation is deleted).

  • space_id (str | None) – Optional space ID to delete conversations in.

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

Returns:

ObjectApiResponse with success, totalDeleted and failures.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = await client.security_ai_assistant.delete_all_conversations(
...     excluded_ids=["abc123"],
... )
>>> print(result.body["totalDeleted"])
async find_prompts(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, space_id=None, validate_spaces=None)[source]

Get prompts.

GET /api/security_ai_assistant/prompts/_find. Lists prompts with optional filters, sorting and pagination.

Parameters:
  • fields (list[str] | None) – List of specific fields to include in each returned prompt.

  • filter (str | None) – Search query string to filter prompts by matching fields.

  • sort_field (str | None) – Field to sort by: created_at, is_default, name or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Prompts per page (default 20).

  • space_id (str | None) – Optional space ID to search prompts in.

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

Returns:

ObjectApiResponse with page, perPage, total and the data array of prompts.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = await client.security_ai_assistant.find_prompts(
...     filter="security",
...     per_page=50,
... )
>>> for prompt in found.body["data"]:
...     print(prompt["name"])
async bulk_action_prompts(*, create=None, update=None, delete=None, space_id=None, validate_spaces=None)[source]

Apply a bulk action to prompts.

POST /api/security_ai_assistant/prompts/_bulk_action. Creates, updates and/or deletes multiple prompts in a single request. The delete action is applied to all prompts matching the filter query or to the listed prompt IDs.

Parameters:
  • create (list[dict[str, Any]] | None) – List of prompts to create. Each prompt requires name, content and promptType (system or quick). Note: on Kibana 9.4.3 the live server 500s when a prompt name contains KQL-special characters such as : (its internal duplicate-name check builds an unescaped KQL query), so avoid colons in prompt names.

  • update (list[dict[str, Any]] | None) – List of prompt updates. Each item requires id plus the fields to change (content, color, categories, isDefault, …).

  • delete (dict[str, Any] | None) – Deletion criteria: {"ids": [...]} and/or {"query": "..."}.

  • space_id (str | None) – Optional space ID to apply the bulk action in.

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

Returns:

ObjectApiResponse with success, prompts_count and an attributes object holding per-action results (created, updated, deleted, skipped) and a summary.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = await client.security_ai_assistant.bulk_action_prompts(
...     create=[
...         {
...             "name": "New Security Prompt",
...             "content": "Please verify the security settings.",
...             "promptType": "quick",
...         }
...     ],
... )
>>> print(result.body["attributes"]["results"]["created"][0]["id"])
async find_anonymization_fields(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, all_data=None, space_id=None, validate_spaces=None)[source]

Get anonymization fields.

GET /api/security_ai_assistant/anonymization_fields/_find. Lists the anonymization fields that control which event fields are allowed to be sent to the model and which are anonymized first.

Parameters:
  • fields (list[str] | None) – Fields to return, e.g. ["id", "field", "anonymized", "allowed"].

  • filter (str | None) – Search query, e.g. 'field: "user.name"'.

  • sort_field (str | None) – Field to sort by: created_at, anonymized, allowed, field or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Anonymization fields per page (default 20).

  • all_data (bool | None) – If True, additionally fetch all anonymization fields (returned under all), otherwise fetch only the requested page.

  • space_id (str | None) – Optional space ID to search anonymization fields in.

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

Returns:

ObjectApiResponse with page, perPage, total, the data array, optional all array and aggregations.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = await client.security_ai_assistant.find_anonymization_fields(
...     filter='field: "host.name"',
... )
>>> print(found.body["total"])
async bulk_action_anonymization_fields(*, create=None, update=None, delete=None, space_id=None, validate_spaces=None)[source]

Apply a bulk action to anonymization fields.

POST /api/security_ai_assistant/anonymization_fields/_bulk_action. Creates, updates and/or deletes multiple anonymization fields in a single request. The delete action is applied to all fields matching the filter query or to the listed field IDs.

Parameters:
  • create (list[dict[str, Any]] | None) – List of anonymization fields to create. Each item requires field (the ECS field name) and optionally allowed and anonymized booleans.

  • update (list[dict[str, Any]] | None) – List of anonymization field updates. Each item requires id plus the allowed/anonymized flags to change.

  • delete (dict[str, Any] | None) – Deletion criteria: {"ids": [...]} and/or {"query": "..."}.

  • space_id (str | None) – Optional space ID to apply the bulk action in.

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

Returns:

ObjectApiResponse with success, anonymization_fields_count and an attributes object holding per-action results (created, updated, deleted, skipped) and a summary.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = await client.security_ai_assistant.bulk_action_anonymization_fields(
...     create=[
...         {"field": "host.name", "allowed": True, "anonymized": False},
...     ],
... )
>>> print(result.body["attributes"]["summary"]["succeeded"])
async get_knowledge_base(*, resource=None, space_id=None, validate_spaces=None)[source]

Read Knowledge Base status.

GET /api/security_ai_assistant/knowledge_base or GET /api/security_ai_assistant/knowledge_base/{resource} when resource is provided. Returns the setup status of the assistant’s Knowledge Base (ELSER model, Security Labs docs, user data, product documentation).

Parameters:
  • resource (str | None) – Optional Knowledge Base resource identifier (e.g. security_labs, defend_insights, user) to read the status for.

  • space_id (str | None) – Optional space ID to read the Knowledge Base status in.

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

Returns:

elser_exists, is_setup_available, is_setup_in_progress, security_labs_exists, defend_insights_exists, user_data_exists and product_documentation_status.

Return type:

ObjectApiResponse with status flags

Raises:

Example

>>> status = await client.security_ai_assistant.get_knowledge_base()
>>> print(status.body["elser_exists"])
async setup_knowledge_base(*, resource=None, model_id=None, ignore_security_labs=None, space_id=None, validate_spaces=None)[source]

Set up the Knowledge Base.

POST /api/security_ai_assistant/knowledge_base or POST /api/security_ai_assistant/knowledge_base/{resource} when resource is provided. Installs and starts the ELSER model (if needed) and loads Knowledge Base content. Security Labs docs are installed by default unless ignore_security_labs is True.

Parameters:
  • resource (str | None) – Optional Knowledge Base resource identifier (e.g. security_labs, defend_insights, user) to set up.

  • model_id (str | None) – ELSER model ID to use when setting up the Knowledge Base. If not provided, a default model is used.

  • ignore_security_labs (bool | None) – If True, skip installing Security Labs docs during setup. Defaults to False on the server.

  • space_id (str | None) – Optional space ID to set up the Knowledge Base in.

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

Returns:

ObjectApiResponse with {"success": true} on success.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = await client.security_ai_assistant.setup_knowledge_base(
...     ignore_security_labs=True,
... )
>>> print(result.body["success"])
True
async create_knowledge_base_entry(*, type, name, text=None, source=None, kb_resource=None, required=None, vector=None, index=None, field=None, description=None, query_description=None, input_schema=None, output_fields=None, global_=None, namespace=None, users=None, space_id=None, validate_spaces=None)[source]

Create a Knowledge Base entry.

POST /api/security_ai_assistant/knowledge_base/entries. Creates either a document entry (inline text content) or an index entry (an Elasticsearch index/data stream the assistant may query), depending on type.

Parameters:
  • type (str) – Entry type: document or index.

  • name (str) – Name of the Knowledge Base entry.

  • text (str | None) – Entry content (required for document entries).

  • source (str | None) – Source document name or filepath (required for document entries).

  • kb_resource (str | None) – Knowledge Base resource grouping for the entry: security_labs, defend_insights or user (required for document entries).

  • required (bool | None) – Whether this document resource should always be included in the model context (document entries only, defaults to False).

  • vector (dict[str, Any] | None) – Optional pre-computed embeddings for document entries: {"modelId": ..., "tokens": {...}}.

  • index (str | None) – Index or data stream to query for content (required for index entries).

  • field (str | None) – Field to query for content (required for index entries).

  • description (str | None) – Description of when this index should be queried, passed to the LLM as a tool description (required for index entries).

  • query_description (str | None) – Description of the query field, passed to the LLM as part of the tool input schema (required for index entries).

  • input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for index entries: [{"fieldName": ..., "fieldType": ..., "description": ...}].

  • output_fields (list[str] | None) – Fields to extract from query results for index entries; defaults to all fields.

  • global – Whether the entry is global (visible to all users). Sent as the global body field; defaults to False.

  • namespace (str | None) – Kibana space for the entry, defaults to the default space.

  • users (list[dict[str, Any]] | None) – Users with access to the entry, defaults to the current user. An empty array grants access to all users.

  • space_id (str | None) – Optional space ID to create the entry in.

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

Returns:

ObjectApiResponse with the created Knowledge Base entry, including its server-assigned id.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> entry = await client.security_ai_assistant.create_knowledge_base_entry(
...     type="document",
...     name="Password reset runbook",
...     kb_resource="user",
...     source="/runbooks/password-reset.md",
...     text="To reset a password, open the settings page ...",
... )
>>> print(entry.body["id"])
async get_knowledge_base_entry(*, id, space_id=None, validate_spaces=None)[source]

Get a Knowledge Base entry.

GET /api/security_ai_assistant/knowledge_base/entries/{id}. Retrieves a Knowledge Base entry by its unique ID.

Parameters:
  • id (str) – The unique identifier of the Knowledge Base entry.

  • space_id (str | None) – Optional space ID to get the entry from.

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

Returns:

ObjectApiResponse with the Knowledge Base entry.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> entry = await client.security_ai_assistant.get_knowledge_base_entry(
...     id="12345",
... )
>>> print(entry.body["name"])
async update_knowledge_base_entry(*, id, type, name, text=None, source=None, kb_resource=None, required=None, vector=None, index=None, field=None, description=None, query_description=None, input_schema=None, output_fields=None, global_=None, namespace=None, users=None, space_id=None, validate_spaces=None)[source]

Update a Knowledge Base entry.

PUT /api/security_ai_assistant/knowledge_base/entries/{id}. Replaces an existing Knowledge Base entry. The body follows the same document/index union as create_knowledge_base_entry(), so the type-specific required fields must be provided again.

Parameters:
  • id (str) – The unique identifier of the Knowledge Base entry to update.

  • type (str) – Entry type: document or index.

  • name (str) – Name of the Knowledge Base entry.

  • text (str | None) – Entry content (required for document entries).

  • source (str | None) – Source document name or filepath (required for document entries).

  • kb_resource (str | None) – Knowledge Base resource grouping for the entry: security_labs, defend_insights or user (required for document entries).

  • required (bool | None) – Whether this document resource should always be included in the model context (document entries only).

  • vector (dict[str, Any] | None) – Optional pre-computed embeddings for document entries.

  • index (str | None) – Index or data stream to query for content (required for index entries).

  • field (str | None) – Field to query for content (required for index entries).

  • description (str | None) – Description of when this index should be queried (required for index entries).

  • query_description (str | None) – Description of the query field (required for index entries).

  • input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for index entries.

  • output_fields (list[str] | None) – Fields to extract from query results for index entries.

  • global – Whether the entry is global (visible to all users). Sent as the global body field.

  • namespace (str | None) – Kibana space for the entry.

  • users (list[dict[str, Any]] | None) – Users with access to the entry.

  • space_id (str | None) – Optional space ID to update the entry in.

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

Returns:

ObjectApiResponse with the updated Knowledge Base entry.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> updated = await client.security_ai_assistant.update_knowledge_base_entry(
...     id="12345",
...     type="document",
...     name="Password reset runbook (updated)",
...     kb_resource="user",
...     source="/runbooks/password-reset.md",
...     text="Updated instructions ...",
... )
>>> print(updated.body["name"])
async delete_knowledge_base_entry(*, id, space_id=None, validate_spaces=None)[source]

Delete a Knowledge Base entry.

DELETE /api/security_ai_assistant/knowledge_base/entries/{id}. Deletes a Knowledge Base entry by its unique ID.

Parameters:
  • id (str) – The unique identifier of the Knowledge Base entry to delete.

  • space_id (str | None) – Optional space ID to delete the entry from.

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

Returns:

ObjectApiResponse with the id of the deleted entry.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> await client.security_ai_assistant.delete_knowledge_base_entry(
...     id="12345",
... )
async find_knowledge_base_entries(*, fields=None, filter=None, sort_field=None, sort_order=None, page=None, per_page=None, space_id=None, validate_spaces=None)[source]

Find Knowledge Base entries.

GET /api/security_ai_assistant/knowledge_base/entries/_find. Finds Knowledge Base entries that match the given query, with sorting and pagination.

Parameters:
  • fields (list[str] | None) – A list of fields to include in the response. If not provided, all fields are included.

  • filter (str | None) – Search query to filter entries by specific criteria.

  • sort_field (str | None) – Field to sort by: created_at, is_default, title or updated_at.

  • sort_order (str | None) – Sort order: asc or desc.

  • page (int | None) – Page number (default 1).

  • per_page (int | None) – Entries per page (default 20).

  • space_id (str | None) – Optional space ID to search entries in.

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

Returns:

ObjectApiResponse with page, perPage, total and the data array of Knowledge Base entries.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> found = await client.security_ai_assistant.find_knowledge_base_entries(
...     per_page=50,
... )
>>> print(found.body["total"])
async bulk_action_knowledge_base_entries(*, create=None, update=None, delete=None, space_id=None, validate_spaces=None)[source]

Apply a bulk action to Knowledge Base entries.

POST /api/security_ai_assistant/knowledge_base/entries/_bulk_action. Creates, updates and/or deletes multiple Knowledge Base entries in a single request. The delete action is applied to all entries matching the filter query or to the listed entry IDs.

Parameters:
  • create (list[dict[str, Any]] | None) – List of entries to create. Each item follows the same document/index union as create_knowledge_base_entry() (e.g. {"type": "document", "name": ..., "kbResource": ..., "source": ..., "text": ...}).

  • update (list[dict[str, Any]] | None) – List of entry updates. Each item requires id plus the entry fields to change.

  • delete (dict[str, Any] | None) – Deletion criteria: {"ids": [...]} and/or {"query": "..."}.

  • space_id (str | None) – Optional space ID to apply the bulk action in.

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

Returns:

ObjectApiResponse with success, knowledgeBaseEntriesCount and an attributes object holding per-action results (created, updated, deleted, skipped) and a summary.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> result = await client.security_ai_assistant.bulk_action_knowledge_base_entries(
...     delete={"ids": ["123", "456"]},
... )
>>> print(result.body["attributes"]["summary"]["succeeded"])
async chat_complete(*, connector_id, messages, persist, conversation_id=None, is_stream=None, lang_smith_api_key=None, lang_smith_project=None, model=None, prompt_id=None, response_language=None, content_references_disabled=None, space_id=None, validate_spaces=None)[source]

Create a model response for a chat conversation.

POST /api/security_ai_assistant/chat/complete. Sends the chat messages to the LLM behind the given Kibana AI connector and returns the model response. Depending on the model and local setup this call can take a while; consider raising the request timeout via client.options(request_timeout=...).

Parameters:
  • connector_id (str) – Kibana AI connector ID used to route the request (e.g. a .gen-ai connector).

  • messages (list[dict[str, Any]]) – List of chat messages exchanged so far. Each message requires role (system, user or assistant) and typically content; optional data and fields_to_anonymize attach anonymizable metadata.

  • persist (bool) – Whether to persist the chat and response as a Security AI Assistant conversation.

  • conversation_id (str | None) – Existing conversation ID to continue (used with persist=True).

  • is_stream (bool | None) – If True, the response is streamed in chunks (application/octet-stream) instead of a single JSON object.

  • lang_smith_api_key (str | None) – API key for LangSmith integration.

  • lang_smith_project (str | None) – LangSmith project name for tracing.

  • model (str | None) – Model ID or name to use for the response (overrides the connector’s default model).

  • prompt_id (str | None) – Prompt template identifier.

  • response_language (str | None) – ISO language code for the assistant’s response.

  • content_references_disabled (bool | None) – If True, the response will not include content references (sent as the content_references_disabled query parameter).

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

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

Returns:

ObjectApiResponse with the model response. For non-streaming calls the body contains connector_id, data (the response text), replacements, trace_data and status.

Raises:
Return type:

ObjectApiResponse[Any]

Example

>>> response = await client.options(request_timeout=120).security_ai_assistant.chat_complete(
...     connector_id="my-openai-connector",
...     messages=[
...         {"role": "user", "content": "What are common phishing techniques?"},
...     ],
...     persist=False,
... )
>>> print(response.body["data"])
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]