For AI agents: markdown of this page — /docs-content-en/chats/copilot/role.md documentation index — /llms.txt

Change the CoPilot role

PUT /v1/chats/:dialogId/copilot/role

Sets the role CoPilot uses when answering in a chat. The role defines the style and specialization of the answers. Works only in a CoPilot chat.

Parameters

Parameter Type Required Description
ParameterdialogId (path) Typestring Requiredyes DescriptionDialog ID of a CoPilot chat — chatN. Get it from data.chat.dialogId of the draft chat or from the recent dialogs list with onlyCopilot=true

Query parameters are not accepted and are rejected with 400 INVALID_PARAMS.

Request fields (body)

Field Type Required Description
Fieldrole Typestring|null Requiredyes DescriptionA role code, or null for the default role. Role codes are the keys of data.copilot.roles returned by Load a chat

Other body fields are rejected with 400 INVALID_PARAMS.

Examples

curl — personal key

Terminal
curl -X PUT https://vibecode.bitrix24.com/v1/chats/chat2001/copilot/role \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"role": "copilot_assistant"}'

curl — OAuth application

Terminal
curl -X PUT https://vibecode.bitrix24.com/v1/chats/chat2001/copilot/role \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"role": "copilot_assistant"}'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat2001/copilot/role', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ role: 'copilot_assistant' }),
})

const { success, data } = await res.json()
console.log('Role set:', data.result)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat2001/copilot/role', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ role: 'copilot_assistant' }),
})

const { success, data } = await res.json()
console.log('Role set:', data.result)

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata.result Typeboolean Descriptiontrue — the role was set

Response example

JSON
{
  "success": true,
  "data": {
    "result": true
  }
}

Error response example

400 — the role field was not sent:

JSON
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "`role` is required (a role code, or null for the default role)."
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS DescriptionThe role field is missing, is neither a non-empty string nor null, or another body field or a query parameter was sent. Checked before any call to Bitrix24
HTTP404 CodeENTITY_NOT_FOUND DescriptionBitrix24 returned "not found". The portal code is in error.b24Code
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 refused with WRONG_MESSAGE_TYPE in error.b24Code — the chat is not a CoPilot chat
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 refused with IDENTICAL_ROLE in error.b24Code — the chat already has this role
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 refused with ROLE_NOT_FOUND in error.b24Code — no role with this code
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 refused with COPILOT_NOT_INSTALLED in error.b24Code — CoPilot is not installed on the portal
HTTP502 CodeME_ALIAS_RESOLUTION_FAILED DescriptionFailed to resolve the user when using the me alias
HTTP403 CodeSCOPE_DENIED DescriptionThe API key does not have the im scope
HTTP403 CodeWRITE_BLOCKED_READONLY_KEY DescriptionThe key is read-only — the call changes the chat
HTTP401 CodeTOKEN_MISSING DescriptionThe API key has no Bitrix24 tokens configured

The full list of general API errors — Errors.

See also