[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fcopilot\u002Frole":3,"docs-tabs-chats\u002Fcopilot\u002Frole":6},{"content":4,"lastmod":5},"\n## Change the CoPilot role\n\n`PUT \u002Fv1\u002Fchats\u002F:dialogId\u002Fcopilot\u002Frole`\n\nSets 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.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `dialogId` (path) | string | yes | Dialog ID of a CoPilot chat — `chatN`. Get it from `data.chat.dialogId` of the [draft chat](\u002Fdocs\u002Fchats\u002Fcopilot\u002Fdraft) or from the [recent dialogs](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Frecent) list with `onlyCopilot=true` |\n\nQuery parameters are not accepted and are rejected with `400 INVALID_PARAMS`.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `role` | string\\|null | yes | A role code, or `null` for the default role. Role codes are the keys of `data.copilot.roles` returned by [Load a chat](\u002Fdocs\u002Fchats\u002Fmessages\u002Fload) |\n\nOther body fields are rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X PUT https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2001\u002Fcopilot\u002Frole \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"role\": \"copilot_assistant\"}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X PUT https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2001\u002Fcopilot\u002Frole \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"role\": \"copilot_assistant\"}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2001\u002Fcopilot\u002Frole', {\n  method: 'PUT',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ role: 'copilot_assistant' }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Role set:', data.result)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2001\u002Fcopilot\u002Frole', {\n  method: 'PUT',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ role: 'copilot_assistant' }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Role set:', data.result)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.result` | boolean | `true` — the role was set |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"result\": true\n  }\n}\n```\n\n## Error response example\n\n400 — the `role` field was not sent:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"`role` is required (a role code, or null for the default role).\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | The `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 |\n| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned \"not found\". The portal code is in `error.b24Code` |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused with `WRONG_MESSAGE_TYPE` in `error.b24Code` — the chat is not a CoPilot chat |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused with `IDENTICAL_ROLE` in `error.b24Code` — the chat already has this role |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused with `ROLE_NOT_FOUND` in `error.b24Code` — no role with this code |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused with `COPILOT_NOT_INSTALLED` in `error.b24Code` — CoPilot is not installed on the portal |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | Failed to resolve the user when using the `me` alias |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — the call changes the chat |\n| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |\n\nThe full list of general API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## See also\n\n- [CoPilot](\u002Fdocs\u002Fchats\u002Fcopilot)\n- [Change the CoPilot model](\u002Fdocs\u002Fchats\u002Fcopilot\u002Fengine)\n- [Load a chat](\u002Fdocs\u002Fchats\u002Fmessages\u002Fload)\n","2026-10-07",{},1794739533673]