Chat
Create a chat
Opens a chat with a published prompt-mode agent.
POST https://api.diska.ai/v1/chats
Scope: chats:write
If the agent speaks first and has a greeting, the response already carries that message. The chat also shows in GET /v1/calls, with channel web_chat. metadata is yours: it is stored and returned, but the agent never sees it. Send Idempotency-Key to retry the request without opening two chats.
Request body
application/json
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Published prompt-mode agent. Up to 64 characters. |
variables | object | No | Chat variables (up to 20), as on calls. |
metadata | object | No | Up to 20 text → text pairs (500 characters per value), for you only. |
contact | string | null | No | Who is chatting: phone, email or your own ID. Up to 120 characters. |
{
"agent_id": "3f1c2a7e-5b9d-4c1e-8f3a-2d6b7e9c1a40",
"contact": "+244923000000",
"variables": {
"nome": "Ana"
},
"metadata": {
"crm_ticket": "T-1042"
}
}
Examples
curl -X POST "https://api.diska.ai/v1/chats" \
-H "Authorization: Bearer $DISKA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"agent_id":"3f1c2a7e-5b9d-4c1e-8f3a-2d6b7e9c1a40","contact":"+244923000000","variables":{"nome":"Ana"},"metadata":{"crm_ticket":"T-1042"}}'
import os
import requests
response = requests.post(
"https://api.diska.ai/v1/chats",
headers={"Authorization": f"Bearer {os.environ['DISKA_API_KEY']}"},
json={
"agent_id": "3f1c2a7e-5b9d-4c1e-8f3a-2d6b7e9c1a40",
"contact": "+244923000000",
"variables": {
"nome": "Ana",
},
"metadata": {
"crm_ticket": "T-1042",
},
},
timeout=30,
)
response.raise_for_status()
print(response.json())
// Node.js 18 or later, in a .mjs file
const response = await fetch('https://api.diska.ai/v1/chats', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.DISKA_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
"agent_id": "3f1c2a7e-5b9d-4c1e-8f3a-2d6b7e9c1a40",
"contact": "+244923000000",
"variables": {
"nome": "Ana"
},
"metadata": {
"crm_ticket": "T-1042"
}
})
})
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`)
console.log(await response.json())
<?php
$ch = curl_init('https://api.diska.ai/v1/chats');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('DISKA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3f1c2a7e-5b9d-4c1e-8f3a-2d6b7e9c1a40',
'contact' => '+244923000000',
'variables' => [
'nome' => 'Ana',
],
'metadata' => [
'crm_ticket' => 'T-1042',
],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status >= 400) {
throw new RuntimeException("HTTP $status: $body");
}
print_r(json_decode($body, true));
Try it
Send the request from this page, with your key. The key stays on this page: it is not stored and is only sent to api.diska.ai. Use a test key with the fewest scopes you need.
POST
https://api.diska.ai/v1/chatsStarts with dsk_. It stays in this browser tab only.
Enter an API key (dsk_…).
Response 201
| Field | Type | Description |
|---|---|---|
id | string | Chat ID (the same as GET /v1/calls/{call_id}). |
agent_id | string | The agent. |
status | string | active or ended. |
contact | string | null | Who is chatting, as you stated it. |
metadata | object | Your metadata, returned as sent. |
created_at | string | Creation date (ISO 8601). |
ended_at | string | null | When it ended. |
end_reason | string | null | ended_by_api, agent_ended or inactivity. |
messages | array | The messages, in order. |
messages[].id | string | Message ID. |
messages[].role | string | user (the person) or assistant (the agent). |
messages[].content | string | The text. |
messages[].created_at | string | null | When it was written. |
{
"id": "5c2e8a14-7d3b-4f9e-a1c6-0b8d2f4e6a93",
"agent_id": "3f1c2a7e-5b9d-4c1e-8f3a-2d6b7e9c1a40",
"status": "active",
"contact": "+244900000000",
"metadata": {},
"created_at": "2026-10-25T18:40:00Z",
"ended_at": "2026-10-25T18:41:35Z",
"end_reason": "caller_hangup",
"messages": [
{
"id": "5c2e8a14-7d3b-4f9e-a1c6-0b8d2f4e6a93",
"role": "user",
"content": "Bom dia, queria marcar uma consulta.",
"created_at": "2026-10-25T18:40:00Z"
}
]
}
Errors
| Code | When |
|---|---|
403 | API chat is not switched on for the organization. |
404 | Agente não encontrado. (agent not found). |
409 | The agent is not published, is inactive or uses the Flow Builder. |
422 | Variables refused or metadata over the limits. |
Errors common to every endpoint (401, 403, 422, 429 and 5xx) are in Errors.

