[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fcopilot\u002Fdraft":3,"docs-tabs-chats\u002Fcopilot\u002Fdraft":6},{"content":4,"lastmod":5},"\n## CoPilot draft chat\n\n`POST \u002Fv1\u002Fchats\u002Fcopilot\u002Fdraft`\n\nOpens the current user's CoPilot draft chat. The response has the same structure as in [Load a chat](\u002Fdocs\u002Fchats\u002Fmessages\u002Fload): the chat card, the first page of messages, pinned messages, participants, files and the `copilot` block. When there is no draft chat yet, the first call creates it.\n\n## Parameters\n\nThere are no path or query parameters. Any query parameter is rejected with `400 INVALID_PARAMS`.\n\n## Request fields (body)\n\nThe body is optional.\n\n| Field | Type | Required | Default | Description |\n|------|-----|:-----:|-----------|---------|\n| `messageLimit` | number | no | — | How many messages to return on the first page. From 1 to 200: a value outside the range is clamped; the passed and applied values are in `meta.requestedMessageLimit` and `meta.appliedMessageLimit` |\n| `pinLimit` | number | no | — | How many pinned messages to return. From 1 to 200; the passed and applied values are in `meta.requestedPinLimit` and `meta.appliedPinLimit` |\n\nOther body fields are rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fcopilot\u002Fdraft \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"messageLimit\": 20}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fcopilot\u002Fdraft \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"messageLimit\": 20}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fcopilot\u002Fdraft', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ messageLimit: 20 }),\n})\n\nconst { data } = await res.json()\nconsole.log('Draft chat:', data.chat.dialogId)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fcopilot\u002Fdraft', {\n  method: 'POST',\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({ messageLimit: 20 }),\n})\n\nconst { data } = await res.json()\nconsole.log('Draft chat:', data.chat.dialogId)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.chat` | object | The draft chat card: `id`, `dialogId`, `name`, `type`, `owner`, `role` and other fields |\n| `data.messages` | array | The first page of messages |\n| `data.pins` | array | Pinned messages |\n| `data.users` | array | Participants mentioned on the page |\n| `data.files` | array | Files of the messages on the page |\n| `data.reactions` | array | Reactions to the messages on the page |\n| `data.copilot` | object | The CoPilot block |\n| `data.copilot.chats` | array | CoPilot chats on the page: `dialogId`, `role` — the role code, `engine` — the model code, `titleIsCustom` |\n| `data.copilot.messages` | array\\|null | CoPilot roles of the messages on the page. `null` if there are no such messages |\n| `data.copilot.engines` | array\\|null | Models of the chats on the page: `code`, `name`, `supportsReasoning` |\n| `data.copilot.roles` | object\\|null | Roles keyed by role code: `code`, `name`, `desc`, `avatar`, `default`, `prompts` |\n| `data.copilot.aiProvider` | string | Name of the default model |\n| `data.hasPrevPage` | boolean | Whether there are messages older than the first page |\n| `data.hasNextPage` | boolean | Whether there are messages newer than the first page |\n| `meta.requestedMessageLimit` | number | The `messageLimit` sent, when it fell outside the range from 1 to 200 |\n| `meta.appliedMessageLimit` | number | The applied `messageLimit` — only when it was clamped to a bound |\n| `meta.requestedPinLimit` | number | The `pinLimit` sent, when it fell outside the range from 1 to 200 |\n| `meta.appliedPinLimit` | number | The applied `pinLimit` — only when it was clamped to a bound |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"chat\": {\n      \"id\": 2001,\n      \"dialogId\": \"chat2001\",\n      \"name\": \"CoPilot\",\n      \"type\": \"copilot\",\n      \"owner\": 5,\n      \"role\": \"owner\"\n    },\n    \"messages\": [\n      {\n        \"id\": 9001,\n        \"chatId\": 2001,\n        \"authorId\": 0,\n        \"date\": \"2026-09-25T10:00:00+00:00\",\n        \"text\": \"Hi! How can I help?\",\n        \"params\": {}\n      }\n    ],\n    \"pins\": [],\n    \"users\": [],\n    \"files\": [],\n    \"reactions\": [],\n    \"copilot\": {\n      \"chats\": [\n        { \"dialogId\": \"chat2001\", \"role\": \"copilot_assistant\", \"engine\": \"b24ai\", \"titleIsCustom\": false }\n      ],\n      \"messages\": null,\n      \"engines\": [\n        { \"code\": \"b24ai\", \"name\": \"BitrixGPT 5.5\", \"supportsReasoning\": true }\n      ],\n      \"roles\": {\n        \"copilot_assistant\": {\n          \"code\": \"copilot_assistant\",\n          \"name\": \"BitrixGPT\",\n          \"desc\": \"Ready to answer any question in a general format\",\n          \"avatar\": { \"small\": \"\", \"medium\": \"\", \"large\": \"\" },\n          \"default\": true,\n          \"prompts\": []\n        }\n      },\n      \"aiProvider\": \"BitrixGPT 5.5\"\n    },\n    \"hasPrevPage\": false,\n    \"hasNextPage\": false\n  }\n}\n```\n\n## Error response example\n\n422 — the CoPilot draft chat is not available in the Bitrix24 account:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ERROR\",\n    \"message\": \"DRAFT_CHAT_NOT_AVAILABLE\",\n    \"b24Code\": \"DRAFT_CHAT_NOT_AVAILABLE\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | `messageLimit` or `pinLimit` is not an integer, or another body field or a query parameter was sent. Checked before any call to Bitrix24 |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused. The portal code is in `error.b24Code`. `DRAFT_CHAT_NOT_AVAILABLE` — the draft chat is turned off on the portal |\n| 403 | `BITRIX_ACCESS_DENIED` | The user is not allowed to create CoPilot chats — Bitrix24 refused with the `ACCESS_DENIED` code |\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 first call creates a 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## Known specifics\n\n**Response keys.** Keys that name fields are converted to camelCase. Keys that are data stay as they are: the keys of the `data.copilot.roles` dictionary are role codes, and `copilot_assistant` arrives as `copilot_assistant` — the same value that `role` carries in `data.copilot.chats`, so you can look up a role directly as `roles[role]`.\n\n**Continue in the message history.** Load older messages with the [message history in the v2 mode](\u002Fdocs\u002Fchats\u002Fmessages\u002Flist) using `data.chat.dialogId`.\n\n## See also\n\n- [CoPilot](\u002Fdocs\u002Fchats\u002Fcopilot)\n- [Load a chat](\u002Fdocs\u002Fchats\u002Fmessages\u002Fload)\n- [Change the CoPilot model](\u002Fdocs\u002Fchats\u002Fcopilot\u002Fengine)\n","2026-10-07",{},1794739533326]