Skip to content

Session Ended Event

When an AI session started by your organization ends, LimaCharlie writes one ai_session_ended event into your organization's event stream. You can forward it with an Output to your SIEM, a bucket or a webhook. You can also match it in a D&R rule.

There is nothing to enable. The event is on by default for every organization. See Where the event appears to turn it off.

When it is emitted

The event is sent once for every org session, whatever the reason it ended. The end_reason field says which reason it was. See the End Reasons table for the values.

"Org session" means a session started by a D&R rule, the API, the CLI or another LimaCharlie feature. Chats that people start in the web console are personal to the user and do not produce this event.

The event is delivered at least once. In rare cases you can receive it twice for the same session. Use session_id to de-duplicate. Delivery does not slow down the end of the session. If a delivery fails, LimaCharlie retries for about a day, so an event can arrive some time after the session ended.

The event contains a summary and the final message. It does not contain the conversation, secrets or environment values. To read the conversation, use history_api_path, or download the full transcript.

Where the event appears

The first time one of your sessions ends, LimaCharlie creates a webhook adapter named ai-sessions in your organization. It is a record in the cloud_sensor Hive, with its own installation key and the lc:system tag. You do not configure it and you do not send anything to it. Events from it appear as a sensor with the hostname ai-sessions, so you can find them in the Timeline and in search, match them in D&R rules with event: ai_session_ended, and forward them with an Output on the event stream.

To stop the event, disable the ai-sessions record in the cloud_sensor Hive. LimaCharlie leaves a disabled record alone. If you delete the record instead, it is created again the next time a session ends.

Fields

Every field is always present. A value that is not known is null.

Field Description
event_type Always ai_session_ended.
session_id The session ID. Use it as the de-duplication key.
agent_name Name of the ai_agent record the session ran, for sessions started by a D&R rule in definition mode (definition: hive://ai_agent/<name>). null otherwise, including D&R rules in inline mode and sessions started through the API or CLI, which send the agent's definition rather than its name.
session_type The kind of session.
trigger What started the session. See below.
started_by The user email or the API key name that started the session.
created_at When the session was created (RFC 3339).
started_at When the session started running (RFC 3339).
ended_at When the session ended (RFC 3339).
status The final status.
end_reason Why the session ended. See End Reasons.
end_error A short error message when the session ended abnormally.
model The model used.
provider The AI provider used.
input_tokens Input tokens used.
output_tokens Output tokens used.
cost_usd Cost of the session in USD.
message_count Number of messages in the conversation.
final_message The last text answer from the assistant, cut to 32 KiB.
final_message_truncated true when final_message was cut.
history_truncated true when older messages are not in the history endpoint's response. Use the full download to get everything.
history_api_path Path to read the session history: /v1/org/sessions/<session_id>/history.

trigger is an object:

Field Description
kind dr_rule for a D&R rule, cli for the LimaCharlie CLI or Python SDK, and api for any other API call. Sessions started by another LimaCharlie feature carry that feature's name.
rule_name The D&R rule that started the session, when kind is dr_rule.
detect_id The detection ID, when the caller recorded one. It is null for sessions started by a D&R rule today.

Sample

{
  "event_type": "ai_session_ended",
  "session_id": "3f6c2a1e-0000-0000-0000-000000000000",
  "agent_name": "detection-investigator",
  "session_type": "api",
  "trigger": {
    "kind": "dr_rule",
    "rule_name": "encoded-powershell-command",
    "detect_id": null
  },
  "started_by": "triage-bot-key",
  "created_at": "2026-12-01T10:30:00Z",
  "started_at": "2026-12-01T10:30:05Z",
  "ended_at": "2026-12-01T10:41:52Z",
  "status": "ended",
  "end_reason": "completed",
  "end_error": null,
  "model": "claude-sonnet-4-6",
  "provider": "anthropic",
  "input_tokens": 184200,
  "output_tokens": 9120,
  "cost_usd": 0.69,
  "message_count": 57,
  "final_message": "The encoded command downloads and runs a second stage from ...",
  "final_message_truncated": false,
  "history_truncated": false,
  "history_api_path": "/v1/org/sessions/3f6c2a1e-0000-0000-0000-000000000000/history"
}

Forward it with an Output

Create an Output on the event stream and keep only this event type. This example sends every ai_session_ended event to a webhook:

name: ai-session-ended-to-webhook
module: webhook
type: event
event_white_list: |
  ai_session_ended
dest_host: https://hooks.example.com/ai-sessions

Use any other Output module the same way, for example S3, GCS or BigQuery, to keep a long-term record of your sessions. See Outputs.

Match it in a D&R rule

This rule raises a detection when a session ended with an error:

detect:
  event: ai_session_ended
  op: exists
  path: event/end_error
  truthy: true

respond:
  - action: report
    name: ai-session-failed
    metadata:
      session_id: "{{ .detect.event.session_id }}"
      end_error: "{{ .detect.event.end_error }}"

This rule flags sessions that cost more than 5 USD:

detect:
  event: ai_session_ended
  op: is greater than
  path: event/cost_usd
  value: 5

respond:
  - action: report
    name: ai-session-expensive

Typical uses

  • Keep a record of every AI investigation for audit, beyond the 90 days of retention.
  • Send the final_message of each session to a chat channel or a ticket.
  • Alert on sessions that fail or time out. Match end_reason values such as failed, max_duration_exceeded or startup_timeout.
  • Alert on sessions that cost more than you expect, with cost_usd.
  • Track cost per agent or per rule across your organization.