
## Regenerate a CoPilot answer

`POST /v1/chats/messages/:messageId/regenerate`

Asks CoPilot to answer the same question again — the v2 messenger method `im.v2.Copilot.Message.regenerate`. Works for a CoPilot answer in a CoPilot chat. The call is asynchronous: `result: true` means the generation has started, and the new answer arrives in the chat as a separate message.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `messageId` (path) | number | yes | ID of a CoPilot answer. Get it from `data.messages[].id` of the [draft chat](/docs/chats/copilot/draft) or of the [message history in the v2 mode](/docs/chats/messages/list) |

The endpoint accepts no request body and no query parameters: any body field or query parameter is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X POST https://vibecode.bitrix24.com/v1/chats/messages/9002/regenerate \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X POST https://vibecode.bitrix24.com/v1/chats/messages/9002/regenerate \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/messages/9002/regenerate', {
  method: 'POST',
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
})

const { success, data } = await res.json()
console.log('Generation started:', data.result)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/messages/9002/regenerate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

const { success, data } = await res.json()
console.log('Generation started:', data.result)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.result` | boolean | `true` — the generation has started |

## Response example

```json
{
  "success": true,
  "data": {
    "result": true
  }
}
```

## Error response example

422 — the message is not from a CoPilot chat:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "WRONG_CHAT_TYPE",
    "b24Code": "WRONG_CHAT_TYPE"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `messageId` is not a positive integer, or a body field or a query parameter was sent. Checked before any call to Bitrix24 |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned "not found"; the portal code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | Bitrix24 refused; the portal code is in `error.b24Code`: `WRONG_CHAT_TYPE` — not a CoPilot chat, `NOT_BOT_MESSAGE` — the message is not a CoPilot answer, `REGENERATE_NOT_AVAILABLE` — the original question is gone or not visible to the user, `AI_NOT_AVAILABLE` — AI is not available on the portal |
| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — the call starts a generation |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |

The full list of general API errors — [Errors](/docs/errors).

## Known specifics

**The call invokes the AI of your Bitrix24 account.** Every regeneration is a new request to the model and counts against the account's AI limit.

**The answer arrives as a message.** The endpoint does not wait for the generation to finish. Read the new answer with the [message history in the v2 mode](/docs/chats/messages/list) or receive it through [events](/docs/chats/events).

## See also

- [CoPilot](/docs/chats/copilot)
- [Rate an answer](/docs/chats/copilot/vote)
- [CoPilot draft chat](/docs/chats/copilot/draft)
