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.
- Authentication and privileges
- Start an investigation:
POST /api/tocharian_ai/investigations - Get an investigation:
GET /api/tocharian_ai/investigations/{id} - The investigation object
- Errors
- Example: investigate from an alerting rule
- Workflows step (Kibana 9.5 and later)
Available in every edition. Investigations started through the API are always read-only. Masking applies as it does in chat.
Authentication and privileges
Section titled “Authentication and privileges”Requests use Kibana’s own authentication: basic authentication or an Elasticsearch API key.
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>| Requirement | Detail |
|---|---|
| Kibana feature privilege | Tocharian AI read or all in the space of the request |
| Data access | The caller’s own Elasticsearch and Kibana privileges. The investigation sees only what the caller could see in Kibana. |
kbn-xsrf header | Required on POST, any value |
| Space | Requests without a space prefix use the default space. For another space, prefix the path: /s/<space id>/api/tocharian_ai/investigations |
| Owner | An 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. |
| Model | The default model, unless the request names another one in model |
Start an investigation
Section titled “Start an investigation”POST /api/tocharian_ai/investigationsStarts 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.
Request body
Section titled “Request body”| Field | Type | Default | Description |
|---|---|---|---|
question | string, 1–8000 characters | required | The question, in plain language. The answer is in the language of the question. |
id | string | none | Id of an earlier investigation of the caller, in the same space, to ask a follow-up. If none is found, a new investigation starts. |
wait | number, 0–300 | 0 | Seconds to wait for the answer. 0 returns at once with "status": "running". |
deep | boolean | true | true: 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. |
model | string, up to 64 characters | the default model | Id of a saved model. Users with read can name models shared with users; users with all can name any saved model. |
skill | auto, security, observability, analysis or platform | auto | Working mode. auto takes it from the page in context, else analysis (data analysis). |
context | object | none | Page context, as the browser sends it from a Kibana page. See below. |
Fields of context that are useful from automation (all optional):
| Field | Type | Description |
|---|---|---|
timeRange | object { "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. |
timeZone | string | IANA time zone for times in the answer, such as Europe/Berlin |
route | string | A Kibana app route such as /app/security/alerts. Sets the working mode for auto and the page whose data is loaded. |
query | string | The KQL query the user would have on screen |
dataView | object { "title": string, "timeField": string } | The data view in focus |
Example
Section titled “Example”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 an investigation
Section titled “Get an investigation”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 parameter | Type | Description |
|---|---|---|
id | string | The id returned when the investigation started |
curl -s -u elastic:<password> http://localhost:5601/api/tocharian_ai/investigations/<investigation id>Poll every few seconds until status is no longer running.
The investigation object
Section titled “The investigation object”Both endpoints return the same object. It describes the latest question of the investigation.
| Field | Type | Description |
|---|---|---|
id | string | Investigation id. Pass it as id to ask a follow-up. |
question | string | The latest question |
status | string | running, done, error or interrupted (Kibana restarted during the run; ask again) |
runId | string | Id of the latest run |
answer | string, Markdown | The answer, with references such as [E1] to its evidence. Present when status is done or error. Masked values appear as real values. |
evidence | array | Queries the answer relies on. Present when status is done. |
evidence[].id | string | Reference used in the answer, such as E1 |
evidence[].language | string | ES|QL, Query DSL, panel or API |
evidence[].dataset | string | Dataset the query ran on |
evidence[].query | string | The query as it ran |
evidence[].hits | number | Hit or row count |
evidence[].purpose | string | What the query was for |
evidence[].timeFilter | string | The time range the plugin added, as <field>: <from> → <to>, when the query had none of its own |
pendingChanges | array | Proposed changes waiting for confirmation: id, kind, summary. Always empty for API runs, which are read-only. |
meta | object | Details of the latest answer, below. Absent until the first answer is written. |
updatedAt | string, ISO 8601 | Last change of the investigation |
meta field | Type | Description |
|---|---|---|
model | string | Model that answered |
fallback | boolean | true when the fallback model finished the answer |
llmCalls | number | Model calls |
queries | number | Queries run |
ms | number | Duration in milliseconds |
mode | string | ro (read-only) |
error | string | Why the run failed, when status is error |
tokensIn, tokensOut | number | Tokens sent and received |
costUsd | number | Estimated cost, when the model has prices |
masked | number | Values masked before they were sent to the model |
runId | string | Run id |
kind | string | api for deep: true, chat for deep: false |
skills | array of strings | Working modes used: security, observability, analysis, platform |
Errors
Section titled “Errors”Errors use Kibana’s error format:
{ "statusCode": 409, "error": "Conflict", "message": "A question is still being answered in this conversation." }| Status | When | Fix |
|---|---|---|
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. |
400 | The body does not match the schema, such as an empty question or wait above 300. The message names the field. | Correct the request. |
401 | Not authenticated | Send basic authentication or an API key. |
403 | The caller has no Tocharian AI feature privilege in this space | Give the role Tocharian AI read. |
404 | GET: no investigation with this id for the caller in this space | Use the caller and space that started it. |
409 | POST with id: a question is still running in that investigation, or it changed meanwhile | Wait for status to leave running, then ask again. |
500 | This 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.
-
Allow Kibana to call itself: add
localhosttoxpack.actions.allowedHostsinkibana.yml, if you restrict hosts. -
In Stack Management → Connectors, create a Webhook connector:
Field Value Method POSTURL http://localhost:5601/api/tocharian_ai/investigationsAuthentication Basic, with a user that has Tocharian AI readand read access to the dataHeaders kbn-xsrf: true,Content-Type: application/json -
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.
Workflows step
Section titled “Workflows step”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.
Inputs
Section titled “Inputs”| Input | Type | Default | Description |
|---|---|---|---|
question | string, 1–8000 characters | required | What to investigate, in plain language |
data | any | none | Data 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_range | object { "from": string, "to": string } | none | Time 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. |
model | string, up to 64 characters | the default model | Id of a saved model |
deep | boolean | true | Structured report with more steps; false for a normal question |
investigation_id | string | none | Continue an earlier investigation (its id) of the same user and space. If none is found, a new investigation starts. |
Outputs
Section titled “Outputs”| Output | Type | Description |
|---|---|---|
id | string | Investigation id. Pass it as investigation_id to ask a follow-up. |
status | string | done |
answer | string, Markdown | The answer |
evidence | array | Queries the answer is based on: id, language, dataset, query, hits, purpose, time_filter |
model | string | Model that answered |
fallback | boolean | true when the fallback model finished the answer |
pending_changes | number | Proposed changes waiting for confirmation; always 0, the step is read-only |
time_range | object | The time_range input as absolute UTC times |
url | string | Link to the investigation in Kibana: a full URL when server.publicBaseUrl is set, else a path |
report | string, Markdown | The 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]Step errors
Section titled “Step errors”The step fails with a message that starts with Tocharian AI::
| Message | Fix |
|---|---|
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 message | The answer’s error, for example when the model cannot be reached. |