---
title: "Regenerate AI response"
method: POST
path: "/conversations/{conversationId}/message/{messageId}/regenerate"
tags: ["Conversations"]
---

# Regenerate AI response

`POST /conversations/{conversationId}/message/{messageId}/regenerate`

Regenerate the AI response for a specific message and stream the new
answer over Server-Sent Events.

**Overview:**

If you're not satisfied with an AI response, use this endpoint to generate
a new answer. The original user query is re-processed and a new bot
response replaces the previous one in place.

**Constraints:**

- Only the *last* message of the conversation can be regenerated.
- The target message must be of type `bot_response`.

**Use Cases:**

- Response was incomplete or unclear
- Want to try a different AI model
- New documents have been indexed since original response

**Model Override:**

Specify `modelKey` to use a different model for regeneration.

**Streaming:**

The response is delivered as an SSE (`text/event-stream`) stream. The
exact event vocabulary depends on `chatMode`:

- For non-agent modes (e.g. `internal_search`, `web_search`) the
  request is dispatched to the assistant chat backend.
- For agent modes (e.g. `agent:auto`) the request is dispatched to
  the agent backend with a placeholder agent built from the caller's
  workspace, which can additionally emit `tool_result` and
  `tool_execution_complete` events.

See `SSEEvent` for the full union of event names this endpoint can
emit across both backends.

## Path parameters

- `conversationId` string, objectId, required
- `messageId` string, objectId, required

## Request body

- RegenerateRequest — Request body for regenerating an AI response. All fields are optional; when omitted the model selection and execution context from the original message are reused. Supported fields: - `filters` — optional `{ apps?, kb? }` filter object - `chatMode` — optional non-empty chat mode string - `modelKey`, `modelName`, `modelFriendlyName` — optional non-empty model override fields - `timezone` — optional non-empty client timezone string - `currentTime` — optional ISO 8601 / RFC 3339 datetime string with UTC `Z` or a numeric offset - `tools` — optional array of non-empty tool identifiers
  - `filters` Filters — App connector instance ids and knowledge-base / record-group ids that narrow retrieval for a turn. For **org assistant** chat streams, send explicit `apps` / `kb` lists. For **agent** chat streams, send explicit id lists, or **omit** `filters` (and `tools`) to let the service use the agent’s stored knowledge and tool configuration. Sending `{ "apps": [], "kb": [] }` on an agent stream means **no** knowledge sources for that turn (it is not “full org default”).
    - `apps` string[] — Connector instance ids to scope retrieval for this turn. Each element must be a UUID (connector instance id, record-group id, etc.) or the org knowledge-base collection sentinel `knowledgeBase_<orgId>` (pattern `knowledgeBase_[a-zA-Z0-9_-]+`). Gateway validation matches Zod `appOrKbIdSchema`.
    - `kb` string[] — Knowledge-base / record-group ids to scope retrieval for this turn. Each element uses the same accepted formats as `apps`: a UUID or `knowledgeBase_<orgId>` (pattern `knowledgeBase_[a-zA-Z0-9_-]+`).
  - `modelKey` string — Identifier of the AI model configuration to use for regeneration. Typically a UUID returned by the model-management endpoints. When omitted, the model used for the original message is reused.
  - `modelName` string — Provider model name (e.g. the underlying LLM identifier).
  - `modelFriendlyName` string — Friendly display name of the selected model.
  - `chatMode` string — Chat mode used for regeneration (for example `internal_search`, `web_search`, or an agent mode such as `agent:auto`).
  - `timezone` string — IANA timezone identifier from the client. Used to provide time-aware context to the AI during regeneration.
  - `currentTime` string, date-time — ISO 8601 / RFC 3339 datetime from the client (UTC `Z` or numeric offset). Used to anchor any relative time references in the query.
  - `tools` string[] — Optional list of tool identifiers (fully-qualified action names such as `jira.create_issue`) the agent may invoke when regenerating. Applicable only in agent chat modes.

## Response `200`

SSE stream established. The body is a sequence of
`text/event-stream` frames using the event vocabulary described
on `SSEEvent`. The exact subset of events emitted depends on
`chatMode` (see the route description for routing rules).

Lifecycle (all event names are sent verbatim on the wire):
- `connected` — `{ "message": "SSE connection established" }`.
  Fired once on connection by the API layer.
- `status` — progress messages from the AI backend. Possible
  `status` sub-values include `started`, `transforming`,
  `searching`, `processing`, `checking_tools`,
  `generating_answer`, `generating`, `analyzing`, `evaluating`,
  `planning`, `executing`, `retrying`, `continuing`, `success`,
  `skipped`, `pending`, `keepalive`, `cascade_error`, and
  backend-defined values that may be added over time.
- `answer_chunk` — incremental token batches with running
  `accumulated` text, accumulated `citations`, and the
  backend-supplied `confidence` (typically null until the final
  chunk).
- `tool_calls` / `tool_call` / `tool_success` / `tool_error` —
  emitted when the model invokes tools (agent chat modes, or the
  non-agent path when SQL / record-fetch tools are configured).
- `tool_result` / `tool_execution_complete` — additional tool
  lifecycle events emitted only on the agent-mode path.
- `restreaming` — emitted when the LLM is restarted with new
  context (e.g. before a citation-verification pass or
  reflection-driven retry).
- `metadata` — `{}` keep-alive emitted by the JSON-streaming
  branch while waiting for the next safe-to-flush chunk.
- `complete` — `{ "conversation": Conversation, "recordsUsed":
  number, "meta": { "requestId": string, "timestamp": string,
  "duration": number, "recordsUsed": number } }`. Fired once
  after the regeneration is persisted; the new bot response
  replaces the previous one in `conversation.messages` at the
  same index. The AI backend's own `complete` frame is consumed
  server-side and is **not** forwarded — clients see only this
  server-defined frame.
- `error` — `{ "error": string, "details"?: string }`. Fired if
  the stream fails; the previous bot response is replaced with an
  error message and the conversation row is marked FAILED before
  close.

Clients should ignore unknown event names rather than treating
them as errors.

## Other responses

- `400` — Cannot regenerate. Common causes: target message is not the last message in the conversation, target message is not of type `bot_response`, or no preceding `user_query` exists.
- `401` — Unauthorized
- `404` — Conversation or message not found

---

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