Retry a message

POST/v2/agents/{agentId}/chat/retry

Ask an agent to write a new answer to the latest message of a conversation, replacing the reply you were not happy with.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

Regenerates the last assistant reply of a conversation. Call it when your interface offers a "try again" button, or when a reply failed halfway and you want a fresh answer to the same question.

Request

POST /v2/agents/{agentId}/chat/retry

Path parameters:

Name Type Required Description
agentId string Yes The ID of the agent, starting with agt_.

Body fields:

Name Type Required Description
conversationId string Yes The conversation that holds the reply, starting with conv_.
messageId string Yes The assistant message to replace, starting with msg_. It must be the latest message of the conversation.
stream boolean No true returns server-sent events instead of JSON. Defaults to false.

The old reply is replaced, not kept next to the new one. Reading the conversation afterwards with List conversation messages shows only the new message.

Example request

curl -X POST https://api.askocto.co/v2/agents/agt_8f3k2m/chat/retry \
  -H "Authorization: Bearer $OCTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "conversationId": "conv_5n2p8w", "messageId": "msg_7c1k9s" }'
const response = await fetch("https://api.askocto.co/v2/agents/agt_8f3k2m/chat/retry", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.OCTO_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ conversationId: "conv_5n2p8w", messageId: "msg_7c1k9s" }),
})

const reply = await response.json()
console.log(reply.message.id, reply.message.content)

Example response

A successful call returns 200 OK. The shape is the same as the response of Chat with an agent, and the new message has a new id.

{
  "conversationId": "conv_5n2p8w",
  "message": {
    "id": "msg_2h8d6f",
    "role": "assistant",
    "content": "Happy to help. Please send me your order number and I will look it up.",
    "sources": [{ "id": "src_91xa7d", "title": "Shipping and delivery" }]
  },
  "usage": { "credits": 1 }
}

Response fields

Name Type Description
conversationId string The conversation that was changed.
message object The new reply, with its id, role, content and sources.
usage.credits integer The credits used by the new reply.

Streaming works as it does for chat, see Streaming.

Errors

Status Code When
400 invalid_request conversationId or messageId is missing or has the wrong format.
401 unauthorized The API key is missing, malformed or deleted.
404 not_found The agent, the conversation or the message does not exist.
409 conflict The message is not the latest message of the conversation, or it is not an assistant message.
429 rate_limited Too many requests. Wait for the number of seconds in the Retry-After header.

Something unclear or missing? Tell us and we will fix the page.