---
title: "AI post-prompt callback"
method: POST
path: "aiPostPromptCallback"
tags: ["AI Webhooks"]
---

# AI post-prompt callback

`POST aiPostPromptCallback` (webhook)

Sent to your [`ai.post_prompt_url`](/docs/swml/reference/calling/ai) when the AI session ends. It
carries the agent's answer to your [`post_prompt`](/docs/swml/reference/calling/ai)
alongside the full record of the call: the conversation, the tool calls, the timings, and the
token counts. This is the one report you get per call, so store the body verbatim and extract only
the fields you query. Nothing you return in the response is read.

Read `action` first. It is `post_conversation` on the end-of-call report described here. The same
URL also receives `fetch_conversation` when the agent starts with a stored conversation
([`save_conversation`](/docs/swml/reference/calling/ai/params#paramssave_conversation) with a
`conversation_id`), asking your endpoint to return that conversation; that request carries the
call and session fields but none of the summary fields. Answer it with the stored
`conversation_summary`.

The conversation appears three times. `call_log` is the filtered view, with interrupted segments
consolidated. `raw_call_log` is unfiltered and append-only, and is the only place barge-in detail
survives. `call_timeline` is a flat stream of typed events aligned to `raw_call_log`.

[`amazon_bedrock`](/docs/swml/reference/calling/amazon-bedrock) agents send a different report.
Write your handler against the
[Bedrock post-prompt callback](#tag/calls/webhook/bedrockPostPromptCallback) instead.

## Payload

- WebhooksAIAiPostPromptCallbackPayload
  - `project_id` string — Your project ID, when available.
  - `space_id` string — Your Space ID, when available.
  - `content_type` string, required — The content type of the request body. Always `text/json`.
  - `content_disposition` string, required — How the body is delivered. `agent.summary` on the end-of-call report, `agent.load_conversation` on a request for a stored conversation.
  - `conversation_type` string, required — The kind of conversation the agent ran. Always `voice`.
  - `call_id` string, required — The ID of the call.
  - `app_name` string, required — The name of your AI application.
  - `ai_session_id` string, required — The ID of the AI session on the call.
  - `ai_id_tag` string — A stable fingerprint of the model the agent ran. Two calls that used the same model share it, so you can group reports by model without recording the model name. Omitted when the session had no model.
  - `conversation_id` string — The conversation ID, when the agent was configured with one.
  - `action` 'post_conversation' | 'fetch_conversation', required — What the request is asking of you. `post_conversation` is the end-of-call report; `fetch_conversation` asks your endpoint to return a stored conversation.
  - `call_log` WebhooksAIAICallLogEntry[] — The conversation, filtered: interrupted segments are consolidated and evicted entries dropped. Included when `action` is `post_conversation`.
    - `role` string, required — Who produced the entry: `system`, `user`, `assistant`, or `tool`.
    - `content` string, required — The text of the entry.
    - `timestamp` integer — When the entry was added, as a Unix timestamp in microseconds. Omitted on entries without one.
    - `tool_calls` object[] — The tool calls the agent made on this turn. Present only on a turn that made any.
  - `raw_call_log` WebhooksAIAICallLogEntry[] — The conversation, unfiltered and append-only. Interruption detail appears here and nowhere else. Included when `action` is `post_conversation`.
    - `role` string, required — Who produced the entry: `system`, `user`, `assistant`, or `tool`.
    - `content` string, required — The text of the entry.
    - `timestamp` integer — When the entry was added, as a Unix timestamp in microseconds. Omitted on entries without one.
    - `tool_calls` object[] — The tool calls the agent made on this turn. Present only on a turn that made any.
  - `call_timeline` WebhooksAIAICallTimelineEntry[] — A flat stream of typed events aligned to `raw_call_log`, for replaying the call in order. Included when the session produced any.
    - `type` string, required — What happened. `user_input`, `ai_response`, and `tool_result` cover the conversation; `pronounce` and `text_normalize` record text rewrites; anything else is the name of a logged action.
    - `ts` number — When it happened, as a Unix timestamp in microseconds. Omitted when the source entry had no timestamp.
  - `previous_contexts` array[] — Conversations from before each context switch, oldest first, one array of messages per switch. Included only when the agent switched context during the call.
    - object[]
  - `hard_timeout` boolean — Always `true` when present, meaning the session ended because it hit its configured time limit rather than finishing on its own. Omitted otherwise.
  - `call_start_date` integer — When the call was created, as a Unix timestamp in microseconds.
  - `call_answer_date` integer — When the call was answered, as a Unix timestamp in microseconds. `0` when it never was.
  - `call_end_date` integer — When the call ended, as a Unix timestamp in microseconds.
  - `ai_start_date` integer — When the AI session started, as a Unix timestamp in microseconds.
  - `call_ended_by` string — Who or what ended the call. Included when the session recorded it.
  - `ai_end_date` integer — When the AI session ended, as a Unix timestamp in microseconds. Omitted when the session was still running.
  - `caller_id_name` string — The caller's name, when available.
  - `caller_id_number` string — The caller's number, when available.
  - `times` WebhooksAIAIResponseTiming[] — Per-response performance metrics, one entry per generated reply. Included once the session has any.
    - `response` string, required — The reply text. Redacted when you enable `redact_prompt`.
    - `response_word_count` integer, required — How many words the reply contained.
    - `answer_time` number, required — How long the reply took to produce, in seconds.
    - `token_time` number, required — How long the model spent generating, in seconds. For an [`ai`](/docs/swml/reference/calling/ai) agent this is the span from the first token to the last; for an [`amazon_bedrock`](/docs/swml/reference/calling/amazon-bedrock) agent it is `answer_time` less a fixed startup estimate, so treat it as approximate there.
    - `tokens` integer, required — How many tokens the reply used.
    - `avg_tps` number, required — Average tokens per second across the reply.
    - `tps` number, required — Tokens per second for this reply.
  - `SWMLVars` object — SWML variables for the call. Included when the call carries SWML state.
  - `SWMLCall` object — SWML call state. Included when the call carries SWML state.
  - `post_prompt_data` WebhooksAIAIPostPromptData — The answer an AI agent gave to your [`post_prompt`](/docs/swml/reference/calling/ai), in three forms.
    - `parsed` object[], required — Every JSON object found in the answer, parsed. An empty array when the agent answered in prose. Ask the post-prompt for named JSON keys when you want to count outcomes.
    - `raw` string, required — The answer exactly as the agent produced it.
    - `substituted` string — The answer with the JSON removed, leaving only the surrounding prose. Omitted when the answer was JSON and nothing followed it.
  - `global_data` object — The session's final `global_data`. Alongside anything you seeded, the session adds `caller_id_name` and `caller_id_number` when the call carries them. Included when `action` is `post_conversation`.
  - `swaig_log` WebhooksAIAISwaigLogEntry[] — Every tool call the agent made, in order. Included when `action` is `post_conversation`.
    - `command_name` string, required — The name of the function the agent called.
    - `command_arg` string, required — The arguments it passed, as the raw string the model produced.
    - `epoch_time` integer, required — When the call was made, as a Unix timestamp in seconds.
    - `native` boolean — Always `true` when present, meaning the function ran inside the platform rather than on your server.
    - `active_count` union — How many times the function may still be called, or `endless` when it has no limit. Present only on a function you limited.
      - integer
      - string
    - `url` string — The URL the function was served from. Present when the call reached your server.
    - `post_data` object — The body sent to your server. Present when the call reached it.
    - `post_response` object — The response your server returned. Present when the call reached it and got a reply.
    - `delayed_post_response` object — A response that arrived after the agent had already moved on. Present only when that happened.
    - `mcp_url` string — The MCP server the tool was served from. Present only for an MCP-backed tool.
    - `mcp_tool` string — The tool name on that MCP server. Present only for an MCP-backed tool.
    - `mcp_response` string — What the MCP server returned. Present only for an MCP-backed tool.
    - `mcp_error` boolean — Always `true` when present, meaning the MCP call failed.
  - `total_minutes` integer — The number of billable minutes, rounded up to at least one. Included when you enable [`enable_accounting`](/docs/swml/reference/calling/ai/params#paramsenable_accounting).
  - `total_input_tokens` integer — Input tokens the session consumed. Included when you enable `enable_accounting`.
  - `total_output_tokens` integer — Output tokens the session produced. Included when you enable `enable_accounting`.
  - `total_wire_input_tokens` integer — Input tokens counted against the model, which differs from `total_input_tokens` when the conversation was trimmed. Included when you enable `enable_accounting`.
  - `total_wire_input_tokens_per_minute` number — `total_wire_input_tokens` divided by `total_minutes`. Included when you enable `enable_accounting`.
  - `total_wire_output_tokens` integer — Output tokens counted against the model. Included when you enable `enable_accounting`.
  - `total_wire_output_tokens_per_minute` number — `total_wire_output_tokens` divided by `total_minutes`. Included when you enable `enable_accounting`.
  - `total_tts_chars` integer — Characters sent to text-to-speech. Included when you enable `enable_accounting`.
  - `total_tts_chars_per_min` number — `total_tts_chars` divided by `total_minutes`. Included when you enable `enable_accounting`.
  - `total_asr_minutes` number — Minutes of audio sent to speech recognition. Included when you enable `enable_accounting`.
  - `total_asr_cost_factor` number — `total_asr_minutes` divided by `total_minutes`. Included when you enable `enable_accounting`.
  - `conversation_summary` string — A plain-language summary of the conversation, for storing against `conversation_id` and handing back on the next `fetch_conversation`. Included when you enable [`save_conversation`](/docs/swml/reference/calling/ai/params#paramssave_conversation) and set a `conversation_id`.

## Acknowledgement `200`

Webhook received

---

[API](https://skmtc.net/signalwire/apis/signalwire-rest-api.md) · [All operations](https://skmtc.net/signalwire/apis/signalwire-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/signalwire/signalwire-rest-api/revisions/a884f7dcbfc3/schema)
