Skip to content

API

For developers and administrators who automate Tocharian AI. This page describes the investigations API, which starts a read-only investigation from a script, an alerting rule or any HTTP client and returns the answer with its evidence, and the Elastic Workflows step built on it.

Available in every edition. Investigations started through the API are always read-only. Masking applies as it does in chat.

Requests use Kibana’s own authentication: basic authentication or an Elasticsearch API key.

Terminal window
curl -u elastic:<password> http://localhost:5601/api/tocharian_ai/investigations/<id>
curl -H "Authorization: ApiKey <base64 id:api_key>" http://localhost:5601/api/tocharian_ai/investigations/<id>
RequirementDetail
Kibana feature privilegeTocharian AI read or all in the space of the request
Data accessThe caller’s own Elasticsearch and Kibana privileges. The investigation sees only what the caller could see in Kibana.
kbn-xsrf headerRequired on POST, any value
SpaceRequests without a space prefix use the default space. For another space, prefix the path: /s/<space id>/api/tocharian_ai/investigations
OwnerAn investigation belongs to the caller, as a user in a realm. With an API key, it belongs to the user who created the key, and it appears in that user’s conversations in the Tocharian AI app.
ModelThe default model, unless the request names another one in model
POST /api/tocharian_ai/investigations

Starts a question as a run on the Kibana server and, if wait is above 0, waits for the answer. The run continues when the client disconnects.

FieldTypeDefaultDescription
questionstring, 1–8000 charactersrequiredThe question, in plain language. The answer is in the language of the question.
idstringnoneId of an earlier investigation of the caller, in the same space, to ask a follow-up. If none is found, a new investigation starts.
waitnumber, 0–3000Seconds to wait for the answer. 0 returns at once with "status": "running".
deepbooleantruetrue: a background investigation with up to 16 steps and 15 minutes, answered as a structured report. false: a normal question, up to 8 steps and 5 minutes.
modelstring, up to 64 charactersthe default modelId of a saved model. Users with read can name models shared with users; users with all can name any saved model.
skillauto, security, observability, analysis or platformautoWorking mode. auto takes it from the page in context, else analysis (data analysis).
contextobjectnonePage context, as the browser sends it from a Kibana page. See below.

Fields of context that are useful from automation (all optional):

FieldTypeDescription
timeRangeobject { "from": string, "to": string }Time window for queries that set none of their own. Kibana date math (now-1h) or ISO 8601 times. Without it, queries cover the last Default time range cap days of datasets with recent data.
timeZonestringIANA time zone for times in the answer, such as Europe/Berlin
routestringA Kibana app route such as /app/security/alerts. Sets the working mode for auto and the page whose data is loaded.
querystringThe KQL query the user would have on screen
dataViewobject { "title": string, "timeField": string }The data view in focus
Terminal window
curl -s -u elastic:<password> \
-H 'kbn-xsrf: true' -H 'Content-Type: application/json' \
-X POST http://localhost:5601/api/tocharian_ai/investigations \
-d '{
"question": "Which hosts in kibana_sample_data_logs returned the most 503 responses, and since when?",
"context": { "timeRange": { "from": "now-24h", "to": "now" } },
"deep": false,
"wait": 120
}'

Response 200 (abridged; the queries depend on the model):

{
"id": "<investigation id>",
"question": "Which hosts in kibana_sample_data_logs returned the most 503 responses, and since when?",
"status": "done",
"runId": "<run id>",
"answer": "Most 503 responses came from … [E1]",
"evidence": [
{
"id": "E1",
"language": "ES|QL",
"dataset": "kibana_sample_data_logs",
"query": "FROM kibana_sample_data_logs | WHERE … | STATS … BY host",
"hits": 4,
"purpose": "503 responses by host",
"timeFilter": "timestamp: now-24h → now"
}
],
"pendingChanges": [],
"meta": {
"model": "<model name>",
"llmCalls": 3,
"queries": 2,
"ms": 14230,
"mode": "ro",
"tokensIn": 18422,
"tokensOut": 611,
"masked": 0,
"runId": "<run id>",
"kind": "chat",
"skills": ["analysis"]
},
"updatedAt": "2026-08-29T09:15:02.481Z"
}

To start without waiting, send "wait": 0 and get the investigation later.

GET /api/tocharian_ai/investigations/{id}

Returns the current state of an investigation of the caller, in the space of the request. A run that stopped updating because Kibana restarted is reported as interrupted.

Path parameterTypeDescription
idstringThe id returned when the investigation started
Terminal window
curl -s -u elastic:<password> http://localhost:5601/api/tocharian_ai/investigations/<investigation id>

Poll every few seconds until status is no longer running.

Both endpoints return the same object. It describes the latest question of the investigation.

FieldTypeDescription
idstringInvestigation id. Pass it as id to ask a follow-up.
questionstringThe latest question
statusstringrunning, done, error or interrupted (Kibana restarted during the run; ask again)
runIdstringId of the latest run
answerstring, MarkdownThe answer, with references such as [E1] to its evidence. Present when status is done or error. Masked values appear as real values.
evidencearrayQueries the answer relies on. Present when status is done.
evidence[].idstringReference used in the answer, such as E1
evidence[].languagestringES|QL, Query DSL, panel or API
evidence[].datasetstringDataset the query ran on
evidence[].querystringThe query as it ran
evidence[].hitsnumberHit or row count
evidence[].purposestringWhat the query was for
evidence[].timeFilterstringThe time range the plugin added, as <field>: <from> → <to>, when the query had none of its own
pendingChangesarrayProposed changes waiting for confirmation: id, kind, summary. Always empty for API runs, which are read-only.
metaobjectDetails of the latest answer, below. Absent until the first answer is written.
updatedAtstring, ISO 8601Last change of the investigation
meta fieldTypeDescription
modelstringModel that answered
fallbackbooleantrue when the fallback model finished the answer
llmCallsnumberModel calls
queriesnumberQueries run
msnumberDuration in milliseconds
modestringro (read-only)
errorstringWhy the run failed, when status is error
tokensIn, tokensOutnumberTokens sent and received
costUsdnumberEstimated cost, when the model has prices
maskednumberValues masked before they were sent to the model
runIdstringRun id
kindstringapi for deep: true, chat for deep: false
skillsarray of stringsWorking modes used: security, observability, analysis, platform

Errors use Kibana’s error format:

{ "statusCode": 409, "error": "Conflict", "message": "A question is still being answered in this conversation." }
StatusWhenFix
200 with "status": "error"The run failed, for example because the model could not be reached. meta.error and answer say why.Check the model with Test connection in the settings page.
400The body does not match the schema, such as an empty question or wait above 300. The message names the field.Correct the request.
401Not authenticatedSend basic authentication or an API key.
403The caller has no Tocharian AI feature privilege in this spaceGive the role Tocharian AI read.
404GET: no investigation with this id for the caller in this spaceUse the caller and space that started it.
409POST with id: a question is still running in that investigation, or it changed meanwhileWait for status to leave running, then ask again.
500This model is not available.: model names an unknown model, or one the caller may not pick. Other server errors carry their message.Use a model id from the settings page, or leave model out.

Example: investigate from an alerting rule

Section titled “Example: investigate from an alerting rule”

A Webhook connector can start an investigation every time a rule fires. The answer then waits in the conversations of the connector’s user.

  1. Allow Kibana to call itself: add localhost to xpack.actions.allowedHosts in kibana.yml, if you restrict hosts.

  2. In Stack Management → Connectors, create a Webhook connector:

    FieldValue
    MethodPOST
    URLhttp://localhost:5601/api/tocharian_ai/investigations
    AuthenticationBasic, with a user that has Tocharian AI read and read access to the data
    Headerskbn-xsrf: true, Content-Type: application/json
  3. Add the connector as an action of the rule, with this body:

    {
    "question": "The rule {{rule.name}} fired at {{date}}. What happened in the data shortly before, and what is the likely cause?",
    "context": { "timeRange": { "from": "now-1h", "to": "now" } },
    "wait": 0
    }

"wait": 0 returns at once, so the connector does not time out. Open the Tocharian AI app as the connector’s user to read the report.

Kibana 9.5 and later. The step tocharian-ai.investigate asks Tocharian AI a question inside an Elastic Workflow, waits for the answer and hands it to the next steps. It appears under AI in the workflow editor’s actions menu.

The step runs inside Kibana, not over HTTP, as the user the workflow runs as: that user needs Tocharian AI read in the workflow’s space, and their Elasticsearch privileges apply. Investigations are read-only, and masking, activity records and the configured models apply. The step checks for the answer every 4 seconds and gives up after about 15 minutes.

InputTypeDefaultDescription
questionstring, 1–8000 charactersrequiredWhat to investigate, in plain language
dataanynoneData for the question, such as the alert that started the workflow. Sent as JSON after the question; the whole text is cut to 8,000 characters.
time_rangeobject { "from": string, "to": string }noneTime range to look at: Kibana date math, rounded in UTC, or ISO times. Fixed to absolute UTC times when the step starts, so every query and follow-up covers the same window.
modelstring, up to 64 charactersthe default modelId of a saved model
deepbooleantrueStructured report with more steps; false for a normal question
investigation_idstringnoneContinue an earlier investigation (its id) of the same user and space. If none is found, a new investigation starts.
OutputTypeDescription
idstringInvestigation id. Pass it as investigation_id to ask a follow-up.
statusstringdone
answerstring, MarkdownThe answer
evidencearrayQueries the answer is based on: id, language, dataset, query, hits, purpose, time_filter
modelstringModel that answered
fallbackbooleantrue when the fallback model finished the answer
pending_changesnumberProposed changes waiting for confirmation; always 0, the step is read-only
time_rangeobjectThe time_range input as absolute UTC times
urlstringLink to the investigation in Kibana: a full URL when server.publicBaseUrl is set, else a path
reportstring, MarkdownThe answer, the time range, every evidence query and the link: ready for a case, an e-mail or a chat message

Example: investigate an alert and open a case

Section titled “Example: investigate an alert and open a case”
steps:
- name: investigate
type: tocharian-ai.investigate
with:
question: "Why did this alert fire, and what is the likely cause?"
data: "${{ event }}"
time_range: { from: "now-1h", to: "now" }
- name: open_case
type: kibana.createCase
with:
title: "AI investigation: ${{ event.rule.name }}"
description: "${{ steps.investigate.output.report }}"
owner: cases
tags: [tocharian-ai]

The step fails with a message that starts with Tocharian AI::

MessageFix
user <user> has no Tocharian AI privilege in space <space>Give the workflow’s user Tocharian AI read in that space.
time_range.from "<value>" is not a valid time …, time_range.from (…) is after time_range.to (…)Use date math such as now-1h, or ISO times, with from before to.
This model is not available.Use the id of a model the user may pick, or leave model out.
the investigation was interrupted (Kibana restarted)Run the workflow again.
Any other messageThe answer’s error, for example when the model cannot be reached.