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:
NamespaceClientClient 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_idto target a specific space (Nonetargets 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
_findand_bulk_actionendpoints:# 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_completeroutes 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:
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"}.connectorIdandactionTypeIdare required inside this object when it is provided.category (str | None) – The conversation category:
assistantorinsights.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,userorassistant) andtimestamp(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,createdByandusers.- Raises:
BadRequestError – If required parameters are missing or invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with the conversation details (
id,title,messages,apiConfig,users, …).- Raises:
NotFoundError – If the conversation does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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
idvalue.api_config (dict[str, Any] | None) – Updated LLM API configuration (
connectorIdandactionTypeIdare required inside this object when it is provided).category (str | None) – Updated conversation category:
assistantorinsights. 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,roleandtimestamp.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:
NotFoundError – If the conversation does not exist.
BadRequestError – If the update payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with an empty object body on success.
- Raises:
NotFoundError – If the conversation does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,titleorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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,totaland thedataarray of conversations.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 inexcluded_idsare kept.- Parameters:
- Returns:
ObjectApiResponse with
success,totalDeletedandfailures.- Raises:
BadRequestError – If the request body is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,nameorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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,totaland thedataarray of prompts.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,contentandpromptType(systemorquick). 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
idplus 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_countand anattributesobject holding per-actionresults(created,updated,deleted,skipped) and asummary.- Raises:
BadRequestError – If the bulk action payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,fieldorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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, thedataarray, optionalallarray andaggregations.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 optionallyallowedandanonymizedbooleans.update (list[dict[str, Any]] | None) – List of anonymization field updates. Each item requires
idplus theallowed/anonymizedflags 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_countand anattributesobject holding per-actionresults(created,updated,deleted,skipped) and asummary.- Raises:
BadRequestError – If the bulk action payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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_baseorGET /api/security_ai_assistant/knowledge_base/{resource}whenresourceis 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_existsandproduct_documentation_status.- Return type:
ObjectApiResponse with status flags
- Raises:
BadRequestError – If the request is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
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_baseorPOST /api/security_ai_assistant/knowledge_base/{resource}whenresourceis provided. Installs and starts the ELSER model (if needed) and loads Knowledge Base content. Security Labs docs are installed by default unlessignore_security_labsis 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:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 adocumententry (inline text content) or anindexentry (an Elasticsearch index/data stream the assistant may query), depending ontype.- Parameters:
type (str) – Entry type:
documentorindex.name (str) – Name of the Knowledge Base entry.
text (str | None) – Entry content (required for
documententries).source (str | None) – Source document name or filepath (required for
documententries).kb_resource (str | None) – Knowledge Base resource grouping for the entry:
security_labs,defend_insightsoruser(required fordocumententries).required (bool | None) – Whether this document resource should always be included in the model context (
documententries only, defaults to False).vector (dict[str, Any] | None) – Optional pre-computed embeddings for
documententries:{"modelId": ..., "tokens": {...}}.index (str | None) – Index or data stream to query for content (required for
indexentries).field (str | None) – Field to query for content (required for
indexentries).description (str | None) – Description of when this index should be queried, passed to the LLM as a tool description (required for
indexentries).query_description (str | None) – Description of the query field, passed to the LLM as part of the tool input schema (required for
indexentries).input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for
indexentries:[{"fieldName": ..., "fieldType": ..., "description": ...}].output_fields (list[str] | None) – Fields to extract from query results for
indexentries; defaults to all fields.global – Whether the entry is global (visible to all users). Sent as the
globalbody field; defaults to False.namespace (str | None) – Kibana space for the entry, defaults to the
defaultspace.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:
BadRequestError – If required fields for the entry type are missing or invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with the Knowledge Base entry.
- Raises:
NotFoundError – If the entry does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 samedocument/indexunion ascreate_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:
documentorindex.name (str) – Name of the Knowledge Base entry.
text (str | None) – Entry content (required for
documententries).source (str | None) – Source document name or filepath (required for
documententries).kb_resource (str | None) – Knowledge Base resource grouping for the entry:
security_labs,defend_insightsoruser(required fordocumententries).required (bool | None) – Whether this document resource should always be included in the model context (
documententries only).vector (dict[str, Any] | None) – Optional pre-computed embeddings for
documententries.index (str | None) – Index or data stream to query for content (required for
indexentries).field (str | None) – Field to query for content (required for
indexentries).description (str | None) – Description of when this index should be queried (required for
indexentries).query_description (str | None) – Description of the query field (required for
indexentries).input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for
indexentries.output_fields (list[str] | None) – Fields to extract from query results for
indexentries.global – Whether the entry is global (visible to all users). Sent as the
globalbody 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:
NotFoundError – If the entry does not exist.
BadRequestError – If the update payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with the
idof the deleted entry.- Raises:
NotFoundError – If the entry does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,titleorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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,totaland thedataarray of Knowledge Base entries.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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/indexunion ascreate_knowledge_base_entry()(e.g.{"type": "document", "name": ..., "kbResource": ..., "source": ..., "text": ...}).update (list[dict[str, Any]] | None) – List of entry updates. Each item requires
idplus 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,knowledgeBaseEntriesCountand anattributesobject holding per-actionresults(created,updated,deleted,skipped) and asummary.- Raises:
BadRequestError – If the bulk action payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 viaclient.options(request_timeout=...).- Parameters:
connector_id (str) – Kibana AI connector ID used to route the request (e.g. a
.gen-aiconnector).messages (list[dict[str, Any]]) – List of chat messages exchanged so far. Each message requires
role(system,userorassistant) and typicallycontent; optionaldataandfields_to_anonymizeattach 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_disabledquery 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_dataandstatus.- Raises:
BadRequestError – If the request payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
ApiError – If the connector call to the model fails.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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"])
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:
AsyncNamespaceClientAsync 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_idto target a specific space (Nonetargets 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"}.connectorIdandactionTypeIdare required inside this object when it is provided.category (str | None) – The conversation category:
assistantorinsights.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,userorassistant) andtimestamp(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,createdByandusers.- Raises:
BadRequestError – If required parameters are missing or invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with the conversation details (
id,title,messages,apiConfig,users, …).- Raises:
NotFoundError – If the conversation does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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
idvalue.api_config (dict[str, Any] | None) – Updated LLM API configuration (
connectorIdandactionTypeIdare required inside this object when it is provided).category (str | None) – Updated conversation category:
assistantorinsights. 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,roleandtimestamp.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:
NotFoundError – If the conversation does not exist.
BadRequestError – If the update payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with an empty object body on success.
- Raises:
NotFoundError – If the conversation does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,titleorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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,totaland thedataarray of conversations.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 inexcluded_idsare kept.- Parameters:
- Returns:
ObjectApiResponse with
success,totalDeletedandfailures.- Raises:
BadRequestError – If the request body is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,nameorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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,totaland thedataarray of prompts.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,contentandpromptType(systemorquick). 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
idplus 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_countand anattributesobject holding per-actionresults(created,updated,deleted,skipped) and asummary.- Raises:
BadRequestError – If the bulk action payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,fieldorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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, thedataarray, optionalallarray andaggregations.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 optionallyallowedandanonymizedbooleans.update (list[dict[str, Any]] | None) – List of anonymization field updates. Each item requires
idplus theallowed/anonymizedflags 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_countand anattributesobject holding per-actionresults(created,updated,deleted,skipped) and asummary.- Raises:
BadRequestError – If the bulk action payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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_baseorGET /api/security_ai_assistant/knowledge_base/{resource}whenresourceis 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_existsandproduct_documentation_status.- Return type:
ObjectApiResponse with status flags
- Raises:
BadRequestError – If the request is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
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_baseorPOST /api/security_ai_assistant/knowledge_base/{resource}whenresourceis provided. Installs and starts the ELSER model (if needed) and loads Knowledge Base content. Security Labs docs are installed by default unlessignore_security_labsis 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:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 adocumententry (inline text content) or anindexentry (an Elasticsearch index/data stream the assistant may query), depending ontype.- Parameters:
type (str) – Entry type:
documentorindex.name (str) – Name of the Knowledge Base entry.
text (str | None) – Entry content (required for
documententries).source (str | None) – Source document name or filepath (required for
documententries).kb_resource (str | None) – Knowledge Base resource grouping for the entry:
security_labs,defend_insightsoruser(required fordocumententries).required (bool | None) – Whether this document resource should always be included in the model context (
documententries only, defaults to False).vector (dict[str, Any] | None) – Optional pre-computed embeddings for
documententries:{"modelId": ..., "tokens": {...}}.index (str | None) – Index or data stream to query for content (required for
indexentries).field (str | None) – Field to query for content (required for
indexentries).description (str | None) – Description of when this index should be queried, passed to the LLM as a tool description (required for
indexentries).query_description (str | None) – Description of the query field, passed to the LLM as part of the tool input schema (required for
indexentries).input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for
indexentries:[{"fieldName": ..., "fieldType": ..., "description": ...}].output_fields (list[str] | None) – Fields to extract from query results for
indexentries; defaults to all fields.global – Whether the entry is global (visible to all users). Sent as the
globalbody field; defaults to False.namespace (str | None) – Kibana space for the entry, defaults to the
defaultspace.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:
BadRequestError – If required fields for the entry type are missing or invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with the Knowledge Base entry.
- Raises:
NotFoundError – If the entry does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 samedocument/indexunion ascreate_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:
documentorindex.name (str) – Name of the Knowledge Base entry.
text (str | None) – Entry content (required for
documententries).source (str | None) – Source document name or filepath (required for
documententries).kb_resource (str | None) – Knowledge Base resource grouping for the entry:
security_labs,defend_insightsoruser(required fordocumententries).required (bool | None) – Whether this document resource should always be included in the model context (
documententries only).vector (dict[str, Any] | None) – Optional pre-computed embeddings for
documententries.index (str | None) – Index or data stream to query for content (required for
indexentries).field (str | None) – Field to query for content (required for
indexentries).description (str | None) – Description of when this index should be queried (required for
indexentries).query_description (str | None) – Description of the query field (required for
indexentries).input_schema (list[dict[str, Any]] | None) – Optional input-schema field definitions for
indexentries.output_fields (list[str] | None) – Fields to extract from query results for
indexentries.global – Whether the entry is global (visible to all users). Sent as the
globalbody 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:
NotFoundError – If the entry does not exist.
BadRequestError – If the update payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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:
- Returns:
ObjectApiResponse with the
idof the deleted entry.- Raises:
NotFoundError – If the entry does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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,titleorupdated_at.sort_order (str | None) – Sort order:
ascordesc.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,totaland thedataarray of Knowledge Base entries.- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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/indexunion ascreate_knowledge_base_entry()(e.g.{"type": "document", "name": ..., "kbResource": ..., "source": ..., "text": ...}).update (list[dict[str, Any]] | None) – List of entry updates. Each item requires
idplus 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,knowledgeBaseEntriesCountand anattributesobject holding per-actionresults(created,updated,deleted,skipped) and asummary.- Raises:
BadRequestError – If the bulk action payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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 viaclient.options(request_timeout=...).- Parameters:
connector_id (str) – Kibana AI connector ID used to route the request (e.g. a
.gen-aiconnector).messages (list[dict[str, Any]]) – List of chat messages exchanged so far. Each message requires
role(system,userorassistant) and typicallycontent; optionaldataandfields_to_anonymizeattach 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_disabledquery 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_dataandstatus.- Raises:
BadRequestError – If the request payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
ApiError – If the connector call to the model fails.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
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"])